meta

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package meta defines the binary format and in-memory view for LLGo package summary cache files (.meta). The format is designed for zero-copy access via mmap: the file layout is the memory layout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder accumulates per-package metadata facts and serializes them into the binary wire format understood by PackageMeta.

Typical usage:

b := NewBuilder()
fn := b.Sym("main.main")
callee := b.Sym("fmt.Println")
b.AddOrdinaryEdge(fn, callee)
pm, err := b.Build()

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates an empty Builder.

func (*Builder) AddIfaceMethod

func (b *Builder) AddIfaceMethod(iface Symbol, methodName string, mtype Symbol)

AddIfaceMethod records one method in an interface's method set. Idempotent: if the same (name, mtype) pair is already registered for iface, this call is a no-op — the Builder deduplicates internally.

func (*Builder) AddIfaceMethodUse

func (b *Builder) AddIfaceMethodUse(src, iface Symbol, methodIndex uint32)

AddIfaceMethodUse records that src calls the methodIndex-th method (in declaration order) of interface iface.

func (*Builder) AddIfaceUse

func (b *Builder) AddIfaceUse(src, typ Symbol)

AddIfaceUse records that src converts a value of type typ to an interface.

func (*Builder) AddMethodSlot

func (b *Builder) AddMethodSlot(typ Symbol, methodName string, mtype, ifn, tfn Symbol)

AddMethodSlot records one ABI method slot for a concrete type. Slots must be appended in abi.Method table order.

func (*Builder) AddNamedMethodUse

func (b *Builder) AddNamedMethodUse(src Symbol, methodName string)

AddNamedMethodUse records that src does a constant MethodByName(methodName) call. The method name is stored as a string-table reference.

func (*Builder) AddOrdinaryEdge

func (b *Builder) AddOrdinaryEdge(src, dst Symbol)

AddOrdinaryEdge records a plain symbol-to-symbol reference from src to dst (call, type use, global var reference, etc.).

func (*Builder) AddTypeChild

func (b *Builder) AddTypeChild(parent, child Symbol)

AddTypeChild records that parent type structurally contains child type. Idempotent: duplicate (parent, child) pairs are silently ignored.

func (*Builder) Build

func (b *Builder) Build() (*PackageMeta, error)

Build serializes all accumulated facts into a PackageMeta.

The process is:

  1. Calculate the byte size of every section.
  2. Derive each section's start offset.
  3. Allocate one []byte for the whole file.
  4. Write header + every section directly into the buffer — no intermediate allocations, no copies.

func (*Builder) MarkReflect

func (b *Builder) MarkReflect(sym Symbol)

MarkReflect marks sym as triggering conservative reflection handling.

func (*Builder) Sym

func (b *Builder) Sym(name string) Symbol

Sym registers a symbol by name and returns its Symbol. Calling Sym with the same name twice returns the same Symbol. Whether the symbol is defined in this package or referenced from another makes no difference to the metadata format.

type DemandKind

type DemandKind uint32

DemandKind identifies a function-level method/interface/reflection demand.

const (
	DemandUseIface      DemandKind = 1
	DemandIfaceMethod   DemandKind = 2
	DemandNamedMethod   DemandKind = 3
	DemandReflectMethod DemandKind = 4
)

FuncDemand kinds used in the FuncDemand section and global analysis API.

type FuncDemand

type FuncDemand struct {
	Kind       DemandKind
	Target     Symbol
	Sig        MethodSig
	MethodName Name
}

FuncDemand is a function-level method/interface/reflection demand in the global namespace. Valid fields depend on Kind:

  • DemandUseIface: Target is the concrete type converted to an interface.
  • DemandIfaceMethod: Target is the interface and Sig is the demanded method.
  • DemandNamedMethod: MethodName is the constant MethodByName argument.
  • DemandReflectMethod: no additional fields are set.

type GlobalSummary

type GlobalSummary struct {
	// contains filtered or unexported fields
}

GlobalSummary is a whole-program metadata view over multiple PackageMetas, in one unified symbol/name space.

Merge strategy:

  • Symbols are interned into a global Symbol space; each package's local symbols are mapped via locToGlb. Edges, FuncDemands, TypeChildren, MethodSlots and IfaceMethods are NOT rewritten at merge time — they are translated lazily on query. Only the strings are interned up front.
  • Duplicate symbols (e.g. linkonce type descriptors emitted by several packages) are assigned one owner by fact strength. Function-demand, MethodInfo, InterfaceInfo and TypeChildren facts outrank ordinary edges, so descriptor references do not hide the package that carries semantic method/interface facts.

GlobalSummary borrows its input PackageMetas. They must remain open and unchanged for the lifetime of the summary.

func NewGlobalSummary

func NewGlobalSummary(pkgs []*PackageMeta) (*GlobalSummary, error)

NewGlobalSummary merges package-local metadata into a whole-program view.

Phase 1 interns all symbol names and builds the locToGlb mapping, owner indices, and type-kind flags. No per-symbol data is translated — only string interning and CSR range checks happen here.

MethodSlots / IfaceMethods / FuncDemands are translated lazily on each query. This avoids translating metadata that DCE never reaches.

func (*GlobalSummary) FuncDemands

func (g *GlobalSummary) FuncDemands(sym Symbol) []FuncDemand

FuncDemands returns the method/interface/reflection demands emitted by sym. Records are translated to the global symbol and name spaces on demand.

func (*GlobalSummary) HasFacts

func (g *GlobalSummary) HasFacts(sym Symbol) bool

HasFacts reports whether sym has a package owner carrying metadata facts. A symbol may be present only because another fact references it, such as a method slot's function symbol.

func (*GlobalSummary) IfaceMethods

func (g *GlobalSummary) IfaceMethods(iface Symbol) []MethodSig

IfaceMethods returns the method set for interface iface.

func (*GlobalSummary) Ifaces

func (g *GlobalSummary) Ifaces() []Symbol

Ifaces returns all interface type symbols with method information. The returned slice is owned by GlobalSummary and must not be modified.

func (*GlobalSummary) LookupSymbol

func (g *GlobalSummary) LookupSymbol(name string) (Symbol, bool)

LookupSymbol returns the global Symbol for a module-level symbol name.

func (*GlobalSummary) MethodSlots

func (g *GlobalSummary) MethodSlots(typ Symbol) []MethodSlot

MethodSlots returns the ABI method slots for concrete type typ.

func (*GlobalSummary) Name

func (g *GlobalSummary) Name(n Name) string

Name returns the text of a global Name.

func (*GlobalSummary) OrdinaryEdges

func (g *GlobalSummary) OrdinaryEdges(sym Symbol) []Symbol

OrdinaryEdges returns plain reachability targets from sym (global Symbols).

func (*GlobalSummary) SymbolName

func (g *GlobalSummary) SymbolName(sym Symbol) string

SymbolName returns the text of a global Symbol.

func (*GlobalSummary) TypeChildren

func (g *GlobalSummary) TypeChildren(typ Symbol) []Symbol

TypeChildren returns child type symbols for typ (global Symbols).

type MethodSig

type MethodSig struct {
	Name  Name
	MType Symbol
}

MethodSig is an interface method signature in the global namespace.

type MethodSlot

type MethodSlot struct {
	Name  Name
	MType Symbol
	IFn   Symbol
	TFn   Symbol
}

MethodSlot is a method slot in the global namespace.

type Name

type Name uint32

Name is a whole-program method-name ID, in a namespace distinct from Symbol.

type PackageMeta

type PackageMeta struct {
	// contains filtered or unexported fields
}

PackageMeta is a read-only, zero-copy view of one package's metadata. Its backing bytes are either owned Go memory from Builder.Build or a read-only mapping created by Open. Package-local lookup helpers return strings and slices that alias those bytes.

The version-1 wire format is below. All integers are little-endian uint32 values. Header offsets are absolute byte offsets from the beginning of the file. Symbol values are indexes in this package's Symbols section.

Header (36 bytes)
  [0:4]   magic: "LLPM"
  [4:8]   version: 1
  [8:36]  section offsets, in this exact order:
            StringTable, Symbols, OrdinaryEdges, FuncDemand,
            TypeChildren, MethodInfo, InterfaceInfo

StringTable
  starts at byte 36
  concatenated string bytes, followed by zero padding to a 4-byte boundary

Symbols
  nsyms
  records[nsyms]: {nameOff, nameLen, reserved}                    // 12 bytes

OrdinaryEdges: CSR<Symbol>
  nsyms
  offsets[nsyms+1]
  data[]: Symbol                                                  // 4 bytes

FuncDemand: CSR<localFuncDemand>
  nsyms
  offsets[nsyms+1]
  data[]: {kind, target, extra}                                  // 12 bytes

TypeChildren: CSR<Symbol>
  nsyms
  offsets[nsyms+1]
  data[]: Symbol                                                  // 4 bytes

MethodInfo: CSR<localMethodSlot>
  nsyms
  offsets[nsyms+1]
  data[]: {nameOff, nameLen, mtype, ifn, tfn}                    // 20 bytes

InterfaceInfo: CSR<localMethodSig>
  nsyms
  offsets[nsyms+1]
  data[]: {nameOff, nameLen, mtype}                              // 12 bytes

Every CSR offsets entry is a record index into that section's data array, not a byte offset. Each CSR nsyms must equal Symbols.nsyms. Every nameOff is relative to the start of StringTable; nameLen excludes alignment padding. The Symbols reserved field is written as zero and ignored when reading. Section sizes are derived from adjacent header offsets, and InterfaceInfo extends to the end of the file. Every section starts on a 4-byte boundary.

func Open

func Open(path string) (*PackageMeta, error)

Open maps path read-only and returns a PackageMeta backed by that mapping. The caller must call Close. Values returned by package-local lookup helpers must not be used after Close.

func (*PackageMeta) Close

func (pm *PackageMeta) Close() error

Close releases the mapping owned by a PackageMeta returned from Open. It is a no-op for PackageMeta values returned from Builder.Build.

func (*PackageMeta) String

func (pm *PackageMeta) String() string

String returns a human-readable representation for testing and debugging.

func (*PackageMeta) WriteTo

func (pm *PackageMeta) WriteTo(w io.Writer) (int64, error)

WriteTo writes the complete metadata file in its binary wire format.

type Symbol

type Symbol uint32

Symbol is a symbol ID whose namespace is determined by the Builder, PackageMeta, or GlobalSummary that owns it. Builder and PackageMeta symbols are package-local; GlobalSummary symbols belong to its unified namespace.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL