Imports #
"bytes"
"crypto/sha256"
"encoding/binary"
"go/constant"
"io"
"math/big"
"runtime"
"strings"
"fmt"
"fmt"
"runtime"
"strings"
"strconv"
"encoding/binary"
"errors"
"fmt"
"go/constant"
"go/token"
"io"
"math/big"
"os"
"runtime"
"strings"
"bytes"
"crypto/sha256"
"encoding/binary"
"go/constant"
"io"
"math/big"
"runtime"
"strings"
"fmt"
"fmt"
"runtime"
"strings"
"strconv"
"encoding/binary"
"errors"
"fmt"
"go/constant"
"go/token"
"io"
"math/big"
"os"
"runtime"
"strings"
ObjAlias has a list of TypeParamNames.
const AliasTypeParamNamesDeprecated: DerivedFuncInstance was a bool indicating whether an object was a function instance.
const DerivedFuncInstanceDeprecated: DerivedInfoNeeded was a bool indicating whether a type was a derived type.
const DerivedInfoNeededFlags in a uint32 in the header of a bitstream that is used to indicate whether optional features are enabled.
const Flags Field = iotaDeprecated: HasInit was a bool indicating whether a package has any init functions.
const HasInitconst ObjAlias CodeObj = iotaconst ObjConstconst ObjFuncconst ObjStubconst ObjTypeconst ObjVarReserved indices within the meta relocation section.
const PrivateRootIdx Index = 1Reserved indices within the meta relocation section.
const PublicRootIdx Index = 0const RelocBodyconst RelocMetaconst RelocNameconst RelocObjconst RelocObjDictconst RelocObjExtconst RelocPkgconst RelocPosBaseconst RelocString RelocKind = iotaconst RelocTypeconst SyncAddLocalconst SyncAssignconst SyncBlockStmtconst SyncBoolconst SyncCaseClauseconst SyncCloseAnotherScopeconst SyncCloseScopeconst SyncCodeObjconst SyncCommClauseconst SyncCompLitconst SyncConvRTTIconst SyncDeclconst SyncDeclNameconst SyncDeclNamesconst SyncDeclsLow-level coding markers.
const SyncEOFconst SyncExprconst SyncExprListconst SyncExprTypeconst SyncExprsconst SyncForStmtconst SyncFuncBodyconst SyncFuncExtconst SyncFuncLitconst SyncIfStmtconst SyncInt64const SyncLabelconst SyncLabeledStmtconst SyncLinknameconst SyncLocalIdentconst SyncMethodconst SyncMultiExprconst SyncObjectconst SyncObject1const SyncOpconst SyncOpenScopeconst SyncOptLabelconst SyncParamconst SyncParamsconst SyncPkgconst SyncPkgDefconst SyncPosconst SyncPosBaseconst SyncPragmaPrivate markers (only known to cmd/compile).
const SyncPrivateHigher-level object and type markers.
const SyncPublicconst SyncRTypeconst SyncRangeStmtconst SyncRelocconst SyncRelocsconst SyncSelectStmtconst SyncSelectorconst SyncSignatureconst SyncStmt1const SyncStmtsconst SyncStmtsEndconst SyncStringconst SyncSwitchStmtconst SyncSymconst SyncTypeconst SyncTypeExtconst SyncTypeIdxconst SyncTypeParamNamesconst SyncUint64const SyncUseObjLocalconst SyncUseRelocconst SyncValconst SyncValueconst SyncVarExtconst TypeArrayconst TypeBasic CodeType = iotaconst TypeChanconst TypeInterfaceconst TypeMapconst TypeNamedconst TypePointerconst TypeSignatureconst TypeSliceconst TypeStructconst TypeTypeParamconst TypeUnionV0: initial prototype. All data that is not assigned a Field is in version V0 and has not been deprecated.
const V0 Version = iotaV1: adds the Flags uint32 word
const V1V2: removes unused legacy fields and supports type parameters for aliases. - remove the legacy "has init" bool from the public root - remove obj's "derived func instance" bool - add a TypeParamNames field to ObjAlias - remove derived info "needed" bool
const V2const ValBigFloatconst ValBigIntconst ValBigRatconst ValBool CodeVal = iotaconst ValInt64const ValStringconst _ SyncMarker = iotavar _SyncMarker_index = [...]uint16{...}const _SyncMarker_name = "EOFBoolInt64Uint64StringValueValRelocsRelocUseRelocPublicPosPosBaseObjectObject1PkgPkgDefMethodTypeTypeIdxTypeParamNamesSignatureParamsParamCodeObjSymLocalIdentSelectorPrivateFuncExtVarExtTypeExtPragmaExprListExprsExprExprTypeAssignOpFuncLitCompLitDeclFuncBodyOpenScopeCloseScopeCloseAnotherScopeDeclNamesDeclNameStmtsBlockStmtIfStmtForStmtSwitchStmtRangeStmtCaseClauseCommClauseSelectStmtDeclsLabeledStmtUseObjLocalAddLocalLinknameStmt1StmtsEndLabelOptLabelMultiExprRTypeConvRTTI"const flagSyncMarkers = *ast.BinaryExprintroduced is the version a field was added.
var introduced = [numFields]Version{...}const numFields = iotaconst numRelocs = iotaconst numVersions = iotavar overflow = *ast.CallExprremoved is the version a field was removed in or 0 for fields that have not yet been deprecated. (So removed[f]-1 is the last version it is included in.)
var removed = [numFields]Version{...}A CodeObj distinguishes among go/types.Object encodings.
type CodeObj intA CodeType distinguishes among go/types.Type encodings.
type CodeType intA CodeVal distinguishes among go/constant.Value encodings.
type CodeVal intField denotes a unit of data in the serialized unified IR bitstream. It is conceptually a like field in a structure. We only really need Fields when the data may or may not be present in a stream based on the Version of the bitstream. Unlike much of pkgbits, Fields are not serialized and can change values as needed.
type Field intAn Index represents a bitstream element index within a particular section.
type Index int32A RelocKind indicates a particular section within a unified IR export.
type RelocKind int32SyncMarker is an enum type that represents markers that may be written to export data to ensure the reader and writer stay synchronized.
type SyncMarker intVersion indicates a version of a unified IR bitstream. Each Version indicates the addition, removal, or change of new data in the bitstream. These are serialized to disk and the interpretation remains fixed.
type Version uint32type frameVisitor func(file string, line int, name string, offset uintptr)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.
type Code interface {
Marker() SyncMarker
Value() int
}A Decoder provides methods for decoding an individual element's bitstream data.
type Decoder struct {
common *PkgDecoder
Relocs []RelocEnt
Data strings.Reader
k RelocKind
Idx Index
}An Encoder provides methods for encoding an individual element's bitstream data.
type Encoder struct {
p *PkgEncoder
Relocs []RelocEnt
RelocMap map[RelocEnt]uint32
Data bytes.Buffer
encodingRelocHeader bool
k RelocKind
Idx Index
}A PkgDecoder provides methods for decoding a package's Unified IR export data.
type PkgDecoder struct {
version Version
sync bool
pkgPath string
elemData string
elemEnds []uint32
elemEndsEnds [numRelocs]uint32
scratchRelocEnt []RelocEnt
}A PkgEncoder provides methods for encoding a package's Unified IR export data.
type PkgEncoder struct {
version Version
elems [numRelocs][]string
stringsIdx map[string]Index
syncFrames int
}A relocEnt (relocation entry) is an entry in an element's local reference table. TODO(mdempsky): Rename this too.
type RelocEnt struct {
Kind RelocKind
Idx Index
}AbsIdx returns the absolute index for the given (section, index) pair.
func (pr *PkgDecoder) AbsIdx(k RelocKind, idx Index) intBool decodes and returns a bool value from the element bitstream.
func (r *Decoder) Bool() boolBool 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.
func (w *Encoder) Bool(b bool) boolCode encodes and writes a Code value into the element bitstream.
func (w *Encoder) Code(c Code)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.
func (r *Decoder) Code(mark SyncMarker) intDataIdx returns the raw element bitstream for the given (section, index) pair.
func (pr *PkgDecoder) DataIdx(k RelocKind, idx Index) stringDumpTo writes the package's encoded data to out0 and returns the package fingerprint.
func (pw *PkgEncoder) DumpTo(out0 io.Writer) (fingerprint [8]byte)Fingerprint returns the package fingerprint.
func (pr *PkgDecoder) Fingerprint() [8]byteFlush finalizes the element's bitstream and returns its Index.
func (w *Encoder) Flush() IndexHas reports whether field f is present in a bitstream at version v.
func (v Version) Has(f Field) boolInt decodes and returns an int value from the element bitstream.
func (r *Decoder) Int() intInt encodes and writes an int value into the element bitstream.
func (w *Encoder) Int(x int)Int64 decodes and returns an int64 value from the element bitstream.
func (r *Decoder) Int64() int64Int64 encodes and writes an int64 value into the element bitstream.
func (w *Encoder) Int64(x int64)Len encodes and writes a non-negative int value into the element bitstream.
func (w *Encoder) Len(x int)Len decodes and returns a non-negative int value from the element bitstream.
func (r *Decoder) Len() intfunc (c CodeObj) Marker() SyncMarkerfunc (c CodeVal) Marker() SyncMarkerfunc (c CodeType) Marker() SyncMarkerNewDecoder returns a Decoder for the given (section, index) pair, and decodes the given SyncMarker from the element bitstream.
func (pr *PkgDecoder) NewDecoder(k RelocKind, idx Index, marker SyncMarker) DecoderNewDecoderRaw returns a Decoder for the given (section, index) pair. Most callers should use NewDecoder instead.
func (pr *PkgDecoder) NewDecoderRaw(k RelocKind, idx Index) DecoderNewEncoder returns an Encoder for a new element within the given section, and encodes the given SyncMarker as the start of the element bitstream.
func (pw *PkgEncoder) NewEncoder(k RelocKind, marker SyncMarker) EncoderNewEncoderRaw returns an Encoder for a new element within the given section. Most callers should use NewEncoder instead.
func (pw *PkgEncoder) NewEncoderRaw(k RelocKind) EncoderNewPkgDecoder 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.
func NewPkgDecoder(pkgPath string, input string) PkgDecoderNewPkgEncoder 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.
func NewPkgEncoder(version Version, syncFrames int) PkgEncoderNumElems returns the number of elements in section k.
func (pr *PkgDecoder) NumElems(k RelocKind) intPeekObj returns the package path, object name, and CodeObj for the specified object index.
func (pr *PkgDecoder) PeekObj(idx Index) (string, string, CodeObj)PeekPkgPath returns the package path for the specified package index.
func (pr *PkgDecoder) PeekPkgPath(idx Index) stringPkgPath returns the package path for the package TODO(mdempsky): Remove; unneeded since CL 391014.
func (pr *PkgDecoder) PkgPath() stringReloc 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.
func (w *Encoder) Reloc(r RelocKind, idx Index)Reloc decodes a relocation of expected section k from the element bitstream and returns an index to the referenced element.
func (r *Decoder) Reloc(k RelocKind) Indexfunc (pr *PkgDecoder) RetireDecoder(d *Decoder)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.
func (w *Encoder) String(s string)func (i SyncMarker) String() stringString decodes and returns a string value from the element bitstream.
func (r *Decoder) String() stringStringIdx returns the string value for the given string index.
func (pr *PkgDecoder) StringIdx(idx Index) stringStringIdx adds a string value to the strings section, if not already present, and returns its index.
func (pw *PkgEncoder) StringIdx(s string) IndexStringRef writes a reference to the given index, which must be a previously encoded string value.
func (w *Encoder) StringRef(idx Index)Strings encodes and writes a variable-length slice of strings into the element bitstream.
func (w *Encoder) Strings(ss []string)Strings decodes and returns a variable-length slice of strings from the element bitstream.
func (r *Decoder) Strings() []stringSync 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.
func (r *Decoder) Sync(mWant SyncMarker)func (w *Encoder) Sync(m SyncMarker)SyncMarkers reports whether pr uses sync markers.
func (pr *PkgDecoder) SyncMarkers() boolSyncMarkers reports whether pw uses sync markers.
func (pw *PkgEncoder) SyncMarkers() boolTempDecoder 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.
func (pr *PkgDecoder) TempDecoder(k RelocKind, idx Index, marker SyncMarker) Decoderfunc (pr *PkgDecoder) TempDecoderRaw(k RelocKind, idx Index) DecoderTotalElems returns the total number of elements across all sections.
func (pr *PkgDecoder) TotalElems() intUint encodes and writes a uint value into the element bitstream.
func (w *Encoder) Uint(x uint)Uint decodes and returns a uint value from the element bitstream.
func (r *Decoder) Uint() uintUint64 encodes and writes a uint64 value into the element bitstream.
func (w *Encoder) Uint64(x uint64)Uint64 decodes and returns a uint64 value from the element bitstream.
func (r *Decoder) Uint64() uint64Value decodes and returns a constant.Value from the element bitstream.
func (r *Decoder) Value() constant.ValueValue encodes and writes a constant.Value into the element bitstream.
func (w *Encoder) Value(val constant.Value)func (c CodeObj) Value() intfunc (c CodeType) Value() intfunc (c CodeVal) Value() intVersion reports the version of the bitstream.
func (w *Decoder) Version() VersionVersion reports the version of the bitstream.
func (w *Encoder) Version() Versionfunc _()func assert(b bool)func (r *Decoder) bigFloat() *big.Floatfunc (w *Encoder) bigFloat(v *big.Float)func (r *Decoder) bigInt() *big.Intfunc (w *Encoder) bigInt(v *big.Int)func (r *Decoder) checkErr(err error)func (w *Encoder) checkErr(err error)fmtFrames formats a backtrace for reporting reader/writer desyncs.
func fmtFrames(pcs ...uintptr) []stringfunc panicf(format string, args ...any)func (w *Encoder) rawReloc(r RelocKind, idx Index) intfunc (r *Decoder) rawReloc(k RelocKind, idx int) Indexfunc (r *Decoder) rawUvarint() uint64func (w *Encoder) rawUvarint(x uint64)func (r *Decoder) rawVarint() int64func (w *Encoder) rawVarint(x int64)readUvarint is a type-specialized copy of encoding/binary.ReadUvarint. This avoids the interface conversion and thus has better escape properties, which flows up the stack.
func readUvarint(r *strings.Reader) (uint64, error)func (w *Encoder) scalar(val constant.Value)func (r *Decoder) scalar() constant.ValuewalkFrames calls visit for each call frame represented by pcs. pcs should be a slice of PCs, as returned by runtime.Callers.
func walkFrames(pcs []uintptr, visit frameVisitor)Generated with Arrow