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
- type Builder
- func (b *Builder) AddIfaceMethod(iface Symbol, methodName string, mtype Symbol)
- func (b *Builder) AddIfaceMethodUse(src, iface Symbol, methodIndex uint32)
- func (b *Builder) AddIfaceUse(src, typ Symbol)
- func (b *Builder) AddMethodSlot(typ Symbol, methodName string, mtype, ifn, tfn Symbol)
- func (b *Builder) AddNamedMethodUse(src Symbol, methodName string)
- func (b *Builder) AddOrdinaryEdge(src, dst Symbol)
- func (b *Builder) AddTypeChild(parent, child Symbol)
- func (b *Builder) Build() (*PackageMeta, error)
- func (b *Builder) MarkReflect(sym Symbol)
- func (b *Builder) Sym(name string) Symbol
- type DemandKind
- type FuncDemand
- type GlobalSummary
- func (g *GlobalSummary) FuncDemands(sym Symbol) []FuncDemand
- func (g *GlobalSummary) HasFacts(sym Symbol) bool
- func (g *GlobalSummary) IfaceMethods(iface Symbol) []MethodSig
- func (g *GlobalSummary) Ifaces() []Symbol
- func (g *GlobalSummary) LookupSymbol(name string) (Symbol, bool)
- func (g *GlobalSummary) MethodSlots(typ Symbol) []MethodSlot
- func (g *GlobalSummary) Name(n Name) string
- func (g *GlobalSummary) OrdinaryEdges(sym Symbol) []Symbol
- func (g *GlobalSummary) SymbolName(sym Symbol) string
- func (g *GlobalSummary) TypeChildren(typ Symbol) []Symbol
- type MethodSig
- type MethodSlot
- type Name
- type PackageMeta
- type Symbol
Constants ¶
const InterfaceUsePrefix = "_llgo_iface_use."
InterfaceUsePrefix identifies link-time interface-domain predicates.
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 (*Builder) AddIfaceMethod ¶
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 ¶
AddIfaceMethodUse records that src calls the methodIndex-th method (in declaration order) of interface iface.
func (*Builder) AddIfaceUse ¶
AddIfaceUse records that src converts a value of type typ to an interface.
func (*Builder) AddMethodSlot ¶
AddMethodSlot records one ABI method slot for a concrete type. Slots must be appended in abi.Method table order.
func (*Builder) AddNamedMethodUse ¶
AddNamedMethodUse records that src does a constant MethodByName(methodName) call. The method name is stored as a string-table reference.
func (*Builder) AddOrdinaryEdge ¶
AddOrdinaryEdge records a plain symbol-to-symbol reference from src to dst (call, type use, global var reference, etc.).
func (*Builder) AddTypeChild ¶
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:
- Calculate the byte size of every section.
- Derive each section's start offset.
- Allocate one []byte for the whole file.
- Write header + every section directly into the buffer — no intermediate allocations, no copies.
func (*Builder) MarkReflect ¶
MarkReflect marks sym as triggering conservative reflection handling.
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 MethodSlot ¶
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.