package pkgbits

Import Path
	internal/pkgbits (on go.dev)

Dependency Relation
	imports 13 packages, and imported by one package

Involved Source Files codes.go decoder.go Package pkgbits implements low-level coding abstractions for Unified IR's export data format. At a low-level, a package is a collection of bitstream elements. Each element has a "kind" and a dense, non-negative index. Elements can be randomly accessed given their kind and index. Individual elements are sequences of variable-length values (e.g., integers, booleans, strings, go/constant values, cross-references to other elements). Package pkgbits provides APIs for encoding and decoding these low-level values, but the details of mapping higher-level Go constructs into elements is left to higher-level abstractions. Elements may cross-reference each other with "relocations." For example, an element representing a pointer type has a relocation referring to the element type. Go constructs may be composed as a constellation of multiple elements. For example, a declared function may have one element to describe the object (e.g., its name, type, position), and a separate element to describe its function body. This allows readers some flexibility in efficiently seeking or re-reading data (e.g., inlining requires re-reading the function body for each inlined call, without needing to re-read the object-level details). encoder.go flags.go reloc.go support.go sync.go syncmarker_string.go
Package-Level Type Names (total 12)
/* sort by: | */
A Code is an enum value that can be encoded into bitstreams. Code types are preferable for enum types, because they allow Decoder to detect desyncs. Marker returns the SyncMarker for the Code's dynamic type. Value returns the Code's ordinal value. CodeObj CodeType CodeVal func (*Encoder).Code(c Code)
A CodeObj distinguishes among go/types.Object encodings. ( CodeObj) Marker() SyncMarker ( CodeObj) Value() int CodeObj : Code func (*PkgDecoder).PeekObj(idx Index) (string, string, CodeObj) const ObjAlias const ObjConst const ObjFunc const ObjStub const ObjType const ObjVar
A CodeType distinguishes among go/types.Type encodings. ( CodeType) Marker() SyncMarker ( CodeType) Value() int CodeType : Code const TypeArray const TypeBasic const TypeChan const TypeInterface const TypeMap const TypeNamed const TypePointer const TypeSignature const TypeSlice const TypeStruct const TypeTypeParam const TypeUnion
A CodeVal distinguishes among go/constant.Value encodings. ( CodeVal) Marker() SyncMarker ( CodeVal) Value() int CodeVal : Code const ValBigFloat const ValBigInt const ValBigRat const ValBool const ValInt64 const ValString
A Decoder provides methods for decoding an individual element's bitstream data. Data strings.Reader Idx Index Relocs []RelocEnt Bool decodes and returns a bool value from the element bitstream. Code decodes a Code value from the element bitstream and returns its ordinal value. It's the caller's responsibility to convert the result to an appropriate Code type. TODO(mdempsky): Ideally this method would have signature "Code[T Code] T" instead, but we don't allow generic methods and the compiler can't depend on generics yet anyway. Int decodes and returns an int value from the element bitstream. Int64 decodes and returns an int64 value from the element bitstream. Len decodes and returns a non-negative int value from the element bitstream. Reloc decodes a relocation of expected section k from the element bitstream and returns an index to the referenced element. String decodes and returns a string value from the element bitstream. Strings decodes and returns a variable-length slice of strings from the element bitstream. Sync decodes a sync marker from the element bitstream and asserts that it matches the expected marker. If EnableSync is false, then Sync is a no-op. Uint decodes and returns a uint value from the element bitstream. Int64 decodes and returns a uint64 value from the element bitstream. Value decodes and returns a constant.Value from the element bitstream. *Decoder : expvar.Var *Decoder : fmt.Stringer *Decoder : math/rand/v2.Source func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgDecoder).NewDecoderRaw(k RelocKind, idx Index) Decoder func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgDecoder).TempDecoderRaw(k RelocKind, idx Index) Decoder func (*PkgDecoder).RetireDecoder(d *Decoder)
An Encoder provides methods for encoding an individual element's bitstream data. // accumulated element bitstream data // index within relocation section RelocMap map[RelocEnt]uint32 Relocs []RelocEnt Bool encodes and writes a bool value into the element bitstream, and then returns the bool value. For simple, 2-alternative encodings, the idiomatic way to call Bool is something like: if w.Bool(x != 0) { // alternative #1 } else { // alternative #2 } For multi-alternative encodings, use Code instead. Code encodes and writes a Code value into the element bitstream. Flush finalizes the element's bitstream and returns its Index. Int encodes and writes an int value into the element bitstream. Int64 encodes and writes an int64 value into the element bitstream. Len encodes and writes a non-negative int value into the element bitstream. Reloc encodes and writes a relocation for the given (section, index) pair into the element bitstream. Note: Only the index is formally written into the element bitstream, so bitstream decoders must know from context which section an encoded relocation refers to. String encodes and writes a string value into the element bitstream. Internally, strings are deduplicated by adding them to the strings section (if not already present), and then writing a relocation into the element bitstream. StringRef writes a reference to the given index, which must be a previously encoded string value. Strings encodes and writes a variable-length slice of strings into the element bitstream. (*Encoder) Sync(m SyncMarker) Len encodes and writes a uint value into the element bitstream. Uint64 encodes and writes a uint64 value into the element bitstream. Value encodes and writes a constant.Value into the element bitstream. func (*PkgEncoder).NewEncoder(k RelocKind, marker SyncMarker) Encoder func (*PkgEncoder).NewEncoderRaw(k RelocKind) Encoder
An Index represents a bitstream element index within a particular section. func (*Decoder).Reloc(k RelocKind) Index func (*Encoder).Flush() Index func (*PkgEncoder).StringIdx(s string) Index func (*Encoder).Reloc(r RelocKind, idx Index) func (*Encoder).StringRef(idx Index) func (*PkgDecoder).AbsIdx(k RelocKind, idx Index) int func (*PkgDecoder).DataIdx(k RelocKind, idx Index) string func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgDecoder).NewDecoderRaw(k RelocKind, idx Index) Decoder func (*PkgDecoder).PeekObj(idx Index) (string, string, CodeObj) func (*PkgDecoder).PeekPkgPath(idx Index) string func (*PkgDecoder).StringIdx(idx Index) string func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgDecoder).TempDecoderRaw(k RelocKind, idx Index) Decoder const PrivateRootIdx const PublicRootIdx
A PkgDecoder provides methods for decoding a package's Unified IR export data. AbsIdx returns the absolute index for the given (section, index) pair. DataIdx returns the raw element bitstream for the given (section, index) pair. Fingerprint returns the package fingerprint. NewDecoder returns a Decoder for the given (section, index) pair, and decodes the given SyncMarker from the element bitstream. NewDecoderRaw returns a Decoder for the given (section, index) pair. Most callers should use NewDecoder instead. NumElems returns the number of elements in section k. PeekObj returns the package path, object name, and CodeObj for the specified object index. PeekPkgPath returns the package path for the specified package index. PkgPath returns the package path for the package TODO(mdempsky): Remove; unneeded since CL 391014. (*PkgDecoder) RetireDecoder(d *Decoder) StringIdx returns the string value for the given string index. SyncMarkers reports whether pr uses sync markers. TempDecoder returns a Decoder for the given (section, index) pair, and decodes the given SyncMarker from the element bitstream. If possible the Decoder should be RetireDecoder'd when it is no longer needed, this will avoid heap allocations. (*PkgDecoder) TempDecoderRaw(k RelocKind, idx Index) Decoder TotalElems returns the total number of elements across all sections. func NewPkgDecoder(pkgPath, input string) PkgDecoder
A PkgEncoder provides methods for encoding a package's Unified IR export data. DumpTo writes the package's encoded data to out0 and returns the package fingerprint. NewEncoder returns an Encoder for a new element within the given section, and encodes the given SyncMarker as the start of the element bitstream. NewEncoderRaw returns an Encoder for a new element within the given section. Most callers should use NewEncoder instead. StringIdx adds a string value to the strings section, if not already present, and returns its index. SyncMarkers reports whether pw uses sync markers. func NewPkgEncoder(syncFrames int) PkgEncoder
A relocEnt (relocation entry) is an entry in an element's local reference table. TODO(mdempsky): Rename this too. Idx Index Kind RelocKind
A RelocKind indicates a particular section within a unified IR export. func (*Decoder).Reloc(k RelocKind) Index func (*Encoder).Reloc(r RelocKind, idx Index) func (*PkgDecoder).AbsIdx(k RelocKind, idx Index) int func (*PkgDecoder).DataIdx(k RelocKind, idx Index) string func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgDecoder).NewDecoderRaw(k RelocKind, idx Index) Decoder func (*PkgDecoder).NumElems(k RelocKind) int func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgDecoder).TempDecoderRaw(k RelocKind, idx Index) Decoder func (*PkgEncoder).NewEncoder(k RelocKind, marker SyncMarker) Encoder func (*PkgEncoder).NewEncoderRaw(k RelocKind) Encoder const RelocBody const RelocMeta const RelocName const RelocObj const RelocObjDict const RelocObjExt const RelocPkg const RelocPosBase const RelocString const RelocType
SyncMarker is an enum type that represents markers that may be written to export data to ensure the reader and writer stay synchronized. ( SyncMarker) String() string SyncMarker : expvar.Var SyncMarker : fmt.Stringer func Code.Marker() SyncMarker func CodeObj.Marker() SyncMarker func CodeType.Marker() SyncMarker func CodeVal.Marker() SyncMarker func (*Decoder).Code(mark SyncMarker) int func (*Decoder).Sync(mWant SyncMarker) func (*Encoder).Sync(m SyncMarker) func (*PkgDecoder).NewDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgDecoder).TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoder func (*PkgEncoder).NewEncoder(k RelocKind, marker SyncMarker) Encoder const SyncAddLocal const SyncAssign const SyncBlockStmt const SyncBool const SyncCaseClause const SyncCloseAnotherScope const SyncCloseScope const SyncCodeObj const SyncCommClause const SyncCompLit const SyncConvRTTI const SyncDecl const SyncDeclName const SyncDeclNames const SyncDecls const SyncEOF const SyncExpr const SyncExprList const SyncExprs const SyncExprType const SyncForStmt const SyncFuncBody const SyncFuncExt const SyncFuncLit const SyncIfStmt const SyncInt64 const SyncLabel const SyncLabeledStmt const SyncLinkname const SyncLocalIdent const SyncMethod const SyncMultiExpr const SyncObject const SyncObject1 const SyncOp const SyncOpenScope const SyncOptLabel const SyncParam const SyncParams const SyncPkg const SyncPkgDef const SyncPos const SyncPosBase const SyncPragma const SyncPrivate const SyncPublic const SyncRangeStmt const SyncReloc const SyncRelocs const SyncRType const SyncSelector const SyncSelectStmt const SyncSignature const SyncStmt1 const SyncStmts const SyncStmtsEnd const SyncString const SyncSwitchStmt const SyncSym const SyncType const SyncTypeExt const SyncTypeIdx const SyncTypeParamNames const SyncUint64 const SyncUseObjLocal const SyncUseReloc const SyncVal const SyncValue const SyncVarExt
Package-Level Functions (total 2)
NewPkgDecoder returns a PkgDecoder initialized to read the Unified IR export data from input. pkgPath is the package path for the compilation unit that produced the export data. TODO(mdempsky): Remove pkgPath parameter; unneeded since CL 391014.
NewPkgEncoder returns an initialized PkgEncoder. syncFrames is the number of caller frames that should be serialized at Sync points. Serializing additional frames results in larger export data files, but can help diagnosing desync errors in higher-level Unified IR reader/writer code. If syncFrames is negative, then sync markers are omitted entirely.
Package-Level Constants (total 105)
const ObjAlias CodeObj = 0
const ObjConst CodeObj = 1
const ObjFunc CodeObj = 3
const ObjStub CodeObj = 5
const ObjType CodeObj = 2
const ObjVar CodeObj = 4
Reserved indices within the meta relocation section.
Reserved indices within the meta relocation section.
const RelocBody RelocKind = 9
const RelocMeta RelocKind = 1
const RelocName RelocKind = 4
const RelocObj RelocKind = 6
const RelocPkg RelocKind = 3
const RelocType RelocKind = 5
const SyncBool SyncMarker = 2
const SyncDecl SyncMarker = 42
const SyncDecls SyncMarker = 58
Low-level coding markers.
const SyncExpr SyncMarker = 36
const SyncExprs SyncMarker = 35
const SyncLabel SyncMarker = 65
const SyncOp SyncMarker = 39
const SyncParam SyncMarker = 24
const SyncPkg SyncMarker = 16
const SyncPos SyncMarker = 12
Private markers (only known to cmd/compile).
Higher-level object and type markers.
const SyncRType SyncMarker = 68
const SyncStmt1 SyncMarker = 63
const SyncStmts SyncMarker = 49
const SyncSym SyncMarker = 26
const SyncType SyncMarker = 19
const SyncVal SyncMarker = 7
const TypeArray CodeType = 4
const TypeBasic CodeType = 0
const TypeChan CodeType = 5
const TypeMap CodeType = 6
const TypeNamed CodeType = 1
const TypeSlice CodeType = 3
const TypeStruct CodeType = 8
const TypeUnion CodeType = 10
const ValBigFloat CodeVal = 5
const ValBigInt CodeVal = 3
const ValBigRat CodeVal = 4
const ValBool CodeVal = 0
const ValInt64 CodeVal = 2
const ValString CodeVal = 1