summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/tools/go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/tools/go')
-rw-r--r--vendor/golang.org/x/tools/go/gcexportdata/gcexportdata.go32
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go853
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/bimport.go1053
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/exportdata.go99
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/gcimporter.go1125
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go1010
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go878
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/newInterface10.go22
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/newInterface11.go14
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go16
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go23
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/unified_no.go10
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/unified_yes.go10
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/ureader_no.go19
-rw-r--r--vendor/golang.org/x/tools/go/internal/gcimporter/ureader_yes.go612
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/codes.go77
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/decoder.go433
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/doc.go32
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/encoder.go379
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/flags.go9
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/frames_go1.go21
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/frames_go17.go28
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/reloc.go42
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/support.go17
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/sync.go113
-rw-r--r--vendor/golang.org/x/tools/go/internal/pkgbits/syncmarker_string.go89
-rw-r--r--vendor/golang.org/x/tools/go/packages/golist.go22
-rw-r--r--vendor/golang.org/x/tools/go/packages/packages.go87
28 files changed, 102 insertions, 7023 deletions
diff --git a/vendor/golang.org/x/tools/go/gcexportdata/gcexportdata.go b/vendor/golang.org/x/tools/go/gcexportdata/gcexportdata.go
index 2ed25a75..165ede0f 100644
--- a/vendor/golang.org/x/tools/go/gcexportdata/gcexportdata.go
+++ b/vendor/golang.org/x/tools/go/gcexportdata/gcexportdata.go
@@ -27,10 +27,9 @@ import (
"go/token"
"go/types"
"io"
- "io/ioutil"
"os/exec"
- "golang.org/x/tools/go/internal/gcimporter"
+ "golang.org/x/tools/internal/gcimporter"
)
// Find returns the name of an object (.o) or archive (.a) file
@@ -85,9 +84,26 @@ func NewReader(r io.Reader) (io.Reader, error) {
}
}
+// readAll works the same way as io.ReadAll, but avoids allocations and copies
+// by preallocating a byte slice of the necessary size if the size is known up
+// front. This is always possible when the input is an archive. In that case,
+// NewReader will return the known size using an io.LimitedReader.
+func readAll(r io.Reader) ([]byte, error) {
+ if lr, ok := r.(*io.LimitedReader); ok {
+ data := make([]byte, lr.N)
+ _, err := io.ReadFull(lr, data)
+ return data, err
+ }
+ return io.ReadAll(r)
+}
+
// Read reads export data from in, decodes it, and returns type
// information for the package.
-// The package name is specified by path.
+//
+// The package path (effectively its linker symbol prefix) is
+// specified by path, since unlike the package name, this information
+// may not be recorded in the export data.
+//
// File position information is added to fset.
//
// Read may inspect and add to the imports map to ensure that references
@@ -98,7 +114,7 @@ func NewReader(r io.Reader) (io.Reader, error) {
//
// On return, the state of the reader is undefined.
func Read(in io.Reader, fset *token.FileSet, imports map[string]*types.Package, path string) (*types.Package, error) {
- data, err := ioutil.ReadAll(in)
+ data, err := readAll(in)
if err != nil {
return nil, fmt.Errorf("reading export data for %q: %v", path, err)
}
@@ -107,12 +123,6 @@ func Read(in io.Reader, fset *token.FileSet, imports map[string]*types.Package,
return nil, fmt.Errorf("can't read export data for %q directly from an archive file (call gcexportdata.NewReader first to extract export data)", path)
}
- // The App Engine Go runtime v1.6 uses the old export data format.
- // TODO(adonovan): delete once v1.7 has been around for a while.
- if bytes.HasPrefix(data, []byte("package ")) {
- return gcimporter.ImportData(imports, path, path, bytes.NewReader(data))
- }
-
// The indexed export format starts with an 'i'; the older
// binary export format starts with a 'c', 'd', or 'v'
// (from "version"). Select appropriate importer.
@@ -161,7 +171,7 @@ func Write(out io.Writer, fset *token.FileSet, pkg *types.Package) error {
//
// Experimental: This API is experimental and may change in the future.
func ReadBundle(in io.Reader, fset *token.FileSet, imports map[string]*types.Package) ([]*types.Package, error) {
- data, err := ioutil.ReadAll(in)
+ data, err := readAll(in)
if err != nil {
return nil, fmt.Errorf("reading export bundle: %v", err)
}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go b/vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go
deleted file mode 100644
index 196cb3f9..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go
+++ /dev/null
@@ -1,853 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Binary package export.
-// This file was derived from $GOROOT/src/cmd/compile/internal/gc/bexport.go;
-// see that file for specification of the format.
-
-package gcimporter
-
-import (
- "bytes"
- "encoding/binary"
- "fmt"
- "go/ast"
- "go/constant"
- "go/token"
- "go/types"
- "math"
- "math/big"
- "sort"
- "strings"
-)
-
-// If debugFormat is set, each integer and string value is preceded by a marker
-// and position information in the encoding. This mechanism permits an importer
-// to recognize immediately when it is out of sync. The importer recognizes this
-// mode automatically (i.e., it can import export data produced with debugging
-// support even if debugFormat is not set at the time of import). This mode will
-// lead to massively larger export data (by a factor of 2 to 3) and should only
-// be enabled during development and debugging.
-//
-// NOTE: This flag is the first flag to enable if importing dies because of
-// (suspected) format errors, and whenever a change is made to the format.
-const debugFormat = false // default: false
-
-// Current export format version. Increase with each format change.
-//
-// Note: The latest binary (non-indexed) export format is at version 6.
-// This exporter is still at level 4, but it doesn't matter since
-// the binary importer can handle older versions just fine.
-//
-// 6: package height (CL 105038) -- NOT IMPLEMENTED HERE
-// 5: improved position encoding efficiency (issue 20080, CL 41619) -- NOT IMPLEMENTED HERE
-// 4: type name objects support type aliases, uses aliasTag
-// 3: Go1.8 encoding (same as version 2, aliasTag defined but never used)
-// 2: removed unused bool in ODCL export (compiler only)
-// 1: header format change (more regular), export package for _ struct fields
-// 0: Go1.7 encoding
-const exportVersion = 4
-
-// trackAllTypes enables cycle tracking for all types, not just named
-// types. The existing compiler invariants assume that unnamed types
-// that are not completely set up are not used, or else there are spurious
-// errors.
-// If disabled, only named types are tracked, possibly leading to slightly
-// less efficient encoding in rare cases. It also prevents the export of
-// some corner-case type declarations (but those are not handled correctly
-// with with the textual export format either).
-// TODO(gri) enable and remove once issues caused by it are fixed
-const trackAllTypes = false
-
-type exporter struct {
- fset *token.FileSet
- out bytes.Buffer
-
- // object -> index maps, indexed in order of serialization
- strIndex map[string]int
- pkgIndex map[*types.Package]int
- typIndex map[types.Type]int
-
- // position encoding
- posInfoFormat bool
- prevFile string
- prevLine int
-
- // debugging support
- written int // bytes written
- indent int // for trace
-}
-
-// internalError represents an error generated inside this package.
-type internalError string
-
-func (e internalError) Error() string { return "gcimporter: " + string(e) }
-
-func internalErrorf(format string, args ...interface{}) error {
- return internalError(fmt.Sprintf(format, args...))
-}
-
-// BExportData returns binary export data for pkg.
-// If no file set is provided, position info will be missing.
-func BExportData(fset *token.FileSet, pkg *types.Package) (b []byte, err error) {
- if !debug {
- defer func() {
- if e := recover(); e != nil {
- if ierr, ok := e.(internalError); ok {
- err = ierr
- return
- }
- // Not an internal error; panic again.
- panic(e)
- }
- }()
- }
-
- p := exporter{
- fset: fset,
- strIndex: map[string]int{"": 0}, // empty string is mapped to 0
- pkgIndex: make(map[*types.Package]int),
- typIndex: make(map[types.Type]int),
- posInfoFormat: true, // TODO(gri) might become a flag, eventually
- }
-
- // write version info
- // The version string must start with "version %d" where %d is the version
- // number. Additional debugging information may follow after a blank; that
- // text is ignored by the importer.
- p.rawStringln(fmt.Sprintf("version %d", exportVersion))
- var debug string
- if debugFormat {
- debug = "debug"
- }
- p.rawStringln(debug) // cannot use p.bool since it's affected by debugFormat; also want to see this clearly
- p.bool(trackAllTypes)
- p.bool(p.posInfoFormat)
-
- // --- generic export data ---
-
- // populate type map with predeclared "known" types
- for index, typ := range predeclared() {
- p.typIndex[typ] = index
- }
- if len(p.typIndex) != len(predeclared()) {
- return nil, internalError("duplicate entries in type map?")
- }
-
- // write package data
- p.pkg(pkg, true)
- if trace {
- p.tracef("\n")
- }
-
- // write objects
- objcount := 0
- scope := pkg.Scope()
- for _, name := range scope.Names() {
- if !ast.IsExported(name) {
- continue
- }
- if trace {
- p.tracef("\n")
- }
- p.obj(scope.Lookup(name))
- objcount++
- }
-
- // indicate end of list
- if trace {
- p.tracef("\n")
- }
- p.tag(endTag)
-
- // for self-verification only (redundant)
- p.int(objcount)
-
- if trace {
- p.tracef("\n")
- }
-
- // --- end of export data ---
-
- return p.out.Bytes(), nil
-}
-
-func (p *exporter) pkg(pkg *types.Package, emptypath bool) {
- if pkg == nil {
- panic(internalError("unexpected nil pkg"))
- }
-
- // if we saw the package before, write its index (>= 0)
- if i, ok := p.pkgIndex[pkg]; ok {
- p.index('P', i)
- return
- }
-
- // otherwise, remember the package, write the package tag (< 0) and package data
- if trace {
- p.tracef("P%d = { ", len(p.pkgIndex))
- defer p.tracef("} ")
- }
- p.pkgIndex[pkg] = len(p.pkgIndex)
-
- p.tag(packageTag)
- p.string(pkg.Name())
- if emptypath {
- p.string("")
- } else {
- p.string(pkg.Path())
- }
-}
-
-func (p *exporter) obj(obj types.Object) {
- switch obj := obj.(type) {
- case *types.Const:
- p.tag(constTag)
- p.pos(obj)
- p.qualifiedName(obj)
- p.typ(obj.Type())
- p.value(obj.Val())
-
- case *types.TypeName:
- if obj.IsAlias() {
- p.tag(aliasTag)
- p.pos(obj)
- p.qualifiedName(obj)
- } else {
- p.tag(typeTag)
- }
- p.typ(obj.Type())
-
- case *types.Var:
- p.tag(varTag)
- p.pos(obj)
- p.qualifiedName(obj)
- p.typ(obj.Type())
-
- case *types.Func:
- p.tag(funcTag)
- p.pos(obj)
- p.qualifiedName(obj)
- sig := obj.Type().(*types.Signature)
- p.paramList(sig.Params(), sig.Variadic())
- p.paramList(sig.Results(), false)
-
- default:
- panic(internalErrorf("unexpected object %v (%T)", obj, obj))
- }
-}
-
-func (p *exporter) pos(obj types.Object) {
- if !p.posInfoFormat {
- return
- }
-
- file, line := p.fileLine(obj)
- if file == p.prevFile {
- // common case: write line delta
- // delta == 0 means different file or no line change
- delta := line - p.prevLine
- p.int(delta)
- if delta == 0 {
- p.int(-1) // -1 means no file change
- }
- } else {
- // different file
- p.int(0)
- // Encode filename as length of common prefix with previous
- // filename, followed by (possibly empty) suffix. Filenames
- // frequently share path prefixes, so this can save a lot
- // of space and make export data size less dependent on file
- // path length. The suffix is unlikely to be empty because
- // file names tend to end in ".go".
- n := commonPrefixLen(p.prevFile, file)
- p.int(n) // n >= 0
- p.string(file[n:]) // write suffix only
- p.prevFile = file
- p.int(line)
- }
- p.prevLine = line
-}
-
-func (p *exporter) fileLine(obj types.Object) (file string, line int) {
- if p.fset != nil {
- pos := p.fset.Position(obj.Pos())
- file = pos.Filename
- line = pos.Line
- }
- return
-}
-
-func commonPrefixLen(a, b string) int {
- if len(a) > len(b) {
- a, b = b, a
- }
- // len(a) <= len(b)
- i := 0
- for i < len(a) && a[i] == b[i] {
- i++
- }
- return i
-}
-
-func (p *exporter) qualifiedName(obj types.Object) {
- p.string(obj.Name())
- p.pkg(obj.Pkg(), false)
-}
-
-func (p *exporter) typ(t types.Type) {
- if t == nil {
- panic(internalError("nil type"))
- }
-
- // Possible optimization: Anonymous pointer types *T where
- // T is a named type are common. We could canonicalize all
- // such types *T to a single type PT = *T. This would lead
- // to at most one *T entry in typIndex, and all future *T's
- // would be encoded as the respective index directly. Would
- // save 1 byte (pointerTag) per *T and reduce the typIndex
- // size (at the cost of a canonicalization map). We can do
- // this later, without encoding format change.
-
- // if we saw the type before, write its index (>= 0)
- if i, ok := p.typIndex[t]; ok {
- p.index('T', i)
- return
- }
-
- // otherwise, remember the type, write the type tag (< 0) and type data
- if trackAllTypes {
- if trace {
- p.tracef("T%d = {>\n", len(p.typIndex))
- defer p.tracef("<\n} ")
- }
- p.typIndex[t] = len(p.typIndex)
- }
-
- switch t := t.(type) {
- case *types.Named:
- if !trackAllTypes {
- // if we don't track all types, track named types now
- p.typIndex[t] = len(p.typIndex)
- }
-
- p.tag(namedTag)
- p.pos(t.Obj())
- p.qualifiedName(t.Obj())
- p.typ(t.Underlying())
- if !types.IsInterface(t) {
- p.assocMethods(t)
- }
-
- case *types.Array:
- p.tag(arrayTag)
- p.int64(t.Len())
- p.typ(t.Elem())
-
- case *types.Slice:
- p.tag(sliceTag)
- p.typ(t.Elem())
-
- case *dddSlice:
- p.tag(dddTag)
- p.typ(t.elem)
-
- case *types.Struct:
- p.tag(structTag)
- p.fieldList(t)
-
- case *types.Pointer:
- p.tag(pointerTag)
- p.typ(t.Elem())
-
- case *types.Signature:
- p.tag(signatureTag)
- p.paramList(t.Params(), t.Variadic())
- p.paramList(t.Results(), false)
-
- case *types.Interface:
- p.tag(interfaceTag)
- p.iface(t)
-
- case *types.Map:
- p.tag(mapTag)
- p.typ(t.Key())
- p.typ(t.Elem())
-
- case *types.Chan:
- p.tag(chanTag)
- p.int(int(3 - t.Dir())) // hack
- p.typ(t.Elem())
-
- default:
- panic(internalErrorf("unexpected type %T: %s", t, t))
- }
-}
-
-func (p *exporter) assocMethods(named *types.Named) {
- // Sort methods (for determinism).
- var methods []*types.Func
- for i := 0; i < named.NumMethods(); i++ {
- methods = append(methods, named.Method(i))
- }
- sort.Sort(methodsByName(methods))
-
- p.int(len(methods))
-
- if trace && methods != nil {
- p.tracef("associated methods {>\n")
- }
-
- for i, m := range methods {
- if trace && i > 0 {
- p.tracef("\n")
- }
-
- p.pos(m)
- name := m.Name()
- p.string(name)
- if !exported(name) {
- p.pkg(m.Pkg(), false)
- }
-
- sig := m.Type().(*types.Signature)
- p.paramList(types.NewTuple(sig.Recv()), false)
- p.paramList(sig.Params(), sig.Variadic())
- p.paramList(sig.Results(), false)
- p.int(0) // dummy value for go:nointerface pragma - ignored by importer
- }
-
- if trace && methods != nil {
- p.tracef("<\n} ")
- }
-}
-
-type methodsByName []*types.Func
-
-func (x methodsByName) Len() int { return len(x) }
-func (x methodsByName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
-func (x methodsByName) Less(i, j int) bool { return x[i].Name() < x[j].Name() }
-
-func (p *exporter) fieldList(t *types.Struct) {
- if trace && t.NumFields() > 0 {
- p.tracef("fields {>\n")
- defer p.tracef("<\n} ")
- }
-
- p.int(t.NumFields())
- for i := 0; i < t.NumFields(); i++ {
- if trace && i > 0 {
- p.tracef("\n")
- }
- p.field(t.Field(i))
- p.string(t.Tag(i))
- }
-}
-
-func (p *exporter) field(f *types.Var) {
- if !f.IsField() {
- panic(internalError("field expected"))
- }
-
- p.pos(f)
- p.fieldName(f)
- p.typ(f.Type())
-}
-
-func (p *exporter) iface(t *types.Interface) {
- // TODO(gri): enable importer to load embedded interfaces,
- // then emit Embeddeds and ExplicitMethods separately here.
- p.int(0)
-
- n := t.NumMethods()
- if trace && n > 0 {
- p.tracef("methods {>\n")
- defer p.tracef("<\n} ")
- }
- p.int(n)
- for i := 0; i < n; i++ {
- if trace && i > 0 {
- p.tracef("\n")
- }
- p.method(t.Method(i))
- }
-}
-
-func (p *exporter) method(m *types.Func) {
- sig := m.Type().(*types.Signature)
- if sig.Recv() == nil {
- panic(internalError("method expected"))
- }
-
- p.pos(m)
- p.string(m.Name())
- if m.Name() != "_" && !ast.IsExported(m.Name()) {
- p.pkg(m.Pkg(), false)
- }
-
- // interface method; no need to encode receiver.
- p.paramList(sig.Params(), sig.Variadic())
- p.paramList(sig.Results(), false)
-}
-
-func (p *exporter) fieldName(f *types.Var) {
- name := f.Name()
-
- if f.Anonymous() {
- // anonymous field - we distinguish between 3 cases:
- // 1) field name matches base type name and is exported
- // 2) field name matches base type name and is not exported
- // 3) field name doesn't match base type name (alias name)
- bname := basetypeName(f.Type())
- if name == bname {
- if ast.IsExported(name) {
- name = "" // 1) we don't need to know the field name or package
- } else {
- name = "?" // 2) use unexported name "?" to force package export
- }
- } else {
- // 3) indicate alias and export name as is
- // (this requires an extra "@" but this is a rare case)
- p.string("@")
- }
- }
-
- p.string(name)
- if name != "" && !ast.IsExported(name) {
- p.pkg(f.Pkg(), false)
- }
-}
-
-func basetypeName(typ types.Type) string {
- switch typ := deref(typ).(type) {
- case *types.Basic:
- return typ.Name()
- case *types.Named:
- return typ.Obj().Name()
- default:
- return "" // unnamed type
- }
-}
-
-func (p *exporter) paramList(params *types.Tuple, variadic bool) {
- // use negative length to indicate unnamed parameters
- // (look at the first parameter only since either all
- // names are present or all are absent)
- n := params.Len()
- if n > 0 && params.At(0).Name() == "" {
- n = -n
- }
- p.int(n)
- for i := 0; i < params.Len(); i++ {
- q := params.At(i)
- t := q.Type()
- if variadic && i == params.Len()-1 {
- t = &dddSlice{t.(*types.Slice).Elem()}
- }
- p.typ(t)
- if n > 0 {
- name := q.Name()
- p.string(name)
- if name != "_" {
- p.pkg(q.Pkg(), false)
- }
- }
- p.string("") // no compiler-specific info
- }
-}
-
-func (p *exporter) value(x constant.Value) {
- if trace {
- p.tracef("= ")
- }
-
- switch x.Kind() {
- case constant.Bool:
- tag := falseTag
- if constant.BoolVal(x) {
- tag = trueTag
- }
- p.tag(tag)
-
- case constant.Int:
- if v, exact := constant.Int64Val(x); exact {
- // common case: x fits into an int64 - use compact encoding
- p.tag(int64Tag)
- p.int64(v)
- return
- }
- // uncommon case: large x - use float encoding
- // (powers of 2 will be encoded efficiently with exponent)
- p.tag(floatTag)
- p.float(constant.ToFloat(x))
-
- case constant.Float:
- p.tag(floatTag)
- p.float(x)
-
- case constant.Complex:
- p.tag(complexTag)
- p.float(constant.Real(x))
- p.float(constant.Imag(x))
-
- case constant.String:
- p.tag(stringTag)
- p.string(constant.StringVal(x))
-
- case constant.Unknown:
- // package contains type errors
- p.tag(unknownTag)
-
- default:
- panic(internalErrorf("unexpected value %v (%T)", x, x))
- }
-}
-
-func (p *exporter) float(x constant.Value) {
- if x.Kind() != constant.Float {
- panic(internalErrorf("unexpected constant %v, want float", x))
- }
- // extract sign (there is no -0)
- sign := constant.Sign(x)
- if sign == 0 {
- // x == 0
- p.int(0)
- return
- }
- // x != 0
-
- var f big.Float
- if v, exact := constant.Float64Val(x); exact {
- // float64
- f.SetFloat64(v)
- } else if num, denom := constant.Num(x), constant.Denom(x); num.Kind() == constant.Int {
- // TODO(gri): add big.Rat accessor to constant.Value.
- r := valueToRat(num)
- f.SetRat(r.Quo(r, valueToRat(denom)))
- } else {
- // Value too large to represent as a fraction => inaccessible.
- // TODO(gri): add big.Float accessor to constant.Value.
- f.SetFloat64(math.MaxFloat64) // FIXME
- }
-
- // extract exponent such that 0.5 <= m < 1.0
- var m big.Float
- exp := f.MantExp(&m)
-
- // extract mantissa as *big.Int
- // - set exponent large enough so mant satisfies mant.IsInt()
- // - get *big.Int from mant
- m.SetMantExp(&m, int(m.MinPrec()))
- mant, acc := m.Int(nil)
- if acc != big.Exact {
- panic(internalError("internal error"))
- }
-
- p.int(sign)
- p.int(exp)
- p.string(string(mant.Bytes()))
-}
-
-func valueToRat(x constant.Value) *big.Rat {
- // Convert little-endian to big-endian.
- // I can't believe this is necessary.
- bytes := constant.Bytes(x)
- for i := 0; i < len(bytes)/2; i++ {
- bytes[i], bytes[len(bytes)-1-i] = bytes[len(bytes)-1-i], bytes[i]
- }
- return new(big.Rat).SetInt(new(big.Int).SetBytes(bytes))
-}
-
-func (p *exporter) bool(b bool) bool {
- if trace {
- p.tracef("[")
- defer p.tracef("= %v] ", b)
- }
-
- x := 0
- if b {
- x = 1
- }
- p.int(x)
- return b
-}
-
-// ----------------------------------------------------------------------------
-// Low-level encoders
-
-func (p *exporter) index(marker byte, index int) {
- if index < 0 {
- panic(internalError("invalid index < 0"))
- }
- if debugFormat {
- p.marker('t')
- }
- if trace {
- p.tracef("%c%d ", marker, index)
- }
- p.rawInt64(int64(index))
-}
-
-func (p *exporter) tag(tag int) {
- if tag >= 0 {
- panic(internalError("invalid tag >= 0"))
- }
- if debugFormat {
- p.marker('t')
- }
- if trace {
- p.tracef("%s ", tagString[-tag])
- }
- p.rawInt64(int64(tag))
-}
-
-func (p *exporter) int(x int) {
- p.int64(int64(x))
-}
-
-func (p *exporter) int64(x int64) {
- if debugFormat {
- p.marker('i')
- }
- if trace {
- p.tracef("%d ", x)
- }
- p.rawInt64(x)
-}
-
-func (p *exporter) string(s string) {
- if debugFormat {
- p.marker('s')
- }
- if trace {
- p.tracef("%q ", s)
- }
- // if we saw the string before, write its index (>= 0)
- // (the empty string is mapped to 0)
- if i, ok := p.strIndex[s]; ok {
- p.rawInt64(int64(i))
- return
- }
- // otherwise, remember string and write its negative length and bytes
- p.strIndex[s] = len(p.strIndex)
- p.rawInt64(-int64(len(s)))
- for i := 0; i < len(s); i++ {
- p.rawByte(s[i])
- }
-}
-
-// marker emits a marker byte and position information which makes
-// it easy for a reader to detect if it is "out of sync". Used for
-// debugFormat format only.
-func (p *exporter) marker(m byte) {
- p.rawByte(m)
- // Enable this for help tracking down the location
- // of an incorrect marker when running in debugFormat.
- if false && trace {
- p.tracef("#%d ", p.written)
- }
- p.rawInt64(int64(p.written))
-}
-
-// rawInt64 should only be used by low-level encoders.
-func (p *exporter) rawInt64(x int64) {
- var tmp [binary.MaxVarintLen64]byte
- n := binary.PutVarint(tmp[:], x)
- for i := 0; i < n; i++ {
- p.rawByte(tmp[i])
- }
-}
-
-// rawStringln should only be used to emit the initial version string.
-func (p *exporter) rawStringln(s string) {
- for i := 0; i < len(s); i++ {
- p.rawByte(s[i])
- }
- p.rawByte('\n')
-}
-
-// rawByte is the bottleneck interface to write to p.out.
-// rawByte escapes b as follows (any encoding does that
-// hides '$'):
-//
-// '$' => '|' 'S'
-// '|' => '|' '|'
-//
-// Necessary so other tools can find the end of the
-// export data by searching for "$$".
-// rawByte should only be used by low-level encoders.
-func (p *exporter) rawByte(b byte) {
- switch b {
- case '$':
- // write '$' as '|' 'S'
- b = 'S'
- fallthrough
- case '|':
- // write '|' as '|' '|'
- p.out.WriteByte('|')
- p.written++
- }
- p.out.WriteByte(b)
- p.written++
-}
-
-// tracef is like fmt.Printf but it rewrites the format string
-// to take care of indentation.
-func (p *exporter) tracef(format string, args ...interface{}) {
- if strings.ContainsAny(format, "<>\n") {
- var buf bytes.Buffer
- for i := 0; i < len(format); i++ {
- // no need to deal with runes
- ch := format[i]
- switch ch {
- case '>':
- p.indent++
- continue
- case '<':
- p.indent--
- continue
- }
- buf.WriteByte(ch)
- if ch == '\n' {
- for j := p.indent; j > 0; j-- {
- buf.WriteString(". ")
- }
- }
- }
- format = buf.String()
- }
- fmt.Printf(format, args...)
-}
-
-// Debugging support.
-// (tagString is only used when tracing is enabled)
-var tagString = [...]string{
- // Packages
- -packageTag: "package",
-
- // Types
- -namedTag: "named type",
- -arrayTag: "array",
- -sliceTag: "slice",
- -dddTag: "ddd",
- -structTag: "struct",
- -pointerTag: "pointer",
- -signatureTag: "signature",
- -interfaceTag: "interface",
- -mapTag: "map",
- -chanTag: "chan",
-
- // Values
- -falseTag: "false",
- -trueTag: "true",
- -int64Tag: "int64",
- -floatTag: "float",
- -fractionTag: "fraction",
- -complexTag: "complex",
- -stringTag: "string",
- -unknownTag: "unknown",
-
- // Type aliases
- -aliasTag: "alias",
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/bimport.go b/vendor/golang.org/x/tools/go/internal/gcimporter/bimport.go
deleted file mode 100644
index b85de014..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/bimport.go
+++ /dev/null
@@ -1,1053 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file is a copy of $GOROOT/src/go/internal/gcimporter/bimport.go.
-
-package gcimporter
-
-import (
- "encoding/binary"
- "fmt"
- "go/constant"
- "go/token"
- "go/types"
- "sort"
- "strconv"
- "strings"
- "sync"
- "unicode"
- "unicode/utf8"
-)
-
-type importer struct {
- imports map[string]*types.Package
- data []byte
- importpath string
- buf []byte // for reading strings
- version int // export format version
-
- // object lists
- strList []string // in order of appearance
- pathList []string // in order of appearance
- pkgList []*types.Package // in order of appearance
- typList []types.Type // in order of appearance
- interfaceList []*types.Interface // for delayed completion only
- trackAllTypes bool
-
- // position encoding
- posInfoFormat bool
- prevFile string
- prevLine int
- fake fakeFileSet
-
- // debugging support
- debugFormat bool
- read int // bytes read
-}
-
-// BImportData imports a package from the serialized package data
-// and returns the number of bytes consumed and a reference to the package.
-// If the export data version is not recognized or the format is otherwise
-// compromised, an error is returned.
-func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) {
- // catch panics and return them as errors
- const currentVersion = 6
- version := -1 // unknown version
- defer func() {
- if e := recover(); e != nil {
- // Return a (possibly nil or incomplete) package unchanged (see #16088).
- if version > currentVersion {
- err = fmt.Errorf("cannot import %q (%v), export data is newer version - update tool", path, e)
- } else {
- err = fmt.Errorf("cannot import %q (%v), possibly version skew - reinstall package", path, e)
- }
- }
- }()
-
- p := importer{
- imports: imports,
- data: data,
- importpath: path,
- version: version,
- strList: []string{""}, // empty string is mapped to 0
- pathList: []string{""}, // empty string is mapped to 0
- fake: fakeFileSet{
- fset: fset,
- files: make(map[string]*fileInfo),
- },
- }
- defer p.fake.setLines() // set lines for files in fset
-
- // read version info
- var versionstr string
- if b := p.rawByte(); b == 'c' || b == 'd' {
- // Go1.7 encoding; first byte encodes low-level
- // encoding format (compact vs debug).
- // For backward-compatibility only (avoid problems with
- // old installed packages). Newly compiled packages use
- // the extensible format string.
- // TODO(gri) Remove this support eventually; after Go1.8.
- if b == 'd' {
- p.debugFormat = true
- }
- p.trackAllTypes = p.rawByte() == 'a'
- p.posInfoFormat = p.int() != 0
- versionstr = p.string()
- if versionstr == "v1" {
- version = 0
- }
- } else {
- // Go1.8 extensible encoding
- // read version string and extract version number (ignore anything after the version number)
- versionstr = p.rawStringln(b)
- if s := strings.SplitN(versionstr, " ", 3); len(s) >= 2 && s[0] == "version" {
- if v, err := strconv.Atoi(s[1]); err == nil && v > 0 {
- version = v
- }
- }
- }
- p.version = version
-
- // read version specific flags - extend as necessary
- switch p.version {
- // case currentVersion:
- // ...
- // fallthrough
- case currentVersion, 5, 4, 3, 2, 1:
- p.debugFormat = p.rawStringln(p.rawByte()) == "debug"
- p.trackAllTypes = p.int() != 0
- p.posInfoFormat = p.int() != 0
- case 0:
- // Go1.7 encoding format - nothing to do here
- default:
- errorf("unknown bexport format version %d (%q)", p.version, versionstr)
- }
-
- // --- generic export data ---
-
- // populate typList with predeclared "known" types
- p.typList = append(p.typList, predeclared()...)
-
- // read package data
- pkg = p.pkg()
-
- // read objects of phase 1 only (see cmd/compile/internal/gc/bexport.go)
- objcount := 0
- for {
- tag := p.tagOrIndex()
- if tag == endTag {
- break
- }
- p.obj(tag)
- objcount++
- }
-
- // self-verification
- if count := p.int(); count != objcount {
- errorf("got %d objects; want %d", objcount, count)
- }
-
- // ignore compiler-specific import data
-
- // complete interfaces
- // TODO(gri) re-investigate if we still need to do this in a delayed fashion
- for _, typ := range p.interfaceList {
- typ.Complete()
- }
-
- // record all referenced packages as imports
- list := append(([]*types.Package)(nil), p.pkgList[1:]...)
- sort.Sort(byPath(list))
- pkg.SetImports(list)
-
- // package was imported completely and without errors
- pkg.MarkComplete()
-
- return p.read, pkg, nil
-}
-
-func errorf(format string, args ...interface{}) {
- panic(fmt.Sprintf(format, args...))
-}
-
-func (p *importer) pkg() *types.Package {
- // if the package was seen before, i is its index (>= 0)
- i := p.tagOrIndex()
- if i >= 0 {
- return p.pkgList[i]
- }
-
- // otherwise, i is the package tag (< 0)
- if i != packageTag {
- errorf("unexpected package tag %d version %d", i, p.version)
- }
-
- // read package data
- name := p.string()
- var path string
- if p.version >= 5 {
- path = p.path()
- } else {
- path = p.string()
- }
- if p.version >= 6 {
- p.int() // package height; unused by go/types
- }
-
- // we should never see an empty package name
- if name == "" {
- errorf("empty package name in import")
- }
-
- // an empty path denotes the package we are currently importing;
- // it must be the first package we see
- if (path == "") != (len(p.pkgList) == 0) {
- errorf("package path %q for pkg index %d", path, len(p.pkgList))
- }
-
- // if the package was imported before, use that one; otherwise create a new one
- if path == "" {
- path = p.importpath
- }
- pkg := p.imports[path]
- if pkg == nil {
- pkg = types.NewPackage(path, name)
- p.imports[path] = pkg
- } else if pkg.Name() != name {
- errorf("conflicting names %s and %s for package %q", pkg.Name(), name, path)
- }
- p.pkgList = append(p.pkgList, pkg)
-
- return pkg
-}
-
-// objTag returns the tag value for each object kind.
-func objTag(obj types.Object) int {
- switch obj.(type) {
- case *types.Const:
- return constTag
- case *types.TypeName:
- return typeTag
- case *types.Var:
- return varTag
- case *types.Func:
- return funcTag
- default:
- errorf("unexpected object: %v (%T)", obj, obj) // panics
- panic("unreachable")
- }
-}
-
-func sameObj(a, b types.Object) bool {
- // Because unnamed types are not canonicalized, we cannot simply compare types for
- // (pointer) identity.
- // Ideally we'd check equality of constant values as well, but this is good enough.
- return objTag(a) == objTag(b) && types.Identical(a.Type(), b.Type())
-}
-
-func (p *importer) declare(obj types.Object) {
- pkg := obj.Pkg()
- if alt := pkg.Scope().Insert(obj); alt != nil {
- // This can only trigger if we import a (non-type) object a second time.
- // Excluding type aliases, this cannot happen because 1) we only import a package
- // once; and b) we ignore compiler-specific export data which may contain
- // functions whose inlined function bodies refer to other functions that
- // were already imported.
- // However, type aliases require reexporting the original type, so we need
- // to allow it (see also the comment in cmd/compile/internal/gc/bimport.go,
- // method importer.obj, switch case importing functions).
- // TODO(gri) review/update this comment once the gc compiler handles type aliases.
- if !sameObj(obj, alt) {
- errorf("inconsistent import:\n\t%v\npreviously imported as:\n\t%v\n", obj, alt)
- }
- }
-}
-
-func (p *importer) obj(tag int) {
- switch tag {
- case constTag:
- pos := p.pos()
- pkg, name := p.qualifiedName()
- typ := p.typ(nil, nil)
- val := p.value()
- p.declare(types.NewConst(pos, pkg, name, typ, val))
-
- case aliasTag:
- // TODO(gri) verify type alias hookup is correct
- pos := p.pos()
- pkg, name := p.qualifiedName()
- typ := p.typ(nil, nil)
- p.declare(types.NewTypeName(pos, pkg, name, typ))
-
- case typeTag:
- p.typ(nil, nil)
-
- case varTag:
- pos := p.pos()
- pkg, name := p.qualifiedName()
- typ := p.typ(nil, nil)
- p.declare(types.NewVar(pos, pkg, name, typ))
-
- case funcTag:
- pos := p.pos()
- pkg, name := p.qualifiedName()
- params, isddd := p.paramList()
- result, _ := p.paramList()
- sig := types.NewSignature(nil, params, result, isddd)
- p.declare(types.NewFunc(pos, pkg, name, sig))
-
- default:
- errorf("unexpected object tag %d", tag)
- }
-}
-
-const deltaNewFile = -64 // see cmd/compile/internal/gc/bexport.go
-
-func (p *importer) pos() token.Pos {
- if !p.posInfoFormat {
- return token.NoPos
- }
-
- file := p.prevFile
- line := p.prevLine
- delta := p.int()
- line += delta
- if p.version >= 5 {
- if delta == deltaNewFile {
- if n := p.int(); n >= 0 {
- // file changed
- file = p.path()
- line = n
- }
- }
- } else {
- if delta == 0 {
- if n := p.int(); n >= 0 {
- // file changed
- file = p.prevFile[:n] + p.string()
- line = p.int()
- }
- }
- }
- p.prevFile = file
- p.prevLine = line
-
- return p.fake.pos(file, line, 0)
-}
-
-// Synthesize a token.Pos
-type fakeFileSet struct {
- fset *token.FileSet
- files map[string]*fileInfo
-}
-
-type fileInfo struct {
- file *token.File
- lastline int
-}
-
-const maxlines = 64 * 1024
-
-func (s *fakeFileSet) pos(file string, line, column int) token.Pos {
- // TODO(mdempsky): Make use of column.
-
- // Since we don't know the set of needed file positions, we reserve maxlines
- // positions per file. We delay calling token.File.SetLines until all
- // positions have been calculated (by way of fakeFileSet.setLines), so that
- // we can avoid setting unnecessary lines. See also golang/go#46586.
- f := s.files[file]
- if f == nil {
- f = &fileInfo{file: s.fset.AddFile(file, -1, maxlines)}
- s.files[file] = f
- }
- if line > maxlines {
- line = 1
- }
- if line > f.lastline {
- f.lastline = line
- }
-
- // Return a fake position assuming that f.file consists only of newlines.
- return token.Pos(f.file.Base() + line - 1)
-}
-
-func (s *fakeFileSet) setLines() {
- fakeLinesOnce.Do(func() {
- fakeLines = make([]int, maxlines)
- for i := range fakeLines {
- fakeLines[i] = i
- }
- })
- for _, f := range s.files {
- f.file.SetLines(fakeLines[:f.lastline])
- }
-}
-
-var (
- fakeLines []int
- fakeLinesOnce sync.Once
-)
-
-func (p *importer) qualifiedName() (pkg *types.Package, name string) {
- name = p.string()
- pkg = p.pkg()
- return
-}
-
-func (p *importer) record(t types.Type) {
- p.typList = append(p.typList, t)
-}
-
-// A dddSlice is a types.Type representing ...T parameters.
-// It only appears for parameter types and does not escape
-// the importer.
-type dddSlice struct {
- elem types.Type
-}
-
-func (t *dddSlice) Underlying() types.Type { return t }
-func (t *dddSlice) String() string { return "..." + t.elem.String() }
-
-// parent is the package which declared the type; parent == nil means
-// the package currently imported. The parent package is needed for
-// exported struct fields and interface methods which don't contain
-// explicit package information in the export data.
-//
-// A non-nil tname is used as the "owner" of the result type; i.e.,
-// the result type is the underlying type of tname. tname is used
-// to give interface methods a named receiver type where possible.
-func (p *importer) typ(parent *types.Package, tname *types.Named) types.Type {
- // if the type was seen before, i is its index (>= 0)
- i := p.tagOrIndex()
- if i >= 0 {
- return p.typList[i]
- }
-
- // otherwise, i is the type tag (< 0)
- switch i {
- case namedTag:
- // read type object
- pos := p.pos()
- parent, name := p.qualifiedName()
- scope := parent.Scope()
- obj := scope.Lookup(name)
-
- // if the object doesn't exist yet, create and insert it
- if obj == nil {
- obj = types.NewTypeName(pos, parent, name, nil)
- scope.Insert(obj)
- }
-
- if _, ok := obj.(*types.TypeName); !ok {
- errorf("pkg = %s, name = %s => %s", parent, name, obj)
- }
-
- // associate new named type with obj if it doesn't exist yet
- t0 := types.NewNamed(obj.(*types.TypeName), nil, nil)
-
- // but record the existing type, if any
- tname := obj.Type().(*types.Named) // tname is either t0 or the existing type
- p.record(tname)
-
- // read underlying type
- t0.SetUnderlying(p.typ(parent, t0))
-
- // interfaces don't have associated methods
- if types.IsInterface(t0) {
- return tname
- }
-
- // read associated methods
- for i := p.int(); i > 0; i-- {
- // TODO(gri) replace this with something closer to fieldName
- pos := p.pos()
- name := p.string()
- if !exported(name) {
- p.pkg()
- }
-
- recv, _ := p.paramList() // TODO(gri) do we need a full param list for the receiver?
- params, isddd := p.paramList()
- result, _ := p.paramList()
- p.int() // go:nointerface pragma - discarded
-
- sig := types.NewSignature(recv.At(0), params, result, isddd)
- t0.AddMethod(types.NewFunc(pos, parent, name, sig))
- }
-
- return tname
-
- case arrayTag:
- t := new(types.Array)
- if p.trackAllTypes {
- p.record(t)
- }
-
- n := p.int64()
- *t = *types.NewArray(p.typ(parent, nil), n)
- return t
-
- case sliceTag:
- t := new(types.Slice)
- if p.trackAllTypes {
- p.record(t)
- }
-
- *t = *types.NewSlice(p.typ(parent, nil))
- return t
-
- case dddTag:
- t := new(dddSlice)
- if p.trackAllTypes {
- p.record(t)
- }
-
- t.elem = p.typ(parent, nil)
- return t
-
- case structTag:
- t := new(types.Struct)
- if p.trackAllTypes {
- p.record(t)
- }
-
- *t = *types.NewStruct(p.fieldList(parent))
- return t
-
- case pointerTag:
- t := new(types.Pointer)
- if p.trackAllTypes {
- p.record(t)
- }
-
- *t = *types.NewPointer(p.typ(parent, nil))
- return t
-
- case signatureTag:
- t := new(types.Signature)
- if p.trackAllTypes {
- p.record(t)
- }
-
- params, isddd := p.paramList()
- result, _ := p.paramList()
- *t = *types.NewSignature(nil, params, result, isddd)
- return t
-
- case interfaceTag:
- // Create a dummy entry in the type list. This is safe because we
- // cannot expect the interface type to appear in a cycle, as any
- // such cycle must contain a named type which would have been
- // first defined earlier.
- // TODO(gri) Is this still true now that we have type aliases?
- // See issue #23225.
- n := len(p.typList)
- if p.trackAllTypes {
- p.record(nil)
- }
-
- var embeddeds []types.Type
- for n := p.int(); n > 0; n-- {
- p.pos()
- embeddeds = append(embeddeds, p.typ(parent, nil))
- }
-
- t := newInterface(p.methodList(parent, tname), embeddeds)
- p.interfaceList = append(p.interfaceList, t)
- if p.trackAllTypes {
- p.typList[n] = t
- }
- return t
-
- case mapTag:
- t := new(types.Map)
- if p.trackAllTypes {
- p.record(t)
- }
-
- key := p.typ(parent, nil)
- val := p.typ(parent, nil)
- *t = *types.NewMap(key, val)
- return t
-
- case chanTag:
- t := new(types.Chan)
- if p.trackAllTypes {
- p.record(t)
- }
-
- dir := chanDir(p.int())
- val := p.typ(parent, nil)
- *t = *types.NewChan(dir, val)
- return t
-
- default:
- errorf("unexpected type tag %d", i) // panics
- panic("unreachable")
- }
-}
-
-func chanDir(d int) types.ChanDir {
- // tag values must match the constants in cmd/compile/internal/gc/go.go
- switch d {
- case 1 /* Crecv */ :
- return types.RecvOnly
- case 2 /* Csend */ :
- return types.SendOnly
- case 3 /* Cboth */ :
- return types.SendRecv
- default:
- errorf("unexpected channel dir %d", d)
- return 0
- }
-}
-
-func (p *importer) fieldList(parent *types.Package) (fields []*types.Var, tags []string) {
- if n := p.int(); n > 0 {
- fields = make([]*types.Var, n)
- tags = make([]string, n)
- for i := range fields {
- fields[i], tags[i] = p.field(parent)
- }
- }
- return
-}
-
-func (p *importer) field(parent *types.Package) (*types.Var, string) {
- pos := p.pos()
- pkg, name, alias := p.fieldName(parent)
- typ := p.typ(parent, nil)
- tag := p.string()
-
- anonymous := false
- if name == "" {
- // anonymous field - typ must be T or *T and T must be a type name
- switch typ := deref(typ).(type) {
- case *types.Basic: // basic types are named types
- pkg = nil // // objects defined in Universe scope have no package
- name = typ.Name()
- case *types.Named:
- name = typ.Obj().Name()
- default:
- errorf("named base type expected")
- }
- anonymous = true
- } else if alias {
- // anonymous field: we have an explicit name because it's an alias
- anonymous = true
- }
-
- return types.NewField(pos, pkg, name, typ, anonymous), tag
-}
-
-func (p *importer) methodList(parent *types.Package, baseType *types.Named) (methods []*types.Func) {
- if n := p.int(); n > 0 {
- methods = make([]*types.Func, n)
- for i := range methods {
- methods[i] = p.method(parent, baseType)
- }
- }
- return
-}
-
-func (p *importer) method(parent *types.Package, baseType *types.Named) *types.Func {
- pos := p.pos()
- pkg, name, _ := p.fieldName(parent)
- // If we don't have a baseType, use a nil receiver.
- // A receiver using the actual interface type (which
- // we don't know yet) will be filled in when we call
- // types.Interface.Complete.
- var recv *types.Var
- if baseType != nil {
- recv = types.NewVar(token.NoPos, parent, "", baseType)
- }
- params, isddd := p.paramList()
- result, _ := p.paramList()
- sig := types.NewSignature(recv, params, result, isddd)
- return types.NewFunc(pos, pkg, name, sig)
-}
-
-func (p *importer) fieldName(parent *types.Package) (pkg *types.Package, name string, alias bool) {
- name = p.string()
- pkg = parent
- if pkg == nil {
- // use the imported package instead
- pkg = p.pkgList[0]
- }
- if p.version == 0 && name == "_" {
- // version 0 didn't export a package for _ fields
- return
- }
- switch name {
- case "":
- // 1) field name matches base type name and is exported: nothing to do
- case "?":
- // 2) field name matches base type name and is not exported: need package
- name = ""
- pkg = p.pkg()
- case "@":
- // 3) field name doesn't match type name (alias)
- name = p.string()
- alias = true
- fallthrough
- default:
- if !exported(name) {
- pkg = p.pkg()
- }
- }
- return
-}
-
-func (p *importer) paramList() (*types.Tuple, bool) {
- n := p.int()
- if n == 0 {
- return nil, false
- }
- // negative length indicates unnamed parameters
- named := true
- if n < 0 {
- n = -n
- named = false
- }
- // n > 0
- params := make([]*types.Var, n)
- isddd := false
- for i := range params {
- params[i], isddd = p.param(named)
- }
- return types.NewTuple(params...), isddd
-}
-
-func (p *importer) param(named bool) (*types.Var, bool) {
- t := p.typ(nil, nil)
- td, isddd := t.(*dddSlice)
- if isddd {
- t = types.NewSlice(td.elem)
- }
-
- var pkg *types.Package
- var name string
- if named {
- name = p.string()
- if name == "" {
- errorf("expected named parameter")
- }
- if name != "_" {
- pkg = p.pkg()
- }
- if i := strings.Index(name, "·"); i > 0 {
- name = name[:i] // cut off gc-specific parameter numbering
- }
- }
-
- // read and discard compiler-specific info
- p.string()
-
- return types.NewVar(token.NoPos, pkg, name, t), isddd
-}
-
-func exported(name string) bool {
- ch, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(ch)
-}
-
-func (p *importer) value() constant.Value {
- switch tag := p.tagOrIndex(); tag {
- case falseTag:
- return constant.MakeBool(false)
- case trueTag:
- return constant.MakeBool(true)
- case int64Tag:
- return constant.MakeInt64(p.int64())
- case floatTag:
- return p.float()
- case complexTag:
- re := p.float()
- im := p.float()
- return constant.BinaryOp(re, token.ADD, constant.MakeImag(im))
- case stringTag:
- return constant.MakeString(p.string())
- case unknownTag:
- return constant.MakeUnknown()
- default:
- errorf("unexpected value tag %d", tag) // panics
- panic("unreachable")
- }
-}
-
-func (p *importer) float() constant.Value {
- sign := p.int()
- if sign == 0 {
- return constant.MakeInt64(0)
- }
-
- exp := p.int()
- mant := []byte(p.string()) // big endian
-
- // remove leading 0's if any
- for len(mant) > 0 && mant[0] == 0 {
- mant = mant[1:]
- }
-
- // convert to little endian
- // TODO(gri) go/constant should have a more direct conversion function
- // (e.g., once it supports a big.Float based implementation)
- for i, j := 0, len(mant)-1; i < j; i, j = i+1, j-1 {
- mant[i], mant[j] = mant[j], mant[i]
- }
-
- // adjust exponent (constant.MakeFromBytes creates an integer value,
- // but mant represents the mantissa bits such that 0.5 <= mant < 1.0)
- exp -= len(mant) << 3
- if len(mant) > 0 {
- for msd := mant[len(mant)-1]; msd&0x80 == 0; msd <<= 1 {
- exp++
- }
- }
-
- x := constant.MakeFromBytes(mant)
- switch {
- case exp < 0:
- d := constant.Shift(constant.MakeInt64(1), token.SHL, uint(-exp))
- x = constant.BinaryOp(x, token.QUO, d)
- case exp > 0:
- x = constant.Shift(x, token.SHL, uint(exp))
- }
-
- if sign < 0 {
- x = constant.UnaryOp(token.SUB, x, 0)
- }
- return x
-}
-
-// ----------------------------------------------------------------------------
-// Low-level decoders
-
-func (p *importer) tagOrIndex() int {
- if p.debugFormat {
- p.marker('t')
- }
-
- return int(p.rawInt64())
-}
-
-func (p *importer) int() int {
- x := p.int64()
- if int64(int(x)) != x {
- errorf("exported integer too large")
- }
- return int(x)
-}
-
-func (p *importer) int64() int64 {
- if p.debugFormat {
- p.marker('i')
- }
-
- return p.rawInt64()
-}
-
-func (p *importer) path() string {
- if p.debugFormat {
- p.marker('p')
- }
- // if the path was seen before, i is its index (>= 0)
- // (the empty string is at index 0)
- i := p.rawInt64()
- if i >= 0 {
- return p.pathList[i]
- }
- // otherwise, i is the negative path length (< 0)
- a := make([]string, -i)
- for n := range a {
- a[n] = p.string()
- }
- s := strings.Join(a, "/")
- p.pathList = append(p.pathList, s)
- return s
-}
-
-func (p *importer) string() string {
- if p.debugFormat {
- p.marker('s')
- }
- // if the string was seen before, i is its index (>= 0)
- // (the empty string is at index 0)
- i := p.rawInt64()
- if i >= 0 {
- return p.strList[i]
- }
- // otherwise, i is the negative string length (< 0)
- if n := int(-i); n <= cap(p.buf) {
- p.buf = p.buf[:n]
- } else {
- p.buf = make([]byte, n)
- }
- for i := range p.buf {
- p.buf[i] = p.rawByte()
- }
- s := string(p.buf)
- p.strList = append(p.strList, s)
- return s
-}
-
-func (p *importer) marker(want byte) {
- if got := p.rawByte(); got != want {
- errorf("incorrect marker: got %c; want %c (pos = %d)", got, want, p.read)
- }
-
- pos := p.read
- if n := int(p.rawInt64()); n != pos {
- errorf("incorrect position: got %d; want %d", n, pos)
- }
-}
-
-// rawInt64 should only be used by low-level decoders.
-func (p *importer) rawInt64() int64 {
- i, err := binary.ReadVarint(p)
- if err != nil {
- errorf("read error: %v", err)
- }
- return i
-}
-
-// rawStringln should only be used to read the initial version string.
-func (p *importer) rawStringln(b byte) string {
- p.buf = p.buf[:0]
- for b != '\n' {
- p.buf = append(p.buf, b)
- b = p.rawByte()
- }
- return string(p.buf)
-}
-
-// needed for binary.ReadVarint in rawInt64
-func (p *importer) ReadByte() (byte, error) {
- return p.rawByte(), nil
-}
-
-// byte is the bottleneck interface for reading p.data.
-// It unescapes '|' 'S' to '$' and '|' '|' to '|'.
-// rawByte should only be used by low-level decoders.
-func (p *importer) rawByte() byte {
- b := p.data[0]
- r := 1
- if b == '|' {
- b = p.data[1]
- r = 2
- switch b {
- case 'S':
- b = '$'
- case '|':
- // nothing to do
- default:
- errorf("unexpected escape sequence in export data")
- }
- }
- p.data = p.data[r:]
- p.read += r
- return b
-
-}
-
-// ----------------------------------------------------------------------------
-// Export format
-
-// Tags. Must be < 0.
-const (
- // Objects
- packageTag = -(iota + 1)
- constTag
- typeTag
- varTag
- funcTag
- endTag
-
- // Types
- namedTag
- arrayTag
- sliceTag
- dddTag
- structTag
- pointerTag
- signatureTag
- interfaceTag
- mapTag
- chanTag
-
- // Values
- falseTag
- trueTag
- int64Tag
- floatTag
- fractionTag // not used by gc
- complexTag
- stringTag
- nilTag // only used by gc (appears in exported inlined function bodies)
- unknownTag // not used by gc (only appears in packages with errors)
-
- // Type aliases
- aliasTag
-)
-
-var predeclOnce sync.Once
-var predecl []types.Type // initialized lazily
-
-func predeclared() []types.Type {
- predeclOnce.Do(func() {
- // initialize lazily to be sure that all
- // elements have been initialized before
- predecl = []types.Type{ // basic types
- types.Typ[types.Bool],
- types.Typ[types.Int],
- types.Typ[types.Int8],
- types.Typ[types.Int16],
- types.Typ[types.Int32],
- types.Typ[types.Int64],
- types.Typ[types.Uint],
- types.Typ[types.Uint8],
- types.Typ[types.Uint16],
- types.Typ[types.Uint32],
- types.Typ[types.Uint64],
- types.Typ[types.Uintptr],
- types.Typ[types.Float32],
- types.Typ[types.Float64],
- types.Typ[types.Complex64],
- types.Typ[types.Complex128],
- types.Typ[types.String],
-
- // basic type aliases
- types.Universe.Lookup("byte").Type(),
- types.Universe.Lookup("rune").Type(),
-
- // error
- types.Universe.Lookup("error").Type(),
-
- // untyped types
- types.Typ[types.UntypedBool],
- types.Typ[types.UntypedInt],
- types.Typ[types.UntypedRune],
- types.Typ[types.UntypedFloat],
- types.Typ[types.UntypedComplex],
- types.Typ[types.UntypedString],
- types.Typ[types.UntypedNil],
-
- // package unsafe
- types.Typ[types.UnsafePointer],
-
- // invalid type
- types.Typ[types.Invalid], // only appears in packages with errors
-
- // used internally by gc; never used by this package or in .a files
- anyType{},
- }
- predecl = append(predecl, additionalPredeclared()...)
- })
- return predecl
-}
-
-type anyType struct{}
-
-func (t anyType) Underlying() types.Type { return t }
-func (t anyType) String() string { return "any" }
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/exportdata.go b/vendor/golang.org/x/tools/go/internal/gcimporter/exportdata.go
deleted file mode 100644
index f6437feb..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/exportdata.go
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file is a copy of $GOROOT/src/go/internal/gcimporter/exportdata.go.
-
-// This file implements FindExportData.
-
-package gcimporter
-
-import (
- "bufio"
- "fmt"
- "io"
- "strconv"
- "strings"
-)
-
-func readGopackHeader(r *bufio.Reader) (name string, size int64, err error) {
- // See $GOROOT/include/ar.h.
- hdr := make([]byte, 16+12+6+6+8+10+2)
- _, err = io.ReadFull(r, hdr)
- if err != nil {
- return
- }
- // leave for debugging
- if false {
- fmt.Printf("header: %s", hdr)
- }
- s := strings.TrimSpace(string(hdr[16+12+6+6+8:][:10]))
- length, err := strconv.Atoi(s)
- size = int64(length)
- if err != nil || hdr[len(hdr)-2] != '`' || hdr[len(hdr)-1] != '\n' {
- err = fmt.Errorf("invalid archive header")
- return
- }
- name = strings.TrimSpace(string(hdr[:16]))
- return
-}
-
-// FindExportData positions the reader r at the beginning of the
-// export data section of an underlying GC-created object/archive
-// file by reading from it. The reader must be positioned at the
-// start of the file before calling this function. The hdr result
-// is the string before the export data, either "$$" or "$$B".
-// The size result is the length of the export data in bytes, or -1 if not known.
-func FindExportData(r *bufio.Reader) (hdr string, size int64, err error) {
- // Read first line to make sure this is an object file.
- line, err := r.ReadSlice('\n')
- if err != nil {
- err = fmt.Errorf("can't find export data (%v)", err)
- return
- }
-
- if string(line) == "!<arch>\n" {
- // Archive file. Scan to __.PKGDEF.
- var name string
- if name, size, err = readGopackHeader(r); err != nil {
- return
- }
-
- // First entry should be __.PKGDEF.
- if name != "__.PKGDEF" {
- err = fmt.Errorf("go archive is missing __.PKGDEF")
- return
- }
-
- // Read first line of __.PKGDEF data, so that line
- // is once again the first line of the input.
- if line, err = r.ReadSlice('\n'); err != nil {
- err = fmt.Errorf("can't find export data (%v)", err)
- return
- }
- size -= int64(len(line))
- }
-
- // Now at __.PKGDEF in archive or still at beginning of file.
- // Either way, line should begin with "go object ".
- if !strings.HasPrefix(string(line), "go object ") {
- err = fmt.Errorf("not a Go object file")
- return
- }
-
- // Skip over object header to export data.
- // Begins after first line starting with $$.
- for line[0] != '$' {
- if line, err = r.ReadSlice('\n'); err != nil {
- err = fmt.Errorf("can't find export data (%v)", err)
- return
- }
- size -= int64(len(line))
- }
- hdr = string(line)
- if size < 0 {
- size = -1
- }
-
- return
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/gcimporter.go b/vendor/golang.org/x/tools/go/internal/gcimporter/gcimporter.go
deleted file mode 100644
index e96c3960..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/gcimporter.go
+++ /dev/null
@@ -1,1125 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file is a modified copy of $GOROOT/src/go/internal/gcimporter/gcimporter.go,
-// but it also contains the original source-based importer code for Go1.6.
-// Once we stop supporting 1.6, we can remove that code.
-
-// Package gcimporter provides various functions for reading
-// gc-generated object files that can be used to implement the
-// Importer interface defined by the Go 1.5 standard library package.
-package gcimporter // import "golang.org/x/tools/go/internal/gcimporter"
-
-import (
- "bufio"
- "errors"
- "fmt"
- "go/build"
- "go/constant"
- "go/token"
- "go/types"
- "io"
- "io/ioutil"
- "os"
- "path/filepath"
- "sort"
- "strconv"
- "strings"
- "text/scanner"
-)
-
-const (
- // Enable debug during development: it adds some additional checks, and
- // prevents errors from being recovered.
- debug = false
-
- // If trace is set, debugging output is printed to std out.
- trace = false
-)
-
-var pkgExts = [...]string{".a", ".o"}
-
-// FindPkg returns the filename and unique package id for an import
-// path based on package information provided by build.Import (using
-// the build.Default build.Context). A relative srcDir is interpreted
-// relative to the current working directory.
-// If no file was found, an empty filename is returned.
-func FindPkg(path, srcDir string) (filename, id string) {
- if path == "" {
- return
- }
-
- var noext string
- switch {
- default:
- // "x" -> "$GOPATH/pkg/$GOOS_$GOARCH/x.ext", "x"
- // Don't require the source files to be present.
- if abs, err := filepath.Abs(srcDir); err == nil { // see issue 14282
- srcDir = abs
- }
- bp, _ := build.Import(path, srcDir, build.FindOnly|build.AllowBinary)
- if bp.PkgObj == "" {
- id = path // make sure we have an id to print in error message
- return
- }
- noext = strings.TrimSuffix(bp.PkgObj, ".a")
- id = bp.ImportPath
-
- case build.IsLocalImport(path):
- // "./x" -> "/this/directory/x.ext", "/this/directory/x"
- noext = filepath.Join(srcDir, path)
- id = noext
-
- case filepath.IsAbs(path):
- // for completeness only - go/build.Import
- // does not support absolute imports
- // "/x" -> "/x.ext", "/x"
- noext = path
- id = path
- }
-
- if false { // for debugging
- if path != id {
- fmt.Printf("%s -> %s\n", path, id)
- }
- }
-
- // try extensions
- for _, ext := range pkgExts {
- filename = noext + ext
- if f, err := os.Stat(filename); err == nil && !f.IsDir() {
- return
- }
- }
-
- filename = "" // not found
- return
-}
-
-// ImportData imports a package by reading the gc-generated export data,
-// adds the corresponding package object to the packages map indexed by id,
-// and returns the object.
-//
-// The packages map must contains all packages already imported. The data
-// reader position must be the beginning of the export data section. The
-// filename is only used in error messages.
-//
-// If packages[id] contains the completely imported package, that package
-// can be used directly, and there is no need to call this function (but
-// there is also no harm but for extra time used).
-func ImportData(packages map[string]*types.Package, filename, id string, data io.Reader) (pkg *types.Package, err error) {
- // support for parser error handling
- defer func() {
- switch r := recover().(type) {
- case nil:
- // nothing to do
- case importError:
- err = r
- default:
- panic(r) // internal error
- }
- }()
-
- var p parser
- p.init(filename, id, data, packages)
- pkg = p.parseExport()
-
- return
-}
-
-// Import imports a gc-generated package given its import path and srcDir, adds
-// the corresponding package object to the packages map, and returns the object.
-// The packages map must contain all packages already imported.
-func Import(packages map[string]*types.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types.Package, err error) {
- var rc io.ReadCloser
- var filename, id string
- if lookup != nil {
- // With custom lookup specified, assume that caller has
- // converted path to a canonical import path for use in the map.
- if path == "unsafe" {
- return types.Unsafe, nil
- }
- id = path
-
- // No need to re-import if the package was imported completely before.
- if pkg = packages[id]; pkg != nil && pkg.Complete() {
- return
- }
- f, err := lookup(path)
- if err != nil {
- return nil, err
- }
- rc = f
- } else {
- filename, id = FindPkg(path, srcDir)
- if filename == "" {
- if path == "unsafe" {
- return types.Unsafe, nil
- }
- return nil, fmt.Errorf("can't find import: %q", id)
- }
-
- // no need to re-import if the package was imported completely before
- if pkg = packages[id]; pkg != nil && pkg.Complete() {
- return
- }
-
- // open file
- f, err := os.Open(filename)
- if err != nil {
- return nil, err
- }
- defer func() {
- if err != nil {
- // add file name to error
- err = fmt.Errorf("%s: %v", filename, err)
- }
- }()
- rc = f
- }
- defer rc.Close()
-
- var hdr string
- var size int64
- buf := bufio.NewReader(rc)
- if hdr, size, err = FindExportData(buf); err != nil {
- return
- }
-
- switch hdr {
- case "$$\n":
- // Work-around if we don't have a filename; happens only if lookup != nil.
- // Either way, the filename is only needed for importer error messages, so
- // this is fine.
- if filename == "" {
- filename = path
- }
- return ImportData(packages, filename, id, buf)
-
- case "$$B\n":
- var data []byte
- data, err = ioutil.ReadAll(buf)
- if err != nil {
- break
- }
-
- // TODO(gri): allow clients of go/importer to provide a FileSet.
- // Or, define a new standard go/types/gcexportdata package.
- fset := token.NewFileSet()
-
- // The indexed export format starts with an 'i'; the older
- // binary export format starts with a 'c', 'd', or 'v'
- // (from "version"). Select appropriate importer.
- if len(data) > 0 {
- switch data[0] {
- case 'i':
- _, pkg, err := IImportData(fset, packages, data[1:], id)
- return pkg, err
-
- case 'v', 'c', 'd':
- _, pkg, err := BImportData(fset, packages, data, id)
- return pkg, err
-
- case 'u':
- _, pkg, err := UImportData(fset, packages, data[1:size], id)
- return pkg, err
-
- default:
- l := len(data)
- if l > 10 {
- l = 10
- }
- return nil, fmt.Errorf("unexpected export data with prefix %q for path %s", string(data[:l]), id)
- }
- }
-
- default:
- err = fmt.Errorf("unknown export data header: %q", hdr)
- }
-
- return
-}
-
-// ----------------------------------------------------------------------------
-// Parser
-
-// TODO(gri) Imported objects don't have position information.
-// Ideally use the debug table line info; alternatively
-// create some fake position (or the position of the
-// import). That way error messages referring to imported
-// objects can print meaningful information.
-
-// parser parses the exports inside a gc compiler-produced
-// object/archive file and populates its scope with the results.
-type parser struct {
- scanner scanner.Scanner
- tok rune // current token
- lit string // literal string; only valid for Ident, Int, String tokens
- id string // package id of imported package
- sharedPkgs map[string]*types.Package // package id -> package object (across importer)
- localPkgs map[string]*types.Package // package id -> package object (just this package)
-}
-
-func (p *parser) init(filename, id string, src io.Reader, packages map[string]*types.Package) {
- p.scanner.Init(src)
- p.scanner.Error = func(_ *scanner.Scanner, msg string) { p.error(msg) }
- p.scanner.Mode = scanner.ScanIdents | scanner.ScanInts | scanner.ScanChars | scanner.ScanStrings | scanner.ScanComments | scanner.SkipComments
- p.scanner.Whitespace = 1<<'\t' | 1<<' '
- p.scanner.Filename = filename // for good error messages
- p.next()
- p.id = id
- p.sharedPkgs = packages
- if debug {
- // check consistency of packages map
- for _, pkg := range packages {
- if pkg.Name() == "" {
- fmt.Printf("no package name for %s\n", pkg.Path())
- }
- }
- }
-}
-
-func (p *parser) next() {
- p.tok = p.scanner.Scan()
- switch p.tok {
- case scanner.Ident, scanner.Int, scanner.Char, scanner.String, '·':
- p.lit = p.scanner.TokenText()
- default:
- p.lit = ""
- }
- if debug {
- fmt.Printf("%s: %q -> %q\n", scanner.TokenString(p.tok), p.scanner.TokenText(), p.lit)
- }
-}
-
-func declTypeName(pkg *types.Package, name string) *types.TypeName {
- scope := pkg.Scope()
- if obj := scope.Lookup(name); obj != nil {
- return obj.(*types.TypeName)
- }
- obj := types.NewTypeName(token.NoPos, pkg, name, nil)
- // a named type may be referred to before the underlying type
- // is known - set it up
- types.NewNamed(obj, nil, nil)
- scope.Insert(obj)
- return obj
-}
-
-// ----------------------------------------------------------------------------
-// Error handling
-
-// Internal errors are boxed as importErrors.
-type importError struct {
- pos scanner.Position
- err error
-}
-
-func (e importError) Error() string {
- return fmt.Sprintf("import error %s (byte offset = %d): %s", e.pos, e.pos.Offset, e.err)
-}
-
-func (p *parser) error(err interface{}) {
- if s, ok := err.(string); ok {
- err = errors.New(s)
- }
- // panic with a runtime.Error if err is not an error
- panic(importError{p.scanner.Pos(), err.(error)})
-}
-
-func (p *parser) errorf(format string, args ...interface{}) {
- p.error(fmt.Sprintf(format, args...))
-}
-
-func (p *parser) expect(tok rune) string {
- lit := p.lit
- if p.tok != tok {
- p.errorf("expected %s, got %s (%s)", scanner.TokenString(tok), scanner.TokenString(p.tok), lit)
- }
- p.next()
- return lit
-}
-
-func (p *parser) expectSpecial(tok string) {
- sep := 'x' // not white space
- i := 0
- for i < len(tok) && p.tok == rune(tok[i]) && sep > ' ' {
- sep = p.scanner.Peek() // if sep <= ' ', there is white space before the next token
- p.next()
- i++
- }
- if i < len(tok) {
- p.errorf("expected %q, got %q", tok, tok[0:i])
- }
-}
-
-func (p *parser) expectKeyword(keyword string) {
- lit := p.expect(scanner.Ident)
- if lit != keyword {
- p.errorf("expected keyword %s, got %q", keyword, lit)
- }
-}
-
-// ----------------------------------------------------------------------------
-// Qualified and unqualified names
-
-// parsePackageID parses a PackageId:
-//
-// PackageId = string_lit .
-func (p *parser) parsePackageID() string {
- id, err := strconv.Unquote(p.expect(scanner.String))
- if err != nil {
- p.error(err)
- }
- // id == "" stands for the imported package id
- // (only known at time of package installation)
- if id == "" {
- id = p.id
- }
- return id
-}
-
-// parsePackageName parse a PackageName:
-//
-// PackageName = ident .
-func (p *parser) parsePackageName() string {
- return p.expect(scanner.Ident)
-}
-
-// parseDotIdent parses a dotIdentifier:
-//
-// dotIdentifier = ( ident | '·' ) { ident | int | '·' } .
-func (p *parser) parseDotIdent() string {
- ident := ""
- if p.tok != scanner.Int {
- sep := 'x' // not white space
- for (p.tok == scanner.Ident || p.tok == scanner.Int || p.tok == '·') && sep > ' ' {
- ident += p.lit
- sep = p.scanner.Peek() // if sep <= ' ', there is white space before the next token
- p.next()
- }
- }
- if ident == "" {
- p.expect(scanner.Ident) // use expect() for error handling
- }
- return ident
-}
-
-// parseQualifiedName parses a QualifiedName:
-//
-// QualifiedName = "@" PackageId "." ( "?" | dotIdentifier ) .
-func (p *parser) parseQualifiedName() (id, name string) {
- p.expect('@')
- id = p.parsePackageID()
- p.expect('.')
- // Per rev f280b8a485fd (10/2/2013), qualified names may be used for anonymous fields.
- if p.tok == '?' {
- p.next()
- } else {
- name = p.parseDotIdent()
- }
- return
-}
-
-// getPkg returns the package for a given id. If the package is
-// not found, create the package and add it to the p.localPkgs
-// and p.sharedPkgs maps. name is the (expected) name of the
-// package. If name == "", the package name is expected to be
-// set later via an import clause in the export data.
-//
-// id identifies a package, usually by a canonical package path like
-// "encoding/json" but possibly by a non-canonical import path like
-// "./json".
-func (p *parser) getPkg(id, name string) *types.Package {
- // package unsafe is not in the packages maps - handle explicitly
- if id == "unsafe" {
- return types.Unsafe
- }
-
- pkg := p.localPkgs[id]
- if pkg == nil {
- // first import of id from this package
- pkg = p.sharedPkgs[id]
- if pkg == nil {
- // first import of id by this importer;
- // add (possibly unnamed) pkg to shared packages
- pkg = types.NewPackage(id, name)
- p.sharedPkgs[id] = pkg
- }
- // add (possibly unnamed) pkg to local packages
- if p.localPkgs == nil {
- p.localPkgs = make(map[string]*types.Package)
- }
- p.localPkgs[id] = pkg
- } else if name != "" {
- // package exists already and we have an expected package name;
- // make sure names match or set package name if necessary
- if pname := pkg.Name(); pname == "" {
- pkg.SetName(name)
- } else if pname != name {
- p.errorf("%s package name mismatch: %s (given) vs %s (expected)", id, pname, name)
- }
- }
- return pkg
-}
-
-// parseExportedName is like parseQualifiedName, but
-// the package id is resolved to an imported *types.Package.
-func (p *parser) parseExportedName() (pkg *types.Package, name string) {
- id, name := p.parseQualifiedName()
- pkg = p.getPkg(id, "")
- return
-}
-
-// ----------------------------------------------------------------------------
-// Types
-
-// parseBasicType parses a BasicType:
-//
-// BasicType = identifier .
-func (p *parser) parseBasicType() types.Type {
- id := p.expect(scanner.Ident)
- obj := types.Universe.Lookup(id)
- if obj, ok := obj.(*types.TypeName); ok {
- return obj.Type()
- }
- p.errorf("not a basic type: %s", id)
- return nil
-}
-
-// parseArrayType parses an ArrayType:
-//
-// ArrayType = "[" int_lit "]" Type .
-func (p *parser) parseArrayType(parent *types.Package) types.Type {
- // "[" already consumed and lookahead known not to be "]"
- lit := p.expect(scanner.Int)
- p.expect(']')
- elem := p.parseType(parent)
- n, err := strconv.ParseInt(lit, 10, 64)
- if err != nil {
- p.error(err)
- }
- return types.NewArray(elem, n)
-}
-
-// parseMapType parses a MapType:
-//
-// MapType = "map" "[" Type "]" Type .
-func (p *parser) parseMapType(parent *types.Package) types.Type {
- p.expectKeyword("map")
- p.expect('[')
- key := p.parseType(parent)
- p.expect(']')
- elem := p.parseType(parent)
- return types.NewMap(key, elem)
-}
-
-// parseName parses a Name:
-//
-// Name = identifier | "?" | QualifiedName .
-//
-// For unqualified and anonymous names, the returned package is the parent
-// package unless parent == nil, in which case the returned package is the
-// package being imported. (The parent package is not nil if the name
-// is an unqualified struct field or interface method name belonging to a
-// type declared in another package.)
-//
-// For qualified names, the returned package is nil (and not created if
-// it doesn't exist yet) unless materializePkg is set (which creates an
-// unnamed package with valid package path). In the latter case, a
-// subsequent import clause is expected to provide a name for the package.
-func (p *parser) parseName(parent *types.Package, materializePkg bool) (pkg *types.Package, name string) {
- pkg = parent
- if pkg == nil {
- pkg = p.sharedPkgs[p.id]
- }
- switch p.tok {
- case scanner.Ident:
- name = p.lit
- p.next()
- case '?':
- // anonymous
- p.next()
- case '@':
- // exported name prefixed with package path
- pkg = nil
- var id string
- id, name = p.parseQualifiedName()
- if materializePkg {
- pkg = p.getPkg(id, "")
- }
- default:
- p.error("name expected")
- }
- return
-}
-
-func deref(typ types.Type) types.Type {
- if p, _ := typ.(*types.Pointer); p != nil {
- return p.Elem()
- }
- return typ
-}
-
-// parseField parses a Field:
-//
-// Field = Name Type [ string_lit ] .
-func (p *parser) parseField(parent *types.Package) (*types.Var, string) {
- pkg, name := p.parseName(parent, true)
-
- if name == "_" {
- // Blank fields should be package-qualified because they
- // are unexported identifiers, but gc does not qualify them.
- // Assuming that the ident belongs to the current package
- // causes types to change during re-exporting, leading
- // to spurious "can't assign A to B" errors from go/types.
- // As a workaround, pretend all blank fields belong
- // to the same unique dummy package.
- const blankpkg = "<_>"
- pkg = p.getPkg(blankpkg, blankpkg)
- }
-
- typ := p.parseType(parent)
- anonymous := false
- if name == "" {
- // anonymous field - typ must be T or *T and T must be a type name
- switch typ := deref(typ).(type) {
- case *types.Basic: // basic types are named types
- pkg = nil // objects defined in Universe scope have no package
- name = typ.Name()
- case *types.Named:
- name = typ.Obj().Name()
- default:
- p.errorf("anonymous field expected")
- }
- anonymous = true
- }
- tag := ""
- if p.tok == scanner.String {
- s := p.expect(scanner.String)
- var err error
- tag, err = strconv.Unquote(s)
- if err != nil {
- p.errorf("invalid struct tag %s: %s", s, err)
- }
- }
- return types.NewField(token.NoPos, pkg, name, typ, anonymous), tag
-}
-
-// parseStructType parses a StructType:
-//
-// StructType = "struct" "{" [ FieldList ] "}" .
-// FieldList = Field { ";" Field } .
-func (p *parser) parseStructType(parent *types.Package) types.Type {
- var fields []*types.Var
- var tags []string
-
- p.expectKeyword("struct")
- p.expect('{')
- for i := 0; p.tok != '}' && p.tok != scanner.EOF; i++ {
- if i > 0 {
- p.expect(';')
- }
- fld, tag := p.parseField(parent)
- if tag != "" && tags == nil {
- tags = make([]string, i)
- }
- if tags != nil {
- tags = append(tags, tag)
- }
- fields = append(fields, fld)
- }
- p.expect('}')
-
- return types.NewStruct(fields, tags)
-}
-
-// parseParameter parses a Parameter:
-//
-// Parameter = ( identifier | "?" ) [ "..." ] Type [ string_lit ] .
-func (p *parser) parseParameter() (par *types.Var, isVariadic bool) {
- _, name := p.parseName(nil, false)
- // remove gc-specific parameter numbering
- if i := strings.Index(name, "·"); i >= 0 {
- name = name[:i]
- }
- if p.tok == '.' {
- p.expectSpecial("...")
- isVariadic = true
- }
- typ := p.parseType(nil)
- if isVariadic {
- typ = types.NewSlice(typ)
- }
- // ignore argument tag (e.g. "noescape")
- if p.tok == scanner.String {
- p.next()
- }
- // TODO(gri) should we provide a package?
- par = types.NewVar(token.NoPos, nil, name, typ)
- return
-}
-
-// parseParameters parses a Parameters:
-//
-// Parameters = "(" [ ParameterList ] ")" .
-// ParameterList = { Parameter "," } Parameter .
-func (p *parser) parseParameters() (list []*types.Var, isVariadic bool) {
- p.expect('(')
- for p.tok != ')' && p.tok != scanner.EOF {
- if len(list) > 0 {
- p.expect(',')
- }
- par, variadic := p.parseParameter()
- list = append(list, par)
- if variadic {
- if isVariadic {
- p.error("... not on final argument")
- }
- isVariadic = true
- }
- }
- p.expect(')')
-
- return
-}
-
-// parseSignature parses a Signature:
-//
-// Signature = Parameters [ Result ] .
-// Result = Type | Parameters .
-func (p *parser) parseSignature(recv *types.Var) *types.Signature {
- params, isVariadic := p.parseParameters()
-
- // optional result type
- var results []*types.Var
- if p.tok == '(' {
- var variadic bool
- results, variadic = p.parseParameters()
- if variadic {
- p.error("... not permitted on result type")
- }
- }
-
- return types.NewSignature(recv, types.NewTuple(params...), types.NewTuple(results...), isVariadic)
-}
-
-// parseInterfaceType parses an InterfaceType:
-//
-// InterfaceType = "interface" "{" [ MethodList ] "}" .
-// MethodList = Method { ";" Method } .
-// Method = Name Signature .
-//
-// The methods of embedded interfaces are always "inlined"
-// by the compiler and thus embedded interfaces are never
-// visible in the export data.
-func (p *parser) parseInterfaceType(parent *types.Package) types.Type {
- var methods []*types.Func
-
- p.expectKeyword("interface")
- p.expect('{')
- for i := 0; p.tok != '}' && p.tok != scanner.EOF; i++ {
- if i > 0 {
- p.expect(';')
- }
- pkg, name := p.parseName(parent, true)
- sig := p.parseSignature(nil)
- methods = append(methods, types.NewFunc(token.NoPos, pkg, name, sig))
- }
- p.expect('}')
-
- // Complete requires the type's embedded interfaces to be fully defined,
- // but we do not define any
- return newInterface(methods, nil).Complete()
-}
-
-// parseChanType parses a ChanType:
-//
-// ChanType = ( "chan" [ "<-" ] | "<-" "chan" ) Type .
-func (p *parser) parseChanType(parent *types.Package) types.Type {
- dir := types.SendRecv
- if p.tok == scanner.Ident {
- p.expectKeyword("chan")
- if p.tok == '<' {
- p.expectSpecial("<-")
- dir = types.SendOnly
- }
- } else {
- p.expectSpecial("<-")
- p.expectKeyword("chan")
- dir = types.RecvOnly
- }
- elem := p.parseType(parent)
- return types.NewChan(dir, elem)
-}
-
-// parseType parses a Type:
-//
-// Type =
-// BasicType | TypeName | ArrayType | SliceType | StructType |
-// PointerType | FuncType | InterfaceType | MapType | ChanType |
-// "(" Type ")" .
-//
-// BasicType = ident .
-// TypeName = ExportedName .
-// SliceType = "[" "]" Type .
-// PointerType = "*" Type .
-// FuncType = "func" Signature .
-func (p *parser) parseType(parent *types.Package) types.Type {
- switch p.tok {
- case scanner.Ident:
- switch p.lit {
- default:
- return p.parseBasicType()
- case "struct":
- return p.parseStructType(parent)
- case "func":
- // FuncType
- p.next()
- return p.parseSignature(nil)
- case "interface":
- return p.parseInterfaceType(parent)
- case "map":
- return p.parseMapType(parent)
- case "chan":
- return p.parseChanType(parent)
- }
- case '@':
- // TypeName
- pkg, name := p.parseExportedName()
- return declTypeName(pkg, name).Type()
- case '[':
- p.next() // look ahead
- if p.tok == ']' {
- // SliceType
- p.next()
- return types.NewSlice(p.parseType(parent))
- }
- return p.parseArrayType(parent)
- case '*':
- // PointerType
- p.next()
- return types.NewPointer(p.parseType(parent))
- case '<':
- return p.parseChanType(parent)
- case '(':
- // "(" Type ")"
- p.next()
- typ := p.parseType(parent)
- p.expect(')')
- return typ
- }
- p.errorf("expected type, got %s (%q)", scanner.TokenString(p.tok), p.lit)
- return nil
-}
-
-// ----------------------------------------------------------------------------
-// Declarations
-
-// parseImportDecl parses an ImportDecl:
-//
-// ImportDecl = "import" PackageName PackageId .
-func (p *parser) parseImportDecl() {
- p.expectKeyword("import")
- name := p.parsePackageName()
- p.getPkg(p.parsePackageID(), name)
-}
-
-// parseInt parses an int_lit:
-//
-// int_lit = [ "+" | "-" ] { "0" ... "9" } .
-func (p *parser) parseInt() string {
- s := ""
- switch p.tok {
- case '-':
- s = "-"
- p.next()
- case '+':
- p.next()
- }
- return s + p.expect(scanner.Int)
-}
-
-// parseNumber parses a number:
-//
-// number = int_lit [ "p" int_lit ] .
-func (p *parser) parseNumber() (typ *types.Basic, val constant.Value) {
- // mantissa
- mant := constant.MakeFromLiteral(p.parseInt(), token.INT, 0)
- if mant == nil {
- panic("invalid mantissa")
- }
-
- if p.lit == "p" {
- // exponent (base 2)
- p.next()
- exp, err := strconv.ParseInt(p.parseInt(), 10, 0)
- if err != nil {
- p.error(err)
- }
- if exp < 0 {
- denom := constant.MakeInt64(1)
- denom = constant.Shift(denom, token.SHL, uint(-exp))
- typ = types.Typ[types.UntypedFloat]
- val = constant.BinaryOp(mant, token.QUO, denom)
- return
- }
- if exp > 0 {
- mant = constant.Shift(mant, token.SHL, uint(exp))
- }
- typ = types.Typ[types.UntypedFloat]
- val = mant
- return
- }
-
- typ = types.Typ[types.UntypedInt]
- val = mant
- return
-}
-
-// parseConstDecl parses a ConstDecl:
-//
-// ConstDecl = "const" ExportedName [ Type ] "=" Literal .
-// Literal = bool_lit | int_lit | float_lit | complex_lit | rune_lit | string_lit .
-// bool_lit = "true" | "false" .
-// complex_lit = "(" float_lit "+" float_lit "i" ")" .
-// rune_lit = "(" int_lit "+" int_lit ")" .
-// string_lit = `"` { unicode_char } `"` .
-func (p *parser) parseConstDecl() {
- p.expectKeyword("const")
- pkg, name := p.parseExportedName()
-
- var typ0 types.Type
- if p.tok != '=' {
- // constant types are never structured - no need for parent type
- typ0 = p.parseType(nil)
- }
-
- p.expect('=')
- var typ types.Type
- var val constant.Value
- switch p.tok {
- case scanner.Ident:
- // bool_lit
- if p.lit != "true" && p.lit != "false" {
- p.error("expected true or false")
- }
- typ = types.Typ[types.UntypedBool]
- val = constant.MakeBool(p.lit == "true")
- p.next()
-
- case '-', scanner.Int:
- // int_lit
- typ, val = p.parseNumber()
-
- case '(':
- // complex_lit or rune_lit
- p.next()
- if p.tok == scanner.Char {
- p.next()
- p.expect('+')
- typ = types.Typ[types.UntypedRune]
- _, val = p.parseNumber()
- p.expect(')')
- break
- }
- _, re := p.parseNumber()
- p.expect('+')
- _, im := p.parseNumber()
- p.expectKeyword("i")
- p.expect(')')
- typ = types.Typ[types.UntypedComplex]
- val = constant.BinaryOp(re, token.ADD, constant.MakeImag(im))
-
- case scanner.Char:
- // rune_lit
- typ = types.Typ[types.UntypedRune]
- val = constant.MakeFromLiteral(p.lit, token.CHAR, 0)
- p.next()
-
- case scanner.String:
- // string_lit
- typ = types.Typ[types.UntypedString]
- val = constant.MakeFromLiteral(p.lit, token.STRING, 0)
- p.next()
-
- default:
- p.errorf("expected literal got %s", scanner.TokenString(p.tok))
- }
-
- if typ0 == nil {
- typ0 = typ
- }
-
- pkg.Scope().Insert(types.NewConst(token.NoPos, pkg, name, typ0, val))
-}
-
-// parseTypeDecl parses a TypeDecl:
-//
-// TypeDecl = "type" ExportedName Type .
-func (p *parser) parseTypeDecl() {
- p.expectKeyword("type")
- pkg, name := p.parseExportedName()
- obj := declTypeName(pkg, name)
-
- // The type object may have been imported before and thus already
- // have a type associated with it. We still need to parse the type
- // structure, but throw it away if the object already has a type.
- // This ensures that all imports refer to the same type object for
- // a given type declaration.
- typ := p.parseType(pkg)
-
- if name := obj.Type().(*types.Named); name.Underlying() == nil {
- name.SetUnderlying(typ)
- }
-}
-
-// parseVarDecl parses a VarDecl:
-//
-// VarDecl = "var" ExportedName Type .
-func (p *parser) parseVarDecl() {
- p.expectKeyword("var")
- pkg, name := p.parseExportedName()
- typ := p.parseType(pkg)
- pkg.Scope().Insert(types.NewVar(token.NoPos, pkg, name, typ))
-}
-
-// parseFunc parses a Func:
-//
-// Func = Signature [ Body ] .
-// Body = "{" ... "}" .
-func (p *parser) parseFunc(recv *types.Var) *types.Signature {
- sig := p.parseSignature(recv)
- if p.tok == '{' {
- p.next()
- for i := 1; i > 0; p.next() {
- switch p.tok {
- case '{':
- i++
- case '}':
- i--
- }
- }
- }
- return sig
-}
-
-// parseMethodDecl parses a MethodDecl:
-//
-// MethodDecl = "func" Receiver Name Func .
-// Receiver = "(" ( identifier | "?" ) [ "*" ] ExportedName ")" .
-func (p *parser) parseMethodDecl() {
- // "func" already consumed
- p.expect('(')
- recv, _ := p.parseParameter() // receiver
- p.expect(')')
-
- // determine receiver base type object
- base := deref(recv.Type()).(*types.Named)
-
- // parse method name, signature, and possibly inlined body
- _, name := p.parseName(nil, false)
- sig := p.parseFunc(recv)
-
- // methods always belong to the same package as the base type object
- pkg := base.Obj().Pkg()
-
- // add method to type unless type was imported before
- // and method exists already
- // TODO(gri) This leads to a quadratic algorithm - ok for now because method counts are small.
- base.AddMethod(types.NewFunc(token.NoPos, pkg, name, sig))
-}
-
-// parseFuncDecl parses a FuncDecl:
-//
-// FuncDecl = "func" ExportedName Func .
-func (p *parser) parseFuncDecl() {
- // "func" already consumed
- pkg, name := p.parseExportedName()
- typ := p.parseFunc(nil)
- pkg.Scope().Insert(types.NewFunc(token.NoPos, pkg, name, typ))
-}
-
-// parseDecl parses a Decl:
-//
-// Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" .
-func (p *parser) parseDecl() {
- if p.tok == scanner.Ident {
- switch p.lit {
- case "import":
- p.parseImportDecl()
- case "const":
- p.parseConstDecl()
- case "type":
- p.parseTypeDecl()
- case "var":
- p.parseVarDecl()
- case "func":
- p.next() // look ahead
- if p.tok == '(' {
- p.parseMethodDecl()
- } else {
- p.parseFuncDecl()
- }
- }
- }
- p.expect('\n')
-}
-
-// ----------------------------------------------------------------------------
-// Export
-
-// parseExport parses an Export:
-//
-// Export = "PackageClause { Decl } "$$" .
-// PackageClause = "package" PackageName [ "safe" ] "\n" .
-func (p *parser) parseExport() *types.Package {
- p.expectKeyword("package")
- name := p.parsePackageName()
- if p.tok == scanner.Ident && p.lit == "safe" {
- // package was compiled with -u option - ignore
- p.next()
- }
- p.expect('\n')
-
- pkg := p.getPkg(p.id, name)
-
- for p.tok != '$' && p.tok != scanner.EOF {
- p.parseDecl()
- }
-
- if ch := p.scanner.Peek(); p.tok != '$' || ch != '$' {
- // don't call next()/expect() since reading past the
- // export data may cause scanner errors (e.g. NUL chars)
- p.errorf("expected '$$', got %s %c", scanner.TokenString(p.tok), ch)
- }
-
- if n := p.scanner.ErrorCount; n != 0 {
- p.errorf("expected no scanner errors, got %d", n)
- }
-
- // Record all locally referenced packages as imports.
- var imports []*types.Package
- for id, pkg2 := range p.localPkgs {
- if pkg2.Name() == "" {
- p.errorf("%s package has no name", id)
- }
- if id == p.id {
- continue // avoid self-edge
- }
- imports = append(imports, pkg2)
- }
- sort.Sort(byPath(imports))
- pkg.SetImports(imports)
-
- // package was imported completely and without errors
- pkg.MarkComplete()
-
- return pkg
-}
-
-type byPath []*types.Package
-
-func (a byPath) Len() int { return len(a) }
-func (a byPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a byPath) Less(i, j int) bool { return a[i].Path() < a[j].Path() }
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go b/vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go
deleted file mode 100644
index 9a4ff329..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go
+++ /dev/null
@@ -1,1010 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Indexed binary package export.
-// This file was derived from $GOROOT/src/cmd/compile/internal/gc/iexport.go;
-// see that file for specification of the format.
-
-package gcimporter
-
-import (
- "bytes"
- "encoding/binary"
- "fmt"
- "go/ast"
- "go/constant"
- "go/token"
- "go/types"
- "io"
- "math/big"
- "reflect"
- "sort"
- "strconv"
- "strings"
-
- "golang.org/x/tools/internal/typeparams"
-)
-
-// Current bundled export format version. Increase with each format change.
-// 0: initial implementation
-const bundleVersion = 0
-
-// IExportData writes indexed export data for pkg to out.
-//
-// If no file set is provided, position info will be missing.
-// The package path of the top-level package will not be recorded,
-// so that calls to IImportData can override with a provided package path.
-func IExportData(out io.Writer, fset *token.FileSet, pkg *types.Package) error {
- return iexportCommon(out, fset, false, iexportVersion, []*types.Package{pkg})
-}
-
-// IExportBundle writes an indexed export bundle for pkgs to out.
-func IExportBundle(out io.Writer, fset *token.FileSet, pkgs []*types.Package) error {
- return iexportCommon(out, fset, true, iexportVersion, pkgs)
-}
-
-func iexportCommon(out io.Writer, fset *token.FileSet, bundle bool, version int, pkgs []*types.Package) (err error) {
- if !debug {
- defer func() {
- if e := recover(); e != nil {
- if ierr, ok := e.(internalError); ok {
- err = ierr
- return
- }
- // Not an internal error; panic again.
- panic(e)
- }
- }()
- }
-
- p := iexporter{
- fset: fset,
- version: version,
- allPkgs: map[*types.Package]bool{},
- stringIndex: map[string]uint64{},
- declIndex: map[types.Object]uint64{},
- tparamNames: map[types.Object]string{},
- typIndex: map[types.Type]uint64{},
- }
- if !bundle {
- p.localpkg = pkgs[0]
- }
-
- for i, pt := range predeclared() {
- p.typIndex[pt] = uint64(i)
- }
- if len(p.typIndex) > predeclReserved {
- panic(internalErrorf("too many predeclared types: %d > %d", len(p.typIndex), predeclReserved))
- }
-
- // Initialize work queue with exported declarations.
- for _, pkg := range pkgs {
- scope := pkg.Scope()
- for _, name := range scope.Names() {
- if ast.IsExported(name) {
- p.pushDecl(scope.Lookup(name))
- }
- }
-
- if bundle {
- // Ensure pkg and its imports are included in the index.
- p.allPkgs[pkg] = true
- for _, imp := range pkg.Imports() {
- p.allPkgs[imp] = true
- }
- }
- }
-
- // Loop until no more work.
- for !p.declTodo.empty() {
- p.doDecl(p.declTodo.popHead())
- }
-
- // Append indices to data0 section.
- dataLen := uint64(p.data0.Len())
- w := p.newWriter()
- w.writeIndex(p.declIndex)
-
- if bundle {
- w.uint64(uint64(len(pkgs)))
- for _, pkg := range pkgs {
- w.pkg(pkg)
- imps := pkg.Imports()
- w.uint64(uint64(len(imps)))
- for _, imp := range imps {
- w.pkg(imp)
- }
- }
- }
- w.flush()
-
- // Assemble header.
- var hdr intWriter
- if bundle {
- hdr.uint64(bundleVersion)
- }
- hdr.uint64(uint64(p.version))
- hdr.uint64(uint64(p.strings.Len()))
- hdr.uint64(dataLen)
-
- // Flush output.
- io.Copy(out, &hdr)
- io.Copy(out, &p.strings)
- io.Copy(out, &p.data0)
-
- return nil
-}
-
-// writeIndex writes out an object index. mainIndex indicates whether
-// we're writing out the main index, which is also read by
-// non-compiler tools and includes a complete package description
-// (i.e., name and height).
-func (w *exportWriter) writeIndex(index map[types.Object]uint64) {
- type pkgObj struct {
- obj types.Object
- name string // qualified name; differs from obj.Name for type params
- }
- // Build a map from packages to objects from that package.
- pkgObjs := map[*types.Package][]pkgObj{}
-
- // For the main index, make sure to include every package that
- // we reference, even if we're not exporting (or reexporting)
- // any symbols from it.
- if w.p.localpkg != nil {
- pkgObjs[w.p.localpkg] = nil
- }
- for pkg := range w.p.allPkgs {
- pkgObjs[pkg] = nil
- }
-
- for obj := range index {
- name := w.p.exportName(obj)
- pkgObjs[obj.Pkg()] = append(pkgObjs[obj.Pkg()], pkgObj{obj, name})
- }
-
- var pkgs []*types.Package
- for pkg, objs := range pkgObjs {
- pkgs = append(pkgs, pkg)
-
- sort.Slice(objs, func(i, j int) bool {
- return objs[i].name < objs[j].name
- })
- }
-
- sort.Slice(pkgs, func(i, j int) bool {
- return w.exportPath(pkgs[i]) < w.exportPath(pkgs[j])
- })
-
- w.uint64(uint64(len(pkgs)))
- for _, pkg := range pkgs {
- w.string(w.exportPath(pkg))
- w.string(pkg.Name())
- w.uint64(uint64(0)) // package height is not needed for go/types
-
- objs := pkgObjs[pkg]
- w.uint64(uint64(len(objs)))
- for _, obj := range objs {
- w.string(obj.name)
- w.uint64(index[obj.obj])
- }
- }
-}
-
-// exportName returns the 'exported' name of an object. It differs from
-// obj.Name() only for type parameters (see tparamExportName for details).
-func (p *iexporter) exportName(obj types.Object) (res string) {
- if name := p.tparamNames[obj]; name != "" {
- return name
- }
- return obj.Name()
-}
-
-type iexporter struct {
- fset *token.FileSet
- out *bytes.Buffer
- version int
-
- localpkg *types.Package
-
- // allPkgs tracks all packages that have been referenced by
- // the export data, so we can ensure to include them in the
- // main index.
- allPkgs map[*types.Package]bool
-
- declTodo objQueue
-
- strings intWriter
- stringIndex map[string]uint64
-
- data0 intWriter
- declIndex map[types.Object]uint64
- tparamNames map[types.Object]string // typeparam->exported name
- typIndex map[types.Type]uint64
-
- indent int // for tracing support
-}
-
-func (p *iexporter) trace(format string, args ...interface{}) {
- if !trace {
- // Call sites should also be guarded, but having this check here allows
- // easily enabling/disabling debug trace statements.
- return
- }
- fmt.Printf(strings.Repeat("..", p.indent)+format+"\n", args...)
-}
-
-// stringOff returns the offset of s within the string section.
-// If not already present, it's added to the end.
-func (p *iexporter) stringOff(s string) uint64 {
- off, ok := p.stringIndex[s]
- if !ok {
- off = uint64(p.strings.Len())
- p.stringIndex[s] = off
-
- p.strings.uint64(uint64(len(s)))
- p.strings.WriteString(s)
- }
- return off
-}
-
-// pushDecl adds n to the declaration work queue, if not already present.
-func (p *iexporter) pushDecl(obj types.Object) {
- // Package unsafe is known to the compiler and predeclared.
- // Caller should not ask us to do export it.
- if obj.Pkg() == types.Unsafe {
- panic("cannot export package unsafe")
- }
-
- if _, ok := p.declIndex[obj]; ok {
- return
- }
-
- p.declIndex[obj] = ^uint64(0) // mark obj present in work queue
- p.declTodo.pushTail(obj)
-}
-
-// exportWriter handles writing out individual data section chunks.
-type exportWriter struct {
- p *iexporter
-
- data intWriter
- currPkg *types.Package
- prevFile string
- prevLine int64
- prevColumn int64
-}
-
-func (w *exportWriter) exportPath(pkg *types.Package) string {
- if pkg == w.p.localpkg {
- return ""
- }
- return pkg.Path()
-}
-
-func (p *iexporter) doDecl(obj types.Object) {
- if trace {
- p.trace("exporting decl %v (%T)", obj, obj)
- p.indent++
- defer func() {
- p.indent--
- p.trace("=> %s", obj)
- }()
- }
- w := p.newWriter()
- w.setPkg(obj.Pkg(), false)
-
- switch obj := obj.(type) {
- case *types.Var:
- w.tag('V')
- w.pos(obj.Pos())
- w.typ(obj.Type(), obj.Pkg())
-
- case *types.Func:
- sig, _ := obj.Type().(*types.Signature)
- if sig.Recv() != nil {
- panic(internalErrorf("unexpected method: %v", sig))
- }
-
- // Function.
- if typeparams.ForSignature(sig).Len() == 0 {
- w.tag('F')
- } else {
- w.tag('G')
- }
- w.pos(obj.Pos())
- // The tparam list of the function type is the declaration of the type
- // params. So, write out the type params right now. Then those type params
- // will be referenced via their type offset (via typOff) in all other
- // places in the signature and function where they are used.
- //
- // While importing the type parameters, tparamList computes and records
- // their export name, so that it can be later used when writing the index.
- if tparams := typeparams.ForSignature(sig); tparams.Len() > 0 {
- w.tparamList(obj.Name(), tparams, obj.Pkg())
- }
- w.signature(sig)
-
- case *types.Const:
- w.tag('C')
- w.pos(obj.Pos())
- w.value(obj.Type(), obj.Val())
-
- case *types.TypeName:
- t := obj.Type()
-
- if tparam, ok := t.(*typeparams.TypeParam); ok {
- w.tag('P')
- w.pos(obj.Pos())
- constraint := tparam.Constraint()
- if p.version >= iexportVersionGo1_18 {
- implicit := false
- if iface, _ := constraint.(*types.Interface); iface != nil {
- implicit = typeparams.IsImplicit(iface)
- }
- w.bool(implicit)
- }
- w.typ(constraint, obj.Pkg())
- break
- }
-
- if obj.IsAlias() {
- w.tag('A')
- w.pos(obj.Pos())
- w.typ(t, obj.Pkg())
- break
- }
-
- // Defined type.
- named, ok := t.(*types.Named)
- if !ok {
- panic(internalErrorf("%s is not a defined type", t))
- }
-
- if typeparams.ForNamed(named).Len() == 0 {
- w.tag('T')
- } else {
- w.tag('U')
- }
- w.pos(obj.Pos())
-
- if typeparams.ForNamed(named).Len() > 0 {
- // While importing the type parameters, tparamList computes and records
- // their export name, so that it can be later used when writing the index.
- w.tparamList(obj.Name(), typeparams.ForNamed(named), obj.Pkg())
- }
-
- underlying := obj.Type().Underlying()
- w.typ(underlying, obj.Pkg())
-
- if types.IsInterface(t) {
- break
- }
-
- n := named.NumMethods()
- w.uint64(uint64(n))
- for i := 0; i < n; i++ {
- m := named.Method(i)
- w.pos(m.Pos())
- w.string(m.Name())
- sig, _ := m.Type().(*types.Signature)
-
- // Receiver type parameters are type arguments of the receiver type, so
- // their name must be qualified before exporting recv.
- if rparams := typeparams.RecvTypeParams(sig); rparams.Len() > 0 {
- prefix := obj.Name() + "." + m.Name()
- for i := 0; i < rparams.Len(); i++ {
- rparam := rparams.At(i)
- name := tparamExportName(prefix, rparam)
- w.p.tparamNames[rparam.Obj()] = name
- }
- }
- w.param(sig.Recv())
- w.signature(sig)
- }
-
- default:
- panic(internalErrorf("unexpected object: %v", obj))
- }
-
- p.declIndex[obj] = w.flush()
-}
-
-func (w *exportWriter) tag(tag byte) {
- w.data.WriteByte(tag)
-}
-
-func (w *exportWriter) pos(pos token.Pos) {
- if w.p.version >= iexportVersionPosCol {
- w.posV1(pos)
- } else {
- w.posV0(pos)
- }
-}
-
-func (w *exportWriter) posV1(pos token.Pos) {
- if w.p.fset == nil {
- w.int64(0)
- return
- }
-
- p := w.p.fset.Position(pos)
- file := p.Filename
- line := int64(p.Line)
- column := int64(p.Column)
-
- deltaColumn := (column - w.prevColumn) << 1
- deltaLine := (line - w.prevLine) << 1
-
- if file != w.prevFile {
- deltaLine |= 1
- }
- if deltaLine != 0 {
- deltaColumn |= 1
- }
-
- w.int64(deltaColumn)
- if deltaColumn&1 != 0 {
- w.int64(deltaLine)
- if deltaLine&1 != 0 {
- w.string(file)
- }
- }
-
- w.prevFile = file
- w.prevLine = line
- w.prevColumn = column
-}
-
-func (w *exportWriter) posV0(pos token.Pos) {
- if w.p.fset == nil {
- w.int64(0)
- return
- }
-
- p := w.p.fset.Position(pos)
- file := p.Filename
- line := int64(p.Line)
-
- // When file is the same as the last position (common case),
- // we can save a few bytes by delta encoding just the line
- // number.
- //
- // Note: Because data objects may be read out of order (or not
- // at all), we can only apply delta encoding within a single
- // object. This is handled implicitly by tracking prevFile and
- // prevLine as fields of exportWriter.
-
- if file == w.prevFile {
- delta := line - w.prevLine
- w.int64(delta)
- if delta == deltaNewFile {
- w.int64(-1)
- }
- } else {
- w.int64(deltaNewFile)
- w.int64(line) // line >= 0
- w.string(file)
- w.prevFile = file
- }
- w.prevLine = line
-}
-
-func (w *exportWriter) pkg(pkg *types.Package) {
- // Ensure any referenced packages are declared in the main index.
- w.p.allPkgs[pkg] = true
-
- w.string(w.exportPath(pkg))
-}
-
-func (w *exportWriter) qualifiedIdent(obj types.Object) {
- name := w.p.exportName(obj)
-
- // Ensure any referenced declarations are written out too.
- w.p.pushDecl(obj)
- w.string(name)
- w.pkg(obj.Pkg())
-}
-
-func (w *exportWriter) typ(t types.Type, pkg *types.Package) {
- w.data.uint64(w.p.typOff(t, pkg))
-}
-
-func (p *iexporter) newWriter() *exportWriter {
- return &exportWriter{p: p}
-}
-
-func (w *exportWriter) flush() uint64 {
- off := uint64(w.p.data0.Len())
- io.Copy(&w.p.data0, &w.data)
- return off
-}
-
-func (p *iexporter) typOff(t types.Type, pkg *types.Package) uint64 {
- off, ok := p.typIndex[t]
- if !ok {
- w := p.newWriter()
- w.doTyp(t, pkg)
- off = predeclReserved + w.flush()
- p.typIndex[t] = off
- }
- return off
-}
-
-func (w *exportWriter) startType(k itag) {
- w.data.uint64(uint64(k))
-}
-
-func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) {
- if trace {
- w.p.trace("exporting type %s (%T)", t, t)
- w.p.indent++
- defer func() {
- w.p.indent--
- w.p.trace("=> %s", t)
- }()
- }
- switch t := t.(type) {
- case *types.Named:
- if targs := typeparams.NamedTypeArgs(t); targs.Len() > 0 {
- w.startType(instanceType)
- // TODO(rfindley): investigate if this position is correct, and if it
- // matters.
- w.pos(t.Obj().Pos())
- w.typeList(targs, pkg)
- w.typ(typeparams.NamedTypeOrigin(t), pkg)
- return
- }
- w.startType(definedType)
- w.qualifiedIdent(t.Obj())
-
- case *typeparams.TypeParam:
- w.startType(typeParamType)
- w.qualifiedIdent(t.Obj())
-
- case *types.Pointer:
- w.startType(pointerType)
- w.typ(t.Elem(), pkg)
-
- case *types.Slice:
- w.startType(sliceType)
- w.typ(t.Elem(), pkg)
-
- case *types.Array:
- w.startType(arrayType)
- w.uint64(uint64(t.Len()))
- w.typ(t.Elem(), pkg)
-
- case *types.Chan:
- w.startType(chanType)
- // 1 RecvOnly; 2 SendOnly; 3 SendRecv
- var dir uint64
- switch t.Dir() {
- case types.RecvOnly:
- dir = 1
- case types.SendOnly:
- dir = 2
- case types.SendRecv:
- dir = 3
- }
- w.uint64(dir)
- w.typ(t.Elem(), pkg)
-
- case *types.Map:
- w.startType(mapType)
- w.typ(t.Key(), pkg)
- w.typ(t.Elem(), pkg)
-
- case *types.Signature:
- w.startType(signatureType)
- w.setPkg(pkg, true)
- w.signature(t)
-
- case *types.Struct:
- w.startType(structType)
- w.setPkg(pkg, true)
-
- n := t.NumFields()
- w.uint64(uint64(n))
- for i := 0; i < n; i++ {
- f := t.Field(i)
- w.pos(f.Pos())
- w.string(f.Name())
- w.typ(f.Type(), pkg)
- w.bool(f.Anonymous())
- w.string(t.Tag(i)) // note (or tag)
- }
-
- case *types.Interface:
- w.startType(interfaceType)
- w.setPkg(pkg, true)
-
- n := t.NumEmbeddeds()
- w.uint64(uint64(n))
- for i := 0; i < n; i++ {
- ft := t.EmbeddedType(i)
- tPkg := pkg
- if named, _ := ft.(*types.Named); named != nil {
- w.pos(named.Obj().Pos())
- } else {
- w.pos(token.NoPos)
- }
- w.typ(ft, tPkg)
- }
-
- n = t.NumExplicitMethods()
- w.uint64(uint64(n))
- for i := 0; i < n; i++ {
- m := t.ExplicitMethod(i)
- w.pos(m.Pos())
- w.string(m.Name())
- sig, _ := m.Type().(*types.Signature)
- w.signature(sig)
- }
-
- case *typeparams.Union:
- w.startType(unionType)
- nt := t.Len()
- w.uint64(uint64(nt))
- for i := 0; i < nt; i++ {
- term := t.Term(i)
- w.bool(term.Tilde())
- w.typ(term.Type(), pkg)
- }
-
- default:
- panic(internalErrorf("unexpected type: %v, %v", t, reflect.TypeOf(t)))
- }
-}
-
-func (w *exportWriter) setPkg(pkg *types.Package, write bool) {
- if write {
- w.pkg(pkg)
- }
-
- w.currPkg = pkg
-}
-
-func (w *exportWriter) signature(sig *types.Signature) {
- w.paramList(sig.Params())
- w.paramList(sig.Results())
- if sig.Params().Len() > 0 {
- w.bool(sig.Variadic())
- }
-}
-
-func (w *exportWriter) typeList(ts *typeparams.TypeList, pkg *types.Package) {
- w.uint64(uint64(ts.Len()))
- for i := 0; i < ts.Len(); i++ {
- w.typ(ts.At(i), pkg)
- }
-}
-
-func (w *exportWriter) tparamList(prefix string, list *typeparams.TypeParamList, pkg *types.Package) {
- ll := uint64(list.Len())
- w.uint64(ll)
- for i := 0; i < list.Len(); i++ {
- tparam := list.At(i)
- // Set the type parameter exportName before exporting its type.
- exportName := tparamExportName(prefix, tparam)
- w.p.tparamNames[tparam.Obj()] = exportName
- w.typ(list.At(i), pkg)
- }
-}
-
-const blankMarker = "$"
-
-// tparamExportName returns the 'exported' name of a type parameter, which
-// differs from its actual object name: it is prefixed with a qualifier, and
-// blank type parameter names are disambiguated by their index in the type
-// parameter list.
-func tparamExportName(prefix string, tparam *typeparams.TypeParam) string {
- assert(prefix != "")
- name := tparam.Obj().Name()
- if name == "_" {
- name = blankMarker + strconv.Itoa(tparam.Index())
- }
- return prefix + "." + name
-}
-
-// tparamName returns the real name of a type parameter, after stripping its
-// qualifying prefix and reverting blank-name encoding. See tparamExportName
-// for details.
-func tparamName(exportName string) string {
- // Remove the "path" from the type param name that makes it unique.
- ix := strings.LastIndex(exportName, ".")
- if ix < 0 {
- errorf("malformed type parameter export name %s: missing prefix", exportName)
- }
- name := exportName[ix+1:]
- if strings.HasPrefix(name, blankMarker) {
- return "_"
- }
- return name
-}
-
-func (w *exportWriter) paramList(tup *types.Tuple) {
- n := tup.Len()
- w.uint64(uint64(n))
- for i := 0; i < n; i++ {
- w.param(tup.At(i))
- }
-}
-
-func (w *exportWriter) param(obj types.Object) {
- w.pos(obj.Pos())
- w.localIdent(obj)
- w.typ(obj.Type(), obj.Pkg())
-}
-
-func (w *exportWriter) value(typ types.Type, v constant.Value) {
- w.typ(typ, nil)
- if w.p.version >= iexportVersionGo1_18 {
- w.int64(int64(v.Kind()))
- }
-
- switch b := typ.Underlying().(*types.Basic); b.Info() & types.IsConstType {
- case types.IsBoolean:
- w.bool(constant.BoolVal(v))
- case types.IsInteger:
- var i big.Int
- if i64, exact := constant.Int64Val(v); exact {
- i.SetInt64(i64)
- } else if ui64, exact := constant.Uint64Val(v); exact {
- i.SetUint64(ui64)
- } else {
- i.SetString(v.ExactString(), 10)
- }
- w.mpint(&i, typ)
- case types.IsFloat:
- f := constantToFloat(v)
- w.mpfloat(f, typ)
- case types.IsComplex:
- w.mpfloat(constantToFloat(constant.Real(v)), typ)
- w.mpfloat(constantToFloat(constant.Imag(v)), typ)
- case types.IsString:
- w.string(constant.StringVal(v))
- default:
- if b.Kind() == types.Invalid {
- // package contains type errors
- break
- }
- panic(internalErrorf("unexpected type %v (%v)", typ, typ.Underlying()))
- }
-}
-
-// constantToFloat converts a constant.Value with kind constant.Float to a
-// big.Float.
-func constantToFloat(x constant.Value) *big.Float {
- x = constant.ToFloat(x)
- // Use the same floating-point precision (512) as cmd/compile
- // (see Mpprec in cmd/compile/internal/gc/mpfloat.go).
- const mpprec = 512
- var f big.Float
- f.SetPrec(mpprec)
- if v, exact := constant.Float64Val(x); exact {
- // float64
- f.SetFloat64(v)
- } else if num, denom := constant.Num(x), constant.Denom(x); num.Kind() == constant.Int {
- // TODO(gri): add big.Rat accessor to constant.Value.
- n := valueToRat(num)
- d := valueToRat(denom)
- f.SetRat(n.Quo(n, d))
- } else {
- // Value too large to represent as a fraction => inaccessible.
- // TODO(gri): add big.Float accessor to constant.Value.
- _, ok := f.SetString(x.ExactString())
- assert(ok)
- }
- return &f
-}
-
-// mpint exports a multi-precision integer.
-//
-// For unsigned types, small values are written out as a single
-// byte. Larger values are written out as a length-prefixed big-endian
-// byte string, where the length prefix is encoded as its complement.
-// For example, bytes 0, 1, and 2 directly represent the integer
-// values 0, 1, and 2; while bytes 255, 254, and 253 indicate a 1-,
-// 2-, and 3-byte big-endian string follow.
-//
-// Encoding for signed types use the same general approach as for
-// unsigned types, except small values use zig-zag encoding and the
-// bottom bit of length prefix byte for large values is reserved as a
-// sign bit.
-//
-// The exact boundary between small and large encodings varies
-// according to the maximum number of bytes needed to encode a value
-// of type typ. As a special case, 8-bit types are always encoded as a
-// single byte.
-//
-// TODO(mdempsky): Is this level of complexity really worthwhile?
-func (w *exportWriter) mpint(x *big.Int, typ types.Type) {
- basic, ok := typ.Underlying().(*types.Basic)
- if !ok {
- panic(internalErrorf("unexpected type %v (%T)", typ.Underlying(), typ.Underlying()))
- }
-
- signed, maxBytes := intSize(basic)
-
- negative := x.Sign() < 0
- if !signed && negative {
- panic(internalErrorf("negative unsigned integer; type %v, value %v", typ, x))
- }
-
- b := x.Bytes()
- if len(b) > 0 && b[0] == 0 {
- panic(internalErrorf("leading zeros"))
- }
- if uint(len(b)) > maxBytes {
- panic(internalErrorf("bad mpint length: %d > %d (type %v, value %v)", len(b), maxBytes, typ, x))
- }
-
- maxSmall := 256 - maxBytes
- if signed {
- maxSmall = 256 - 2*maxBytes
- }
- if maxBytes == 1 {
- maxSmall = 256
- }
-
- // Check if x can use small value encoding.
- if len(b) <= 1 {
- var ux uint
- if len(b) == 1 {
- ux = uint(b[0])
- }
- if signed {
- ux <<= 1
- if negative {
- ux--
- }
- }
- if ux < maxSmall {
- w.data.WriteByte(byte(ux))
- return
- }
- }
-
- n := 256 - uint(len(b))
- if signed {
- n = 256 - 2*uint(len(b))
- if negative {
- n |= 1
- }
- }
- if n < maxSmall || n >= 256 {
- panic(internalErrorf("encoding mistake: %d, %v, %v => %d", len(b), signed, negative, n))
- }
-
- w.data.WriteByte(byte(n))
- w.data.Write(b)
-}
-
-// mpfloat exports a multi-precision floating point number.
-//
-// The number's value is decomposed into mantissa × 2**exponent, where
-// mantissa is an integer. The value is written out as mantissa (as a
-// multi-precision integer) and then the exponent, except exponent is
-// omitted if mantissa is zero.
-func (w *exportWriter) mpfloat(f *big.Float, typ types.Type) {
- if f.IsInf() {
- panic("infinite constant")
- }
-
- // Break into f = mant × 2**exp, with 0.5 <= mant < 1.
- var mant big.Float
- exp := int64(f.MantExp(&mant))
-
- // Scale so that mant is an integer.
- prec := mant.MinPrec()
- mant.SetMantExp(&mant, int(prec))
- exp -= int64(prec)
-
- manti, acc := mant.Int(nil)
- if acc != big.Exact {
- panic(internalErrorf("mantissa scaling failed for %f (%s)", f, acc))
- }
- w.mpint(manti, typ)
- if manti.Sign() != 0 {
- w.int64(exp)
- }
-}
-
-func (w *exportWriter) bool(b bool) bool {
- var x uint64
- if b {
- x = 1
- }
- w.uint64(x)
- return b
-}
-
-func (w *exportWriter) int64(x int64) { w.data.int64(x) }
-func (w *exportWriter) uint64(x uint64) { w.data.uint64(x) }
-func (w *exportWriter) string(s string) { w.uint64(w.p.stringOff(s)) }
-
-func (w *exportWriter) localIdent(obj types.Object) {
- // Anonymous parameters.
- if obj == nil {
- w.string("")
- return
- }
-
- name := obj.Name()
- if name == "_" {
- w.string("_")
- return
- }
-
- w.string(name)
-}
-
-type intWriter struct {
- bytes.Buffer
-}
-
-func (w *intWriter) int64(x int64) {
- var buf [binary.MaxVarintLen64]byte
- n := binary.PutVarint(buf[:], x)
- w.Write(buf[:n])
-}
-
-func (w *intWriter) uint64(x uint64) {
- var buf [binary.MaxVarintLen64]byte
- n := binary.PutUvarint(buf[:], x)
- w.Write(buf[:n])
-}
-
-func assert(cond bool) {
- if !cond {
- panic("internal error: assertion failed")
- }
-}
-
-// The below is copied from go/src/cmd/compile/internal/gc/syntax.go.
-
-// objQueue is a FIFO queue of types.Object. The zero value of objQueue is
-// a ready-to-use empty queue.
-type objQueue struct {
- ring []types.Object
- head, tail int
-}
-
-// empty returns true if q contains no Nodes.
-func (q *objQueue) empty() bool {
- return q.head == q.tail
-}
-
-// pushTail appends n to the tail of the queue.
-func (q *objQueue) pushTail(obj types.Object) {
- if len(q.ring) == 0 {
- q.ring = make([]types.Object, 16)
- } else if q.head+len(q.ring) == q.tail {
- // Grow the ring.
- nring := make([]types.Object, len(q.ring)*2)
- // Copy the old elements.
- part := q.ring[q.head%len(q.ring):]
- if q.tail-q.head <= len(part) {
- part = part[:q.tail-q.head]
- copy(nring, part)
- } else {
- pos := copy(nring, part)
- copy(nring[pos:], q.ring[:q.tail%len(q.ring)])
- }
- q.ring, q.head, q.tail = nring, 0, q.tail-q.head
- }
-
- q.ring[q.tail%len(q.ring)] = obj
- q.tail++
-}
-
-// popHead pops a node from the head of the queue. It panics if q is empty.
-func (q *objQueue) popHead() types.Object {
- if q.empty() {
- panic("dequeue empty")
- }
- obj := q.ring[q.head%len(q.ring)]
- q.head++
- return obj
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go b/vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go
deleted file mode 100644
index 4caa0f55..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go
+++ /dev/null
@@ -1,878 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Indexed package import.
-// See cmd/compile/internal/gc/iexport.go for the export data format.
-
-// This file is a copy of $GOROOT/src/go/internal/gcimporter/iimport.go.
-
-package gcimporter
-
-import (
- "bytes"
- "encoding/binary"
- "fmt"
- "go/constant"
- "go/token"
- "go/types"
- "io"
- "math/big"
- "sort"
- "strings"
-
- "golang.org/x/tools/internal/typeparams"
-)
-
-type intReader struct {
- *bytes.Reader
- path string
-}
-
-func (r *intReader) int64() int64 {
- i, err := binary.ReadVarint(r.Reader)
- if err != nil {
- errorf("import %q: read varint error: %v", r.path, err)
- }
- return i
-}
-
-func (r *intReader) uint64() uint64 {
- i, err := binary.ReadUvarint(r.Reader)
- if err != nil {
- errorf("import %q: read varint error: %v", r.path, err)
- }
- return i
-}
-
-// Keep this in sync with constants in iexport.go.
-const (
- iexportVersionGo1_11 = 0
- iexportVersionPosCol = 1
- iexportVersionGo1_18 = 2
- iexportVersionGenerics = 2
-)
-
-type ident struct {
- pkg *types.Package
- name string
-}
-
-const predeclReserved = 32
-
-type itag uint64
-
-const (
- // Types
- definedType itag = iota
- pointerType
- sliceType
- arrayType
- chanType
- mapType
- signatureType
- structType
- interfaceType
- typeParamType
- instanceType
- unionType
-)
-
-// IImportData imports a package from the serialized package data
-// and returns 0 and a reference to the package.
-// If the export data version is not recognized or the format is otherwise
-// compromised, an error is returned.
-func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (int, *types.Package, error) {
- pkgs, err := iimportCommon(fset, imports, data, false, path)
- if err != nil {
- return 0, nil, err
- }
- return 0, pkgs[0], nil
-}
-
-// IImportBundle imports a set of packages from the serialized package bundle.
-func IImportBundle(fset *token.FileSet, imports map[string]*types.Package, data []byte) ([]*types.Package, error) {
- return iimportCommon(fset, imports, data, true, "")
-}
-
-func iimportCommon(fset *token.FileSet, imports map[string]*types.Package, data []byte, bundle bool, path string) (pkgs []*types.Package, err error) {
- const currentVersion = 1
- version := int64(-1)
- if !debug {
- defer func() {
- if e := recover(); e != nil {
- if bundle {
- err = fmt.Errorf("%v", e)
- } else if version > currentVersion {
- err = fmt.Errorf("cannot import %q (%v), export data is newer version - update tool", path, e)
- } else {
- err = fmt.Errorf("cannot import %q (%v), possibly version skew - reinstall package", path, e)
- }
- }
- }()
- }
-
- r := &intReader{bytes.NewReader(data), path}
-
- if bundle {
- bundleVersion := r.uint64()
- switch bundleVersion {
- case bundleVersion:
- default:
- errorf("unknown bundle format version %d", bundleVersion)
- }
- }
-
- version = int64(r.uint64())
- switch version {
- case iexportVersionGo1_18, iexportVersionPosCol, iexportVersionGo1_11:
- default:
- if version > iexportVersionGo1_18 {
- errorf("unstable iexport format version %d, just rebuild compiler and std library", version)
- } else {
- errorf("unknown iexport format version %d", version)
- }
- }
-
- sLen := int64(r.uint64())
- dLen := int64(r.uint64())
-
- whence, _ := r.Seek(0, io.SeekCurrent)
- stringData := data[whence : whence+sLen]
- declData := data[whence+sLen : whence+sLen+dLen]
- r.Seek(sLen+dLen, io.SeekCurrent)
-
- p := iimporter{
- version: int(version),
- ipath: path,
-
- stringData: stringData,
- stringCache: make(map[uint64]string),
- pkgCache: make(map[uint64]*types.Package),
-
- declData: declData,
- pkgIndex: make(map[*types.Package]map[string]uint64),
- typCache: make(map[uint64]types.Type),
- // Separate map for typeparams, keyed by their package and unique
- // name.
- tparamIndex: make(map[ident]types.Type),
-
- fake: fakeFileSet{
- fset: fset,
- files: make(map[string]*fileInfo),
- },
- }
- defer p.fake.setLines() // set lines for files in fset
-
- for i, pt := range predeclared() {
- p.typCache[uint64(i)] = pt
- }
-
- pkgList := make([]*types.Package, r.uint64())
- for i := range pkgList {
- pkgPathOff := r.uint64()
- pkgPath := p.stringAt(pkgPathOff)
- pkgName := p.stringAt(r.uint64())
- _ = r.uint64() // package height; unused by go/types
-
- if pkgPath == "" {
- pkgPath = path
- }
- pkg := imports[pkgPath]
- if pkg == nil {
- pkg = types.NewPackage(pkgPath, pkgName)
- imports[pkgPath] = pkg
- } else if pkg.Name() != pkgName {
- errorf("conflicting names %s and %s for package %q", pkg.Name(), pkgName, path)
- }
-
- p.pkgCache[pkgPathOff] = pkg
-
- nameIndex := make(map[string]uint64)
- for nSyms := r.uint64(); nSyms > 0; nSyms-- {
- name := p.stringAt(r.uint64())
- nameIndex[name] = r.uint64()
- }
-
- p.pkgIndex[pkg] = nameIndex
- pkgList[i] = pkg
- }
-
- if bundle {
- pkgs = make([]*types.Package, r.uint64())
- for i := range pkgs {
- pkg := p.pkgAt(r.uint64())
- imps := make([]*types.Package, r.uint64())
- for j := range imps {
- imps[j] = p.pkgAt(r.uint64())
- }
- pkg.SetImports(imps)
- pkgs[i] = pkg
- }
- } else {
- if len(pkgList) == 0 {
- errorf("no packages found for %s", path)
- panic("unreachable")
- }
- pkgs = pkgList[:1]
-
- // record all referenced packages as imports
- list := append(([]*types.Package)(nil), pkgList[1:]...)
- sort.Sort(byPath(list))
- pkgs[0].SetImports(list)
- }
-
- for _, pkg := range pkgs {
- if pkg.Complete() {
- continue
- }
-
- names := make([]string, 0, len(p.pkgIndex[pkg]))
- for name := range p.pkgIndex[pkg] {
- names = append(names, name)
- }
- sort.Strings(names)
- for _, name := range names {
- p.doDecl(pkg, name)
- }
-
- // package was imported completely and without errors
- pkg.MarkComplete()
- }
-
- // SetConstraint can't be called if the constraint type is not yet complete.
- // When type params are created in the 'P' case of (*importReader).obj(),
- // the associated constraint type may not be complete due to recursion.
- // Therefore, we defer calling SetConstraint there, and call it here instead
- // after all types are complete.
- for _, d := range p.later {
- typeparams.SetTypeParamConstraint(d.t, d.constraint)
- }
-
- for _, typ := range p.interfaceList {
- typ.Complete()
- }
-
- return pkgs, nil
-}
-
-type setConstraintArgs struct {
- t *typeparams.TypeParam
- constraint types.Type
-}
-
-type iimporter struct {
- version int
- ipath string
-
- stringData []byte
- stringCache map[uint64]string
- pkgCache map[uint64]*types.Package
-
- declData []byte
- pkgIndex map[*types.Package]map[string]uint64
- typCache map[uint64]types.Type
- tparamIndex map[ident]types.Type
-
- fake fakeFileSet
- interfaceList []*types.Interface
-
- // Arguments for calls to SetConstraint that are deferred due to recursive types
- later []setConstraintArgs
-
- indent int // for tracing support
-}
-
-func (p *iimporter) trace(format string, args ...interface{}) {
- if !trace {
- // Call sites should also be guarded, but having this check here allows
- // easily enabling/disabling debug trace statements.
- return
- }
- fmt.Printf(strings.Repeat("..", p.indent)+format+"\n", args...)
-}
-
-func (p *iimporter) doDecl(pkg *types.Package, name string) {
- if debug {
- p.trace("import decl %s", name)
- p.indent++
- defer func() {
- p.indent--
- p.trace("=> %s", name)
- }()
- }
- // See if we've already imported this declaration.
- if obj := pkg.Scope().Lookup(name); obj != nil {
- return
- }
-
- off, ok := p.pkgIndex[pkg][name]
- if !ok {
- errorf("%v.%v not in index", pkg, name)
- }
-
- r := &importReader{p: p, currPkg: pkg}
- r.declReader.Reset(p.declData[off:])
-
- r.obj(name)
-}
-
-func (p *iimporter) stringAt(off uint64) string {
- if s, ok := p.stringCache[off]; ok {
- return s
- }
-
- slen, n := binary.Uvarint(p.stringData[off:])
- if n <= 0 {
- errorf("varint failed")
- }
- spos := off + uint64(n)
- s := string(p.stringData[spos : spos+slen])
- p.stringCache[off] = s
- return s
-}
-
-func (p *iimporter) pkgAt(off uint64) *types.Package {
- if pkg, ok := p.pkgCache[off]; ok {
- return pkg
- }
- path := p.stringAt(off)
- errorf("missing package %q in %q", path, p.ipath)
- return nil
-}
-
-func (p *iimporter) typAt(off uint64, base *types.Named) types.Type {
- if t, ok := p.typCache[off]; ok && canReuse(base, t) {
- return t
- }
-
- if off < predeclReserved {
- errorf("predeclared type missing from cache: %v", off)
- }
-
- r := &importReader{p: p}
- r.declReader.Reset(p.declData[off-predeclReserved:])
- t := r.doType(base)
-
- if canReuse(base, t) {
- p.typCache[off] = t
- }
- return t
-}
-
-// canReuse reports whether the type rhs on the RHS of the declaration for def
-// may be re-used.
-//
-// Specifically, if def is non-nil and rhs is an interface type with methods, it
-// may not be re-used because we have a convention of setting the receiver type
-// for interface methods to def.
-func canReuse(def *types.Named, rhs types.Type) bool {
- if def == nil {
- return true
- }
- iface, _ := rhs.(*types.Interface)
- if iface == nil {
- return true
- }
- // Don't use iface.Empty() here as iface may not be complete.
- return iface.NumEmbeddeds() == 0 && iface.NumExplicitMethods() == 0
-}
-
-type importReader struct {
- p *iimporter
- declReader bytes.Reader
- currPkg *types.Package
- prevFile string
- prevLine int64
- prevColumn int64
-}
-
-func (r *importReader) obj(name string) {
- tag := r.byte()
- pos := r.pos()
-
- switch tag {
- case 'A':
- typ := r.typ()
-
- r.declare(types.NewTypeName(pos, r.currPkg, name, typ))
-
- case 'C':
- typ, val := r.value()
-
- r.declare(types.NewConst(pos, r.currPkg, name, typ, val))
-
- case 'F', 'G':
- var tparams []*typeparams.TypeParam
- if tag == 'G' {
- tparams = r.tparamList()
- }
- sig := r.signature(nil, nil, tparams)
- r.declare(types.NewFunc(pos, r.currPkg, name, sig))
-
- case 'T', 'U':
- // Types can be recursive. We need to setup a stub
- // declaration before recursing.
- obj := types.NewTypeName(pos, r.currPkg, name, nil)
- named := types.NewNamed(obj, nil, nil)
- // Declare obj before calling r.tparamList, so the new type name is recognized
- // if used in the constraint of one of its own typeparams (see #48280).
- r.declare(obj)
- if tag == 'U' {
- tparams := r.tparamList()
- typeparams.SetForNamed(named, tparams)
- }
-
- underlying := r.p.typAt(r.uint64(), named).Underlying()
- named.SetUnderlying(underlying)
-
- if !isInterface(underlying) {
- for n := r.uint64(); n > 0; n-- {
- mpos := r.pos()
- mname := r.ident()
- recv := r.param()
-
- // If the receiver has any targs, set those as the
- // rparams of the method (since those are the
- // typeparams being used in the method sig/body).
- base := baseType(recv.Type())
- assert(base != nil)
- targs := typeparams.NamedTypeArgs(base)
- var rparams []*typeparams.TypeParam
- if targs.Len() > 0 {
- rparams = make([]*typeparams.TypeParam, targs.Len())
- for i := range rparams {
- rparams[i] = targs.At(i).(*typeparams.TypeParam)
- }
- }
- msig := r.signature(recv, rparams, nil)
-
- named.AddMethod(types.NewFunc(mpos, r.currPkg, mname, msig))
- }
- }
-
- case 'P':
- // We need to "declare" a typeparam in order to have a name that
- // can be referenced recursively (if needed) in the type param's
- // bound.
- if r.p.version < iexportVersionGenerics {
- errorf("unexpected type param type")
- }
- name0 := tparamName(name)
- tn := types.NewTypeName(pos, r.currPkg, name0, nil)
- t := typeparams.NewTypeParam(tn, nil)
-
- // To handle recursive references to the typeparam within its
- // bound, save the partial type in tparamIndex before reading the bounds.
- id := ident{r.currPkg, name}
- r.p.tparamIndex[id] = t
- var implicit bool
- if r.p.version >= iexportVersionGo1_18 {
- implicit = r.bool()
- }
- constraint := r.typ()
- if implicit {
- iface, _ := constraint.(*types.Interface)
- if iface == nil {
- errorf("non-interface constraint marked implicit")
- }
- typeparams.MarkImplicit(iface)
- }
- // The constraint type may not be complete, if we
- // are in the middle of a type recursion involving type
- // constraints. So, we defer SetConstraint until we have
- // completely set up all types in ImportData.
- r.p.later = append(r.p.later, setConstraintArgs{t: t, constraint: constraint})
-
- case 'V':
- typ := r.typ()
-
- r.declare(types.NewVar(pos, r.currPkg, name, typ))
-
- default:
- errorf("unexpected tag: %v", tag)
- }
-}
-
-func (r *importReader) declare(obj types.Object) {
- obj.Pkg().Scope().Insert(obj)
-}
-
-func (r *importReader) value() (typ types.Type, val constant.Value) {
- typ = r.typ()
- if r.p.version >= iexportVersionGo1_18 {
- // TODO: add support for using the kind.
- _ = constant.Kind(r.int64())
- }
-
- switch b := typ.Underlying().(*types.Basic); b.Info() & types.IsConstType {
- case types.IsBoolean:
- val = constant.MakeBool(r.bool())
-
- case types.IsString:
- val = constant.MakeString(r.string())
-
- case types.IsInteger:
- var x big.Int
- r.mpint(&x, b)
- val = constant.Make(&x)
-
- case types.IsFloat:
- val = r.mpfloat(b)
-
- case types.IsComplex:
- re := r.mpfloat(b)
- im := r.mpfloat(b)
- val = constant.BinaryOp(re, token.ADD, constant.MakeImag(im))
-
- default:
- if b.Kind() == types.Invalid {
- val = constant.MakeUnknown()
- return
- }
- errorf("unexpected type %v", typ) // panics
- panic("unreachable")
- }
-
- return
-}
-
-func intSize(b *types.Basic) (signed bool, maxBytes uint) {
- if (b.Info() & types.IsUntyped) != 0 {
- return true, 64
- }
-
- switch b.Kind() {
- case types.Float32, types.Complex64:
- return true, 3
- case types.Float64, types.Complex128:
- return true, 7
- }
-
- signed = (b.Info() & types.IsUnsigned) == 0
- switch b.Kind() {
- case types.Int8, types.Uint8:
- maxBytes = 1
- case types.Int16, types.Uint16:
- maxBytes = 2
- case types.Int32, types.Uint32:
- maxBytes = 4
- default:
- maxBytes = 8
- }
-
- return
-}
-
-func (r *importReader) mpint(x *big.Int, typ *types.Basic) {
- signed, maxBytes := intSize(typ)
-
- maxSmall := 256 - maxBytes
- if signed {
- maxSmall = 256 - 2*maxBytes
- }
- if maxBytes == 1 {
- maxSmall = 256
- }
-
- n, _ := r.declReader.ReadByte()
- if uint(n) < maxSmall {
- v := int64(n)
- if signed {
- v >>= 1
- if n&1 != 0 {
- v = ^v
- }
- }
- x.SetInt64(v)
- return
- }
-
- v := -n
- if signed {
- v = -(n &^ 1) >> 1
- }
- if v < 1 || uint(v) > maxBytes {
- errorf("weird decoding: %v, %v => %v", n, signed, v)
- }
- b := make([]byte, v)
- io.ReadFull(&r.declReader, b)
- x.SetBytes(b)
- if signed && n&1 != 0 {
- x.Neg(x)
- }
-}
-
-func (r *importReader) mpfloat(typ *types.Basic) constant.Value {
- var mant big.Int
- r.mpint(&mant, typ)
- var f big.Float
- f.SetInt(&mant)
- if f.Sign() != 0 {
- f.SetMantExp(&f, int(r.int64()))
- }
- return constant.Make(&f)
-}
-
-func (r *importReader) ident() string {
- return r.string()
-}
-
-func (r *importReader) qualifiedIdent() (*types.Package, string) {
- name := r.string()
- pkg := r.pkg()
- return pkg, name
-}
-
-func (r *importReader) pos() token.Pos {
- if r.p.version >= iexportVersionPosCol {
- r.posv1()
- } else {
- r.posv0()
- }
-
- if r.prevFile == "" && r.prevLine == 0 && r.prevColumn == 0 {
- return token.NoPos
- }
- return r.p.fake.pos(r.prevFile, int(r.prevLine), int(r.prevColumn))
-}
-
-func (r *importReader) posv0() {
- delta := r.int64()
- if delta != deltaNewFile {
- r.prevLine += delta
- } else if l := r.int64(); l == -1 {
- r.prevLine += deltaNewFile
- } else {
- r.prevFile = r.string()
- r.prevLine = l
- }
-}
-
-func (r *importReader) posv1() {
- delta := r.int64()
- r.prevColumn += delta >> 1
- if delta&1 != 0 {
- delta = r.int64()
- r.prevLine += delta >> 1
- if delta&1 != 0 {
- r.prevFile = r.string()
- }
- }
-}
-
-func (r *importReader) typ() types.Type {
- return r.p.typAt(r.uint64(), nil)
-}
-
-func isInterface(t types.Type) bool {
- _, ok := t.(*types.Interface)
- return ok
-}
-
-func (r *importReader) pkg() *types.Package { return r.p.pkgAt(r.uint64()) }
-func (r *importReader) string() string { return r.p.stringAt(r.uint64()) }
-
-func (r *importReader) doType(base *types.Named) (res types.Type) {
- k := r.kind()
- if debug {
- r.p.trace("importing type %d (base: %s)", k, base)
- r.p.indent++
- defer func() {
- r.p.indent--
- r.p.trace("=> %s", res)
- }()
- }
- switch k {
- default:
- errorf("unexpected kind tag in %q: %v", r.p.ipath, k)
- return nil
-
- case definedType:
- pkg, name := r.qualifiedIdent()
- r.p.doDecl(pkg, name)
- return pkg.Scope().Lookup(name).(*types.TypeName).Type()
- case pointerType:
- return types.NewPointer(r.typ())
- case sliceType:
- return types.NewSlice(r.typ())
- case arrayType:
- n := r.uint64()
- return types.NewArray(r.typ(), int64(n))
- case chanType:
- dir := chanDir(int(r.uint64()))
- return types.NewChan(dir, r.typ())
- case mapType:
- return types.NewMap(r.typ(), r.typ())
- case signatureType:
- r.currPkg = r.pkg()
- return r.signature(nil, nil, nil)
-
- case structType:
- r.currPkg = r.pkg()
-
- fields := make([]*types.Var, r.uint64())
- tags := make([]string, len(fields))
- for i := range fields {
- fpos := r.pos()
- fname := r.ident()
- ftyp := r.typ()
- emb := r.bool()
- tag := r.string()
-
- fields[i] = types.NewField(fpos, r.currPkg, fname, ftyp, emb)
- tags[i] = tag
- }
- return types.NewStruct(fields, tags)
-
- case interfaceType:
- r.currPkg = r.pkg()
-
- embeddeds := make([]types.Type, r.uint64())
- for i := range embeddeds {
- _ = r.pos()
- embeddeds[i] = r.typ()
- }
-
- methods := make([]*types.Func, r.uint64())
- for i := range methods {
- mpos := r.pos()
- mname := r.ident()
-
- // TODO(mdempsky): Matches bimport.go, but I
- // don't agree with this.
- var recv *types.Var
- if base != nil {
- recv = types.NewVar(token.NoPos, r.currPkg, "", base)
- }
-
- msig := r.signature(recv, nil, nil)
- methods[i] = types.NewFunc(mpos, r.currPkg, mname, msig)
- }
-
- typ := newInterface(methods, embeddeds)
- r.p.interfaceList = append(r.p.interfaceList, typ)
- return typ
-
- case typeParamType:
- if r.p.version < iexportVersionGenerics {
- errorf("unexpected type param type")
- }
- pkg, name := r.qualifiedIdent()
- id := ident{pkg, name}
- if t, ok := r.p.tparamIndex[id]; ok {
- // We're already in the process of importing this typeparam.
- return t
- }
- // Otherwise, import the definition of the typeparam now.
- r.p.doDecl(pkg, name)
- return r.p.tparamIndex[id]
-
- case instanceType:
- if r.p.version < iexportVersionGenerics {
- errorf("unexpected instantiation type")
- }
- // pos does not matter for instances: they are positioned on the original
- // type.
- _ = r.pos()
- len := r.uint64()
- targs := make([]types.Type, len)
- for i := range targs {
- targs[i] = r.typ()
- }
- baseType := r.typ()
- // The imported instantiated type doesn't include any methods, so
- // we must always use the methods of the base (orig) type.
- // TODO provide a non-nil *Environment
- t, _ := typeparams.Instantiate(nil, baseType, targs, false)
- return t
-
- case unionType:
- if r.p.version < iexportVersionGenerics {
- errorf("unexpected instantiation type")
- }
- terms := make([]*typeparams.Term, r.uint64())
- for i := range terms {
- terms[i] = typeparams.NewTerm(r.bool(), r.typ())
- }
- return typeparams.NewUnion(terms)
- }
-}
-
-func (r *importReader) kind() itag {
- return itag(r.uint64())
-}
-
-func (r *importReader) signature(recv *types.Var, rparams []*typeparams.TypeParam, tparams []*typeparams.TypeParam) *types.Signature {
- params := r.paramList()
- results := r.paramList()
- variadic := params.Len() > 0 && r.bool()
- return typeparams.NewSignatureType(recv, rparams, tparams, params, results, variadic)
-}
-
-func (r *importReader) tparamList() []*typeparams.TypeParam {
- n := r.uint64()
- if n == 0 {
- return nil
- }
- xs := make([]*typeparams.TypeParam, n)
- for i := range xs {
- // Note: the standard library importer is tolerant of nil types here,
- // though would panic in SetTypeParams.
- xs[i] = r.typ().(*typeparams.TypeParam)
- }
- return xs
-}
-
-func (r *importReader) paramList() *types.Tuple {
- xs := make([]*types.Var, r.uint64())
- for i := range xs {
- xs[i] = r.param()
- }
- return types.NewTuple(xs...)
-}
-
-func (r *importReader) param() *types.Var {
- pos := r.pos()
- name := r.ident()
- typ := r.typ()
- return types.NewParam(pos, r.currPkg, name, typ)
-}
-
-func (r *importReader) bool() bool {
- return r.uint64() != 0
-}
-
-func (r *importReader) int64() int64 {
- n, err := binary.ReadVarint(&r.declReader)
- if err != nil {
- errorf("readVarint: %v", err)
- }
- return n
-}
-
-func (r *importReader) uint64() uint64 {
- n, err := binary.ReadUvarint(&r.declReader)
- if err != nil {
- errorf("readUvarint: %v", err)
- }
- return n
-}
-
-func (r *importReader) byte() byte {
- x, err := r.declReader.ReadByte()
- if err != nil {
- errorf("declReader.ReadByte: %v", err)
- }
- return x
-}
-
-func baseType(typ types.Type) *types.Named {
- // pointer receivers are never types.Named types
- if p, _ := typ.(*types.Pointer); p != nil {
- typ = p.Elem()
- }
- // receiver base types are always (possibly generic) types.Named types
- n, _ := typ.(*types.Named)
- return n
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/newInterface10.go b/vendor/golang.org/x/tools/go/internal/gcimporter/newInterface10.go
deleted file mode 100644
index 8b163e3d..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/newInterface10.go
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build !go1.11
-// +build !go1.11
-
-package gcimporter
-
-import "go/types"
-
-func newInterface(methods []*types.Func, embeddeds []types.Type) *types.Interface {
- named := make([]*types.Named, len(embeddeds))
- for i, e := range embeddeds {
- var ok bool
- named[i], ok = e.(*types.Named)
- if !ok {
- panic("embedding of non-defined interfaces in interfaces is not supported before Go 1.11")
- }
- }
- return types.NewInterface(methods, named)
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/newInterface11.go b/vendor/golang.org/x/tools/go/internal/gcimporter/newInterface11.go
deleted file mode 100644
index 49984f40..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/newInterface11.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build go1.11
-// +build go1.11
-
-package gcimporter
-
-import "go/types"
-
-func newInterface(methods []*types.Func, embeddeds []types.Type) *types.Interface {
- return types.NewInterfaceType(methods, embeddeds)
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go b/vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go
deleted file mode 100644
index d892273e..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build !go1.18
-// +build !go1.18
-
-package gcimporter
-
-import "go/types"
-
-const iexportVersion = iexportVersionGo1_11
-
-func additionalPredeclared() []types.Type {
- return nil
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go b/vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go
deleted file mode 100644
index a9938432..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build go1.18
-// +build go1.18
-
-package gcimporter
-
-import "go/types"
-
-const iexportVersion = iexportVersionGenerics
-
-// additionalPredeclared returns additional predeclared types in go.1.18.
-func additionalPredeclared() []types.Type {
- return []types.Type{
- // comparable
- types.Universe.Lookup("comparable").Type(),
-
- // any
- types.Universe.Lookup("any").Type(),
- }
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/unified_no.go b/vendor/golang.org/x/tools/go/internal/gcimporter/unified_no.go
deleted file mode 100644
index 286bf445..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/unified_no.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build !(go1.18 && goexperiment.unified)
-// +build !go1.18 !goexperiment.unified
-
-package gcimporter
-
-const unifiedIR = false
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/unified_yes.go b/vendor/golang.org/x/tools/go/internal/gcimporter/unified_yes.go
deleted file mode 100644
index b5d69ffb..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/unified_yes.go
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build go1.18 && goexperiment.unified
-// +build go1.18,goexperiment.unified
-
-package gcimporter
-
-const unifiedIR = true
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/ureader_no.go b/vendor/golang.org/x/tools/go/internal/gcimporter/ureader_no.go
deleted file mode 100644
index 8eb20729..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/ureader_no.go
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build !go1.18
-// +build !go1.18
-
-package gcimporter
-
-import (
- "fmt"
- "go/token"
- "go/types"
-)
-
-func UImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) {
- err = fmt.Errorf("go/tools compiled with a Go version earlier than 1.18 cannot read unified IR export data")
- return
-}
diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/ureader_yes.go b/vendor/golang.org/x/tools/go/internal/gcimporter/ureader_yes.go
deleted file mode 100644
index 3c1a4375..00000000
--- a/vendor/golang.org/x/tools/go/internal/gcimporter/ureader_yes.go
+++ /dev/null
@@ -1,612 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Derived from go/internal/gcimporter/ureader.go
-
-//go:build go1.18
-// +build go1.18
-
-package gcimporter
-
-import (
- "go/token"
- "go/types"
- "strings"
-
- "golang.org/x/tools/go/internal/pkgbits"
-)
-
-// A pkgReader holds the shared state for reading a unified IR package
-// description.
-type pkgReader struct {
- pkgbits.PkgDecoder
-
- fake fakeFileSet
-
- ctxt *types.Context
- imports map[string]*types.Package // previously imported packages, indexed by path
-
- // lazily initialized arrays corresponding to the unified IR
- // PosBase, Pkg, and Type sections, respectively.
- posBases []string // position bases (i.e., file names)
- pkgs []*types.Package
- typs []types.Type
-
- // laterFns holds functions that need to be invoked at the end of
- // import reading.
- laterFns []func()
-}
-
-// later adds a function to be invoked at the end of import reading.
-func (pr *pkgReader) later(fn func()) {
- pr.laterFns = append(pr.laterFns, fn)
-}
-
-// See cmd/compile/internal/noder.derivedInfo.
-type derivedInfo struct {
- idx pkgbits.Index
- needed bool
-}
-
-// See cmd/compile/internal/noder.typeInfo.
-type typeInfo struct {
- idx pkgbits.Index
- derived bool
-}
-
-func UImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) {
- s := string(data)
- s = s[:strings.LastIndex(s, "\n$$\n")]
- input := pkgbits.NewPkgDecoder(path, s)
- pkg = readUnifiedPackage(fset, nil, imports, input)
- return
-}
-
-// readUnifiedPackage reads a package description from the given
-// unified IR export data decoder.
-func readUnifiedPackage(fset *token.FileSet, ctxt *types.Context, imports map[string]*types.Package, input pkgbits.PkgDecoder) *types.Package {
- pr := pkgReader{
- PkgDecoder: input,
-
- fake: fakeFileSet{
- fset: fset,
- files: make(map[string]*fileInfo),
- },
-
- ctxt: ctxt,
- imports: imports,
-
- posBases: make([]string, input.NumElems(pkgbits.RelocPosBase)),
- pkgs: make([]*types.Package, input.NumElems(pkgbits.RelocPkg)),
- typs: make([]types.Type, input.NumElems(pkgbits.RelocType)),
- }
- defer pr.fake.setLines()
-
- r := pr.newReader(pkgbits.RelocMeta, pkgbits.PublicRootIdx, pkgbits.SyncPublic)
- pkg := r.pkg()
- r.Bool() // has init
-
- for i, n := 0, r.Len(); i < n; i++ {
- // As if r.obj(), but avoiding the Scope.Lookup call,
- // to avoid eager loading of imports.
- r.Sync(pkgbits.SyncObject)
- assert(!r.Bool())
- r.p.objIdx(r.Reloc(pkgbits.RelocObj))
- assert(r.Len() == 0)
- }
-
- r.Sync(pkgbits.SyncEOF)
-
- for _, fn := range pr.laterFns {
- fn()
- }
-
- pkg.MarkComplete()
- return pkg
-}
-
-// A reader holds the state for reading a single unified IR element
-// within a package.
-type reader struct {
- pkgbits.Decoder
-
- p *pkgReader
-
- dict *readerDict
-}
-
-// A readerDict holds the state for type parameters that parameterize
-// the current unified IR element.
-type readerDict struct {
- // bounds is a slice of typeInfos corresponding to the underlying
- // bounds of the element's type parameters.
- bounds []typeInfo
-
- // tparams is a slice of the constructed TypeParams for the element.
- tparams []*types.TypeParam
-
- // devived is a slice of types derived from tparams, which may be
- // instantiated while reading the current element.
- derived []derivedInfo
- derivedTypes []types.Type // lazily instantiated from derived
-}
-
-func (pr *pkgReader) newReader(k pkgbits.RelocKind, idx pkgbits.Index, marker pkgbits.SyncMarker) *reader {
- return &reader{
- Decoder: pr.NewDecoder(k, idx, marker),
- p: pr,
- }
-}
-
-// @@@ Positions
-
-func (r *reader) pos() token.Pos {
- r.Sync(pkgbits.SyncPos)
- if !r.Bool() {
- return token.NoPos
- }
-
- // TODO(mdempsky): Delta encoding.
- posBase := r.posBase()
- line := r.Uint()
- col := r.Uint()
- return r.p.fake.pos(posBase, int(line), int(col))
-}
-
-func (r *reader) posBase() string {
- return r.p.posBaseIdx(r.Reloc(pkgbits.RelocPosBase))
-}
-
-func (pr *pkgReader) posBaseIdx(idx pkgbits.Index) string {
- if b := pr.posBases[idx]; b != "" {
- return b
- }
-
- r := pr.newReader(pkgbits.RelocPosBase, idx, pkgbits.SyncPosBase)
-
- // Within types2, position bases have a lot more details (e.g.,
- // keeping track of where //line directives appeared exactly).
- //
- // For go/types, we just track the file name.
-
- filename := r.String()
-
- if r.Bool() { // file base
- // Was: "b = token.NewTrimmedFileBase(filename, true)"
- } else { // line base
- pos := r.pos()
- line := r.Uint()
- col := r.Uint()
-
- // Was: "b = token.NewLineBase(pos, filename, true, line, col)"
- _, _, _ = pos, line, col
- }
-
- b := filename
- pr.posBases[idx] = b
- return b
-}
-
-// @@@ Packages
-
-func (r *reader) pkg() *types.Package {
- r.Sync(pkgbits.SyncPkg)
- return r.p.pkgIdx(r.Reloc(pkgbits.RelocPkg))
-}
-
-func (pr *pkgReader) pkgIdx(idx pkgbits.Index) *types.Package {
- // TODO(mdempsky): Consider using some non-nil pointer to indicate
- // the universe scope, so we don't need to keep re-reading it.
- if pkg := pr.pkgs[idx]; pkg != nil {
- return pkg
- }
-
- pkg := pr.newReader(pkgbits.RelocPkg, idx, pkgbits.SyncPkgDef).doPkg()
- pr.pkgs[idx] = pkg
- return pkg
-}
-
-func (r *reader) doPkg() *types.Package {
- path := r.String()
- switch path {
- case "":
- path = r.p.PkgPath()
- case "builtin":
- return nil // universe
- case "unsafe":
- return types.Unsafe
- }
-
- if pkg := r.p.imports[path]; pkg != nil {
- return pkg
- }
-
- name := r.String()
-
- pkg := types.NewPackage(path, name)
- r.p.imports[path] = pkg
-
- imports := make([]*types.Package, r.Len())
- for i := range imports {
- imports[i] = r.pkg()
- }
- pkg.SetImports(imports)
-
- return pkg
-}
-
-// @@@ Types
-
-func (r *reader) typ() types.Type {
- return r.p.typIdx(r.typInfo(), r.dict)
-}
-
-func (r *reader) typInfo() typeInfo {
- r.Sync(pkgbits.SyncType)
- if r.Bool() {
- return typeInfo{idx: pkgbits.Index(r.Len()), derived: true}
- }
- return typeInfo{idx: r.Reloc(pkgbits.RelocType), derived: false}
-}
-
-func (pr *pkgReader) typIdx(info typeInfo, dict *readerDict) types.Type {
- idx := info.idx
- var where *types.Type
- if info.derived {
- where = &dict.derivedTypes[idx]
- idx = dict.derived[idx].idx
- } else {
- where = &pr.typs[idx]
- }
-
- if typ := *where; typ != nil {
- return typ
- }
-
- r := pr.newReader(pkgbits.RelocType, idx, pkgbits.SyncTypeIdx)
- r.dict = dict
-
- typ := r.doTyp()
- assert(typ != nil)
-
- // See comment in pkgReader.typIdx explaining how this happens.
- if prev := *where; prev != nil {
- return prev
- }
-
- *where = typ
- return typ
-}
-
-func (r *reader) doTyp() (res types.Type) {
- switch tag := pkgbits.CodeType(r.Code(pkgbits.SyncType)); tag {
- default:
- errorf("unhandled type tag: %v", tag)
- panic("unreachable")
-
- case pkgbits.TypeBasic:
- return types.Typ[r.Len()]
-
- case pkgbits.TypeNamed:
- obj, targs := r.obj()
- name := obj.(*types.TypeName)
- if len(targs) != 0 {
- t, _ := types.Instantiate(r.p.ctxt, name.Type(), targs, false)
- return t
- }
- return name.Type()
-
- case pkgbits.TypeTypeParam:
- return r.dict.tparams[r.Len()]
-
- case pkgbits.TypeArray:
- len := int64(r.Uint64())
- return types.NewArray(r.typ(), len)
- case pkgbits.TypeChan:
- dir := types.ChanDir(r.Len())
- return types.NewChan(dir, r.typ())
- case pkgbits.TypeMap:
- return types.NewMap(r.typ(), r.typ())
- case pkgbits.TypePointer:
- return types.NewPointer(r.typ())
- case pkgbits.TypeSignature:
- return r.signature(nil, nil, nil)
- case pkgbits.TypeSlice:
- return types.NewSlice(r.typ())
- case pkgbits.TypeStruct:
- return r.structType()
- case pkgbits.TypeInterface:
- return r.interfaceType()
- case pkgbits.TypeUnion:
- return r.unionType()
- }
-}
-
-func (r *reader) structType() *types.Struct {
- fields := make([]*types.Var, r.Len())
- var tags []string
- for i := range fields {
- pos := r.pos()
- pkg, name := r.selector()
- ftyp := r.typ()
- tag := r.String()
- embedded := r.Bool()
-
- fields[i] = types.NewField(pos, pkg, name, ftyp, embedded)
- if tag != "" {
- for len(tags) < i {
- tags = append(tags, "")
- }
- tags = append(tags, tag)
- }
- }
- return types.NewStruct(fields, tags)
-}
-
-func (r *reader) unionType() *types.Union {
- terms := make([]*types.Term, r.Len())
- for i := range terms {
- terms[i] = types.NewTerm(r.Bool(), r.typ())
- }
- return types.NewUnion(terms)
-}
-
-func (r *reader) interfaceType() *types.Interface {
- methods := make([]*types.Func, r.Len())
- embeddeds := make([]types.Type, r.Len())
- implicit := len(methods) == 0 && len(embeddeds) == 1 && r.Bool()
-
- for i := range methods {
- pos := r.pos()
- pkg, name := r.selector()
- mtyp := r.signature(nil, nil, nil)
- methods[i] = types.NewFunc(pos, pkg, name, mtyp)
- }
-
- for i := range embeddeds {
- embeddeds[i] = r.typ()
- }
-
- iface := types.NewInterfaceType(methods, embeddeds)
- if implicit {
- iface.MarkImplicit()
- }
- return iface
-}
-
-func (r *reader) signature(recv *types.Var, rtparams, tparams []*types.TypeParam) *types.Signature {
- r.Sync(pkgbits.SyncSignature)
-
- params := r.params()
- results := r.params()
- variadic := r.Bool()
-
- return types.NewSignatureType(recv, rtparams, tparams, params, results, variadic)
-}
-
-func (r *reader) params() *types.Tuple {
- r.Sync(pkgbits.SyncParams)
-
- params := make([]*types.Var, r.Len())
- for i := range params {
- params[i] = r.param()
- }
-
- return types.NewTuple(params...)
-}
-
-func (r *reader) param() *types.Var {
- r.Sync(pkgbits.SyncParam)
-
- pos := r.pos()
- pkg, name := r.localIdent()
- typ := r.typ()
-
- return types.NewParam(pos, pkg, name, typ)
-}
-
-// @@@ Objects
-
-func (r *reader) obj() (types.Object, []types.Type) {
- r.Sync(pkgbits.SyncObject)
-
- assert(!r.Bool())
-
- pkg, name := r.p.objIdx(r.Reloc(pkgbits.RelocObj))
- obj := pkgScope(pkg).Lookup(name)
-
- targs := make([]types.Type, r.Len())
- for i := range targs {
- targs[i] = r.typ()
- }
-
- return obj, targs
-}
-
-func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
- rname := pr.newReader(pkgbits.RelocName, idx, pkgbits.SyncObject1)
-
- objPkg, objName := rname.qualifiedIdent()
- assert(objName != "")
-
- tag := pkgbits.CodeObj(rname.Code(pkgbits.SyncCodeObj))
-
- if tag == pkgbits.ObjStub {
- assert(objPkg == nil || objPkg == types.Unsafe)
- return objPkg, objName
- }
-
- if objPkg.Scope().Lookup(objName) == nil {
- dict := pr.objDictIdx(idx)
-
- r := pr.newReader(pkgbits.RelocObj, idx, pkgbits.SyncObject1)
- r.dict = dict
-
- declare := func(obj types.Object) {
- objPkg.Scope().Insert(obj)
- }
-
- switch tag {
- default:
- panic("weird")
-
- case pkgbits.ObjAlias:
- pos := r.pos()
- typ := r.typ()
- declare(types.NewTypeName(pos, objPkg, objName, typ))
-
- case pkgbits.ObjConst:
- pos := r.pos()
- typ := r.typ()
- val := r.Value()
- declare(types.NewConst(pos, objPkg, objName, typ, val))
-
- case pkgbits.ObjFunc:
- pos := r.pos()
- tparams := r.typeParamNames()
- sig := r.signature(nil, nil, tparams)
- declare(types.NewFunc(pos, objPkg, objName, sig))
-
- case pkgbits.ObjType:
- pos := r.pos()
-
- obj := types.NewTypeName(pos, objPkg, objName, nil)
- named := types.NewNamed(obj, nil, nil)
- declare(obj)
-
- named.SetTypeParams(r.typeParamNames())
-
- // TODO(mdempsky): Rewrite receiver types to underlying is an
- // Interface? The go/types importer does this (I think because
- // unit tests expected that), but cmd/compile doesn't care
- // about it, so maybe we can avoid worrying about that here.
- rhs := r.typ()
- r.p.later(func() {
- underlying := rhs.Underlying()
- named.SetUnderlying(underlying)
- })
-
- for i, n := 0, r.Len(); i < n; i++ {
- named.AddMethod(r.method())
- }
-
- case pkgbits.ObjVar:
- pos := r.pos()
- typ := r.typ()
- declare(types.NewVar(pos, objPkg, objName, typ))
- }
- }
-
- return objPkg, objName
-}
-
-func (pr *pkgReader) objDictIdx(idx pkgbits.Index) *readerDict {
- r := pr.newReader(pkgbits.RelocObjDict, idx, pkgbits.SyncObject1)
-
- var dict readerDict
-
- if implicits := r.Len(); implicits != 0 {
- errorf("unexpected object with %v implicit type parameter(s)", implicits)
- }
-
- dict.bounds = make([]typeInfo, r.Len())
- for i := range dict.bounds {
- dict.bounds[i] = r.typInfo()
- }
-
- dict.derived = make([]derivedInfo, r.Len())
- dict.derivedTypes = make([]types.Type, len(dict.derived))
- for i := range dict.derived {
- dict.derived[i] = derivedInfo{r.Reloc(pkgbits.RelocType), r.Bool()}
- }
-
- // function references follow, but reader doesn't need those
-
- return &dict
-}
-
-func (r *reader) typeParamNames() []*types.TypeParam {
- r.Sync(pkgbits.SyncTypeParamNames)
-
- // Note: This code assumes it only processes objects without
- // implement type parameters. This is currently fine, because
- // reader is only used to read in exported declarations, which are
- // always package scoped.
-
- if len(r.dict.bounds) == 0 {
- return nil
- }
-
- // Careful: Type parameter lists may have cycles. To allow for this,
- // we construct the type parameter list in two passes: first we
- // create all the TypeNames and TypeParams, then we construct and
- // set the bound type.
-
- r.dict.tparams = make([]*types.TypeParam, len(r.dict.bounds))
- for i := range r.dict.bounds {
- pos := r.pos()
- pkg, name := r.localIdent()
-
- tname := types.NewTypeName(pos, pkg, name, nil)
- r.dict.tparams[i] = types.NewTypeParam(tname, nil)
- }
-
- typs := make([]types.Type, len(r.dict.bounds))
- for i, bound := range r.dict.bounds {
- typs[i] = r.p.typIdx(bound, r.dict)
- }
-
- // TODO(mdempsky): This is subtle, elaborate further.
- //
- // We have to save tparams outside of the closure, because
- // typeParamNames() can be called multiple times with the same
- // dictionary instance.
- //
- // Also, this needs to happen later to make sure SetUnderlying has
- // been called.
- //
- // TODO(mdempsky): Is it safe to have a single "later" slice or do
- // we need to have multiple passes? See comments on CL 386002 and
- // go.dev/issue/52104.
- tparams := r.dict.tparams
- r.p.later(func() {
- for i, typ := range typs {
- tparams[i].SetConstraint(typ)
- }
- })
-
- return r.dict.tparams
-}
-
-func (r *reader) method() *types.Func {
- r.Sync(pkgbits.SyncMethod)
- pos := r.pos()
- pkg, name := r.selector()
-
- rparams := r.typeParamNames()
- sig := r.signature(r.param(), rparams, nil)
-
- _ = r.pos() // TODO(mdempsky): Remove; this is a hacker for linker.go.
- return types.NewFunc(pos, pkg, name, sig)
-}
-
-func (r *reader) qualifiedIdent() (*types.Package, string) { return r.ident(pkgbits.SyncSym) }
-func (r *reader) localIdent() (*types.Package, string) { return r.ident(pkgbits.SyncLocalIdent) }
-func (r *reader) selector() (*types.Package, string) { return r.ident(pkgbits.SyncSelector) }
-
-func (r *reader) ident(marker pkgbits.SyncMarker) (*types.Package, string) {
- r.Sync(marker)
- return r.pkg(), r.String()
-}
-
-// pkgScope returns pkg.Scope().
-// If pkg is nil, it returns types.Universe instead.
-//
-// TODO(mdempsky): Remove after x/tools can depend on Go 1.19.
-func pkgScope(pkg *types.Package) *types.Scope {
- if pkg != nil {
- return pkg.Scope()
- }
- return types.Universe
-}
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/codes.go b/vendor/golang.org/x/tools/go/internal/pkgbits/codes.go
deleted file mode 100644
index f0cabde9..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/codes.go
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package pkgbits
-
-// 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 returns the SyncMarker for the Code's dynamic type.
- Marker() SyncMarker
-
- // Value returns the Code's ordinal value.
- Value() int
-}
-
-// A CodeVal distinguishes among go/constant.Value encodings.
-type CodeVal int
-
-func (c CodeVal) Marker() SyncMarker { return SyncVal }
-func (c CodeVal) Value() int { return int(c) }
-
-// Note: These values are public and cannot be changed without
-// updating the go/types importers.
-
-const (
- ValBool CodeVal = iota
- ValString
- ValInt64
- ValBigInt
- ValBigRat
- ValBigFloat
-)
-
-// A CodeType distinguishes among go/types.Type encodings.
-type CodeType int
-
-func (c CodeType) Marker() SyncMarker { return SyncType }
-func (c CodeType) Value() int { return int(c) }
-
-// Note: These values are public and cannot be changed without
-// updating the go/types importers.
-
-const (
- TypeBasic CodeType = iota
- TypeNamed
- TypePointer
- TypeSlice
- TypeArray
- TypeChan
- TypeMap
- TypeSignature
- TypeStruct
- TypeInterface
- TypeUnion
- TypeTypeParam
-)
-
-// A CodeObj distinguishes among go/types.Object encodings.
-type CodeObj int
-
-func (c CodeObj) Marker() SyncMarker { return SyncCodeObj }
-func (c CodeObj) Value() int { return int(c) }
-
-// Note: These values are public and cannot be changed without
-// updating the go/types importers.
-
-const (
- ObjAlias CodeObj = iota
- ObjConst
- ObjType
- ObjFunc
- ObjVar
- ObjStub
-)
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/decoder.go b/vendor/golang.org/x/tools/go/internal/pkgbits/decoder.go
deleted file mode 100644
index 2bc79366..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/decoder.go
+++ /dev/null
@@ -1,433 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package pkgbits
-
-import (
- "encoding/binary"
- "fmt"
- "go/constant"
- "go/token"
- "math/big"
- "os"
- "runtime"
- "strings"
-)
-
-// A PkgDecoder provides methods for decoding a package's Unified IR
-// export data.
-type PkgDecoder struct {
- // version is the file format version.
- version uint32
-
- // sync indicates whether the file uses sync markers.
- sync bool
-
- // pkgPath is the package path for the package to be decoded.
- //
- // TODO(mdempsky): Remove; unneeded since CL 391014.
- pkgPath string
-
- // elemData is the full data payload of the encoded package.
- // Elements are densely and contiguously packed together.
- //
- // The last 8 bytes of elemData are the package fingerprint.
- elemData string
-
- // elemEnds stores the byte-offset end positions of element
- // bitstreams within elemData.
- //
- // For example, element I's bitstream data starts at elemEnds[I-1]
- // (or 0, if I==0) and ends at elemEnds[I].
- //
- // Note: elemEnds is indexed by absolute indices, not
- // section-relative indices.
- elemEnds []uint32
-
- // elemEndsEnds stores the index-offset end positions of relocation
- // sections within elemEnds.
- //
- // For example, section K's end positions start at elemEndsEnds[K-1]
- // (or 0, if K==0) and end at elemEndsEnds[K].
- elemEndsEnds [numRelocs]uint32
-}
-
-// PkgPath returns the package path for the package
-//
-// TODO(mdempsky): Remove; unneeded since CL 391014.
-func (pr *PkgDecoder) PkgPath() string { return pr.pkgPath }
-
-// SyncMarkers reports whether pr uses sync markers.
-func (pr *PkgDecoder) SyncMarkers() bool { return pr.sync }
-
-// 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.
-func NewPkgDecoder(pkgPath, input string) PkgDecoder {
- pr := PkgDecoder{
- pkgPath: pkgPath,
- }
-
- // TODO(mdempsky): Implement direct indexing of input string to
- // avoid copying the position information.
-
- r := strings.NewReader(input)
-
- assert(binary.Read(r, binary.LittleEndian, &pr.version) == nil)
-
- switch pr.version {
- default:
- panic(fmt.Errorf("unsupported version: %v", pr.version))
- case 0:
- // no flags
- case 1:
- var flags uint32
- assert(binary.Read(r, binary.LittleEndian, &flags) == nil)
- pr.sync = flags&flagSyncMarkers != 0
- }
-
- assert(binary.Read(r, binary.LittleEndian, pr.elemEndsEnds[:]) == nil)
-
- pr.elemEnds = make([]uint32, pr.elemEndsEnds[len(pr.elemEndsEnds)-1])
- assert(binary.Read(r, binary.LittleEndian, pr.elemEnds[:]) == nil)
-
- pos, err := r.Seek(0, os.SEEK_CUR)
- assert(err == nil)
-
- pr.elemData = input[pos:]
- assert(len(pr.elemData)-8 == int(pr.elemEnds[len(pr.elemEnds)-1]))
-
- return pr
-}
-
-// NumElems returns the number of elements in section k.
-func (pr *PkgDecoder) NumElems(k RelocKind) int {
- count := int(pr.elemEndsEnds[k])
- if k > 0 {
- count -= int(pr.elemEndsEnds[k-1])
- }
- return count
-}
-
-// TotalElems returns the total number of elements across all sections.
-func (pr *PkgDecoder) TotalElems() int {
- return len(pr.elemEnds)
-}
-
-// Fingerprint returns the package fingerprint.
-func (pr *PkgDecoder) Fingerprint() [8]byte {
- var fp [8]byte
- copy(fp[:], pr.elemData[len(pr.elemData)-8:])
- return fp
-}
-
-// AbsIdx returns the absolute index for the given (section, index)
-// pair.
-func (pr *PkgDecoder) AbsIdx(k RelocKind, idx Index) int {
- absIdx := int(idx)
- if k > 0 {
- absIdx += int(pr.elemEndsEnds[k-1])
- }
- if absIdx >= int(pr.elemEndsEnds[k]) {
- errorf("%v:%v is out of bounds; %v", k, idx, pr.elemEndsEnds)
- }
- return absIdx
-}
-
-// DataIdx returns the raw element bitstream for the given (section,
-// index) pair.
-func (pr *PkgDecoder) DataIdx(k RelocKind, idx Index) string {
- absIdx := pr.AbsIdx(k, idx)
-
- var start uint32
- if absIdx > 0 {
- start = pr.elemEnds[absIdx-1]
- }
- end := pr.elemEnds[absIdx]
-
- return pr.elemData[start:end]
-}
-
-// StringIdx returns the string value for the given string index.
-func (pr *PkgDecoder) StringIdx(idx Index) string {
- return pr.DataIdx(RelocString, idx)
-}
-
-// NewDecoder 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) Decoder {
- r := pr.NewDecoderRaw(k, idx)
- r.Sync(marker)
- return r
-}
-
-// NewDecoderRaw returns a Decoder for the given (section, index) pair.
-//
-// Most callers should use NewDecoder instead.
-func (pr *PkgDecoder) NewDecoderRaw(k RelocKind, idx Index) Decoder {
- r := Decoder{
- common: pr,
- k: k,
- Idx: idx,
- }
-
- // TODO(mdempsky) r.data.Reset(...) after #44505 is resolved.
- r.Data = *strings.NewReader(pr.DataIdx(k, idx))
-
- r.Sync(SyncRelocs)
- r.Relocs = make([]RelocEnt, r.Len())
- for i := range r.Relocs {
- r.Sync(SyncReloc)
- r.Relocs[i] = RelocEnt{RelocKind(r.Len()), Index(r.Len())}
- }
-
- return r
-}
-
-// 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
-}
-
-func (r *Decoder) checkErr(err error) {
- if err != nil {
- errorf("unexpected decoding error: %w", err)
- }
-}
-
-func (r *Decoder) rawUvarint() uint64 {
- x, err := binary.ReadUvarint(&r.Data)
- r.checkErr(err)
- return x
-}
-
-func (r *Decoder) rawVarint() int64 {
- ux := r.rawUvarint()
-
- // Zig-zag decode.
- x := int64(ux >> 1)
- if ux&1 != 0 {
- x = ^x
- }
- return x
-}
-
-func (r *Decoder) rawReloc(k RelocKind, idx int) Index {
- e := r.Relocs[idx]
- assert(e.Kind == k)
- return e.Idx
-}
-
-// Sync decodes a sync marker from the element bitstream and asserts
-// that it matches the expected marker.
-//
-// If r.common.sync is false, then Sync is a no-op.
-func (r *Decoder) Sync(mWant SyncMarker) {
- if !r.common.sync {
- return
- }
-
- pos, _ := r.Data.Seek(0, os.SEEK_CUR) // TODO(mdempsky): io.SeekCurrent after #44505 is resolved
- mHave := SyncMarker(r.rawUvarint())
- writerPCs := make([]int, r.rawUvarint())
- for i := range writerPCs {
- writerPCs[i] = int(r.rawUvarint())
- }
-
- if mHave == mWant {
- return
- }
-
- // There's some tension here between printing:
- //
- // (1) full file paths that tools can recognize (e.g., so emacs
- // hyperlinks the "file:line" text for easy navigation), or
- //
- // (2) short file paths that are easier for humans to read (e.g., by
- // omitting redundant or irrelevant details, so it's easier to
- // focus on the useful bits that remain).
- //
- // The current formatting favors the former, as it seems more
- // helpful in practice. But perhaps the formatting could be improved
- // to better address both concerns. For example, use relative file
- // paths if they would be shorter, or rewrite file paths to contain
- // "$GOROOT" (like objabi.AbsFile does) if tools can be taught how
- // to reliably expand that again.
-
- fmt.Printf("export data desync: package %q, section %v, index %v, offset %v\n", r.common.pkgPath, r.k, r.Idx, pos)
-
- fmt.Printf("\nfound %v, written at:\n", mHave)
- if len(writerPCs) == 0 {
- fmt.Printf("\t[stack trace unavailable; recompile package %q with -d=syncframes]\n", r.common.pkgPath)
- }
- for _, pc := range writerPCs {
- fmt.Printf("\t%s\n", r.common.StringIdx(r.rawReloc(RelocString, pc)))
- }
-
- fmt.Printf("\nexpected %v, reading at:\n", mWant)
- var readerPCs [32]uintptr // TODO(mdempsky): Dynamically size?
- n := runtime.Callers(2, readerPCs[:])
- for _, pc := range fmtFrames(readerPCs[:n]...) {
- fmt.Printf("\t%s\n", pc)
- }
-
- // We already printed a stack trace for the reader, so now we can
- // simply exit. Printing a second one with panic or base.Fatalf
- // would just be noise.
- os.Exit(1)
-}
-
-// Bool decodes and returns a bool value from the element bitstream.
-func (r *Decoder) Bool() bool {
- r.Sync(SyncBool)
- x, err := r.Data.ReadByte()
- r.checkErr(err)
- assert(x < 2)
- return x != 0
-}
-
-// Int64 decodes and returns an int64 value from the element bitstream.
-func (r *Decoder) Int64() int64 {
- r.Sync(SyncInt64)
- return r.rawVarint()
-}
-
-// Int64 decodes and returns a uint64 value from the element bitstream.
-func (r *Decoder) Uint64() uint64 {
- r.Sync(SyncUint64)
- return r.rawUvarint()
-}
-
-// Len decodes and returns a non-negative int value from the element bitstream.
-func (r *Decoder) Len() int { x := r.Uint64(); v := int(x); assert(uint64(v) == x); return v }
-
-// Int decodes and returns an int value from the element bitstream.
-func (r *Decoder) Int() int { x := r.Int64(); v := int(x); assert(int64(v) == x); return v }
-
-// Uint decodes and returns a uint value from the element bitstream.
-func (r *Decoder) Uint() uint { x := r.Uint64(); v := uint(x); assert(uint64(v) == x); return v }
-
-// 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) int {
- r.Sync(mark)
- return r.Len()
-}
-
-// 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) Index {
- r.Sync(SyncUseReloc)
- return r.rawReloc(k, r.Len())
-}
-
-// String decodes and returns a string value from the element
-// bitstream.
-func (r *Decoder) String() string {
- r.Sync(SyncString)
- return r.common.StringIdx(r.Reloc(RelocString))
-}
-
-// Strings decodes and returns a variable-length slice of strings from
-// the element bitstream.
-func (r *Decoder) Strings() []string {
- res := make([]string, r.Len())
- for i := range res {
- res[i] = r.String()
- }
- return res
-}
-
-// Value decodes and returns a constant.Value from the element
-// bitstream.
-func (r *Decoder) Value() constant.Value {
- r.Sync(SyncValue)
- isComplex := r.Bool()
- val := r.scalar()
- if isComplex {
- val = constant.BinaryOp(val, token.ADD, constant.MakeImag(r.scalar()))
- }
- return val
-}
-
-func (r *Decoder) scalar() constant.Value {
- switch tag := CodeVal(r.Code(SyncVal)); tag {
- default:
- panic(fmt.Errorf("unexpected scalar tag: %v", tag))
-
- case ValBool:
- return constant.MakeBool(r.Bool())
- case ValString:
- return constant.MakeString(r.String())
- case ValInt64:
- return constant.MakeInt64(r.Int64())
- case ValBigInt:
- return constant.Make(r.bigInt())
- case ValBigRat:
- num := r.bigInt()
- denom := r.bigInt()
- return constant.Make(new(big.Rat).SetFrac(num, denom))
- case ValBigFloat:
- return constant.Make(r.bigFloat())
- }
-}
-
-func (r *Decoder) bigInt() *big.Int {
- v := new(big.Int).SetBytes([]byte(r.String()))
- if r.Bool() {
- v.Neg(v)
- }
- return v
-}
-
-func (r *Decoder) bigFloat() *big.Float {
- v := new(big.Float).SetPrec(512)
- assert(v.UnmarshalText([]byte(r.String())) == nil)
- return v
-}
-
-// @@@ Helpers
-
-// TODO(mdempsky): These should probably be removed. I think they're a
-// smell that the export data format is not yet quite right.
-
-// PeekPkgPath returns the package path for the specified package
-// index.
-func (pr *PkgDecoder) PeekPkgPath(idx Index) string {
- r := pr.NewDecoder(RelocPkg, idx, SyncPkgDef)
- path := r.String()
- if path == "" {
- path = pr.pkgPath
- }
- return path
-}
-
-// PeekObj returns the package path, object name, and CodeObj for the
-// specified object index.
-func (pr *PkgDecoder) PeekObj(idx Index) (string, string, CodeObj) {
- r := pr.NewDecoder(RelocName, idx, SyncObject1)
- r.Sync(SyncSym)
- r.Sync(SyncPkg)
- path := pr.PeekPkgPath(r.Reloc(RelocPkg))
- name := r.String()
- assert(name != "")
-
- tag := CodeObj(r.Code(SyncCodeObj))
-
- return path, name, tag
-}
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/doc.go b/vendor/golang.org/x/tools/go/internal/pkgbits/doc.go
deleted file mode 100644
index c8a2796b..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/doc.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// 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).
-//
-// This is a copy of internal/pkgbits in the Go implementation.
-package pkgbits
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/encoder.go b/vendor/golang.org/x/tools/go/internal/pkgbits/encoder.go
deleted file mode 100644
index c50c838c..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/encoder.go
+++ /dev/null
@@ -1,379 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package pkgbits
-
-import (
- "bytes"
- "crypto/md5"
- "encoding/binary"
- "go/constant"
- "io"
- "math/big"
- "runtime"
-)
-
-// currentVersion is the current version number.
-//
-// - v0: initial prototype
-//
-// - v1: adds the flags uint32 word
-const currentVersion uint32 = 1
-
-// A PkgEncoder provides methods for encoding a package's Unified IR
-// export data.
-type PkgEncoder struct {
- // elems holds the bitstream for previously encoded elements.
- elems [numRelocs][]string
-
- // stringsIdx maps previously encoded strings to their index within
- // the RelocString section, to allow deduplication. That is,
- // elems[RelocString][stringsIdx[s]] == s (if present).
- stringsIdx map[string]Index
-
- // syncFrames is the number of frames to write at each sync
- // marker. A negative value means sync markers are omitted.
- syncFrames int
-}
-
-// SyncMarkers reports whether pw uses sync markers.
-func (pw *PkgEncoder) SyncMarkers() bool { return pw.syncFrames >= 0 }
-
-// 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.
-func NewPkgEncoder(syncFrames int) PkgEncoder {
- return PkgEncoder{
- stringsIdx: make(map[string]Index),
- syncFrames: syncFrames,
- }
-}
-
-// DumpTo writes the package's encoded data to out0 and returns the
-// package fingerprint.
-func (pw *PkgEncoder) DumpTo(out0 io.Writer) (fingerprint [8]byte) {
- h := md5.New()
- out := io.MultiWriter(out0, h)
-
- writeUint32 := func(x uint32) {
- assert(binary.Write(out, binary.LittleEndian, x) == nil)
- }
-
- writeUint32(currentVersion)
-
- var flags uint32
- if pw.SyncMarkers() {
- flags |= flagSyncMarkers
- }
- writeUint32(flags)
-
- // Write elemEndsEnds.
- var sum uint32
- for _, elems := range &pw.elems {
- sum += uint32(len(elems))
- writeUint32(sum)
- }
-
- // Write elemEnds.
- sum = 0
- for _, elems := range &pw.elems {
- for _, elem := range elems {
- sum += uint32(len(elem))
- writeUint32(sum)
- }
- }
-
- // Write elemData.
- for _, elems := range &pw.elems {
- for _, elem := range elems {
- _, err := io.WriteString(out, elem)
- assert(err == nil)
- }
- }
-
- // Write fingerprint.
- copy(fingerprint[:], h.Sum(nil))
- _, err := out0.Write(fingerprint[:])
- assert(err == nil)
-
- return
-}
-
-// StringIdx adds a string value to the strings section, if not
-// already present, and returns its index.
-func (pw *PkgEncoder) StringIdx(s string) Index {
- if idx, ok := pw.stringsIdx[s]; ok {
- assert(pw.elems[RelocString][idx] == s)
- return idx
- }
-
- idx := Index(len(pw.elems[RelocString]))
- pw.elems[RelocString] = append(pw.elems[RelocString], s)
- pw.stringsIdx[s] = idx
- return idx
-}
-
-// NewEncoder 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) Encoder {
- e := pw.NewEncoderRaw(k)
- e.Sync(marker)
- return e
-}
-
-// NewEncoderRaw returns an Encoder for a new element within the given
-// section.
-//
-// Most callers should use NewEncoder instead.
-func (pw *PkgEncoder) NewEncoderRaw(k RelocKind) Encoder {
- idx := Index(len(pw.elems[k]))
- pw.elems[k] = append(pw.elems[k], "") // placeholder
-
- return Encoder{
- p: pw,
- k: k,
- Idx: idx,
- }
-}
-
-// An Encoder provides methods for encoding an individual element's
-// bitstream data.
-type Encoder struct {
- p *PkgEncoder
-
- Relocs []RelocEnt
- Data bytes.Buffer // accumulated element bitstream data
-
- encodingRelocHeader bool
-
- k RelocKind
- Idx Index // index within relocation section
-}
-
-// Flush finalizes the element's bitstream and returns its Index.
-func (w *Encoder) Flush() Index {
- var sb bytes.Buffer // TODO(mdempsky): strings.Builder after #44505 is resolved
-
- // Backup the data so we write the relocations at the front.
- var tmp bytes.Buffer
- io.Copy(&tmp, &w.Data)
-
- // TODO(mdempsky): Consider writing these out separately so they're
- // easier to strip, along with function bodies, so that we can prune
- // down to just the data that's relevant to go/types.
- if w.encodingRelocHeader {
- panic("encodingRelocHeader already true; recursive flush?")
- }
- w.encodingRelocHeader = true
- w.Sync(SyncRelocs)
- w.Len(len(w.Relocs))
- for _, rEnt := range w.Relocs {
- w.Sync(SyncReloc)
- w.Len(int(rEnt.Kind))
- w.Len(int(rEnt.Idx))
- }
-
- io.Copy(&sb, &w.Data)
- io.Copy(&sb, &tmp)
- w.p.elems[w.k][w.Idx] = sb.String()
-
- return w.Idx
-}
-
-func (w *Encoder) checkErr(err error) {
- if err != nil {
- errorf("unexpected encoding error: %v", err)
- }
-}
-
-func (w *Encoder) rawUvarint(x uint64) {
- var buf [binary.MaxVarintLen64]byte
- n := binary.PutUvarint(buf[:], x)
- _, err := w.Data.Write(buf[:n])
- w.checkErr(err)
-}
-
-func (w *Encoder) rawVarint(x int64) {
- // Zig-zag encode.
- ux := uint64(x) << 1
- if x < 0 {
- ux = ^ux
- }
-
- w.rawUvarint(ux)
-}
-
-func (w *Encoder) rawReloc(r RelocKind, idx Index) int {
- // TODO(mdempsky): Use map for lookup; this takes quadratic time.
- for i, rEnt := range w.Relocs {
- if rEnt.Kind == r && rEnt.Idx == idx {
- return i
- }
- }
-
- i := len(w.Relocs)
- w.Relocs = append(w.Relocs, RelocEnt{r, idx})
- return i
-}
-
-func (w *Encoder) Sync(m SyncMarker) {
- if !w.p.SyncMarkers() {
- return
- }
-
- // Writing out stack frame string references requires working
- // relocations, but writing out the relocations themselves involves
- // sync markers. To prevent infinite recursion, we simply trim the
- // stack frame for sync markers within the relocation header.
- var frames []string
- if !w.encodingRelocHeader && w.p.syncFrames > 0 {
- pcs := make([]uintptr, w.p.syncFrames)
- n := runtime.Callers(2, pcs)
- frames = fmtFrames(pcs[:n]...)
- }
-
- // TODO(mdempsky): Save space by writing out stack frames as a
- // linked list so we can share common stack frames.
- w.rawUvarint(uint64(m))
- w.rawUvarint(uint64(len(frames)))
- for _, frame := range frames {
- w.rawUvarint(uint64(w.rawReloc(RelocString, w.p.StringIdx(frame))))
- }
-}
-
-// 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.
-func (w *Encoder) Bool(b bool) bool {
- w.Sync(SyncBool)
- var x byte
- if b {
- x = 1
- }
- err := w.Data.WriteByte(x)
- w.checkErr(err)
- return b
-}
-
-// Int64 encodes and writes an int64 value into the element bitstream.
-func (w *Encoder) Int64(x int64) {
- w.Sync(SyncInt64)
- w.rawVarint(x)
-}
-
-// Uint64 encodes and writes a uint64 value into the element bitstream.
-func (w *Encoder) Uint64(x uint64) {
- w.Sync(SyncUint64)
- w.rawUvarint(x)
-}
-
-// Len encodes and writes a non-negative int value into the element bitstream.
-func (w *Encoder) Len(x int) { assert(x >= 0); w.Uint64(uint64(x)) }
-
-// Int encodes and writes an int value into the element bitstream.
-func (w *Encoder) Int(x int) { w.Int64(int64(x)) }
-
-// Len encodes and writes a uint value into the element bitstream.
-func (w *Encoder) Uint(x uint) { w.Uint64(uint64(x)) }
-
-// 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.
-func (w *Encoder) Reloc(r RelocKind, idx Index) {
- w.Sync(SyncUseReloc)
- w.Len(w.rawReloc(r, idx))
-}
-
-// Code encodes and writes a Code value into the element bitstream.
-func (w *Encoder) Code(c Code) {
- w.Sync(c.Marker())
- w.Len(c.Value())
-}
-
-// 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) {
- w.Sync(SyncString)
- w.Reloc(RelocString, w.p.StringIdx(s))
-}
-
-// Strings encodes and writes a variable-length slice of strings into
-// the element bitstream.
-func (w *Encoder) Strings(ss []string) {
- w.Len(len(ss))
- for _, s := range ss {
- w.String(s)
- }
-}
-
-// Value encodes and writes a constant.Value into the element
-// bitstream.
-func (w *Encoder) Value(val constant.Value) {
- w.Sync(SyncValue)
- if w.Bool(val.Kind() == constant.Complex) {
- w.scalar(constant.Real(val))
- w.scalar(constant.Imag(val))
- } else {
- w.scalar(val)
- }
-}
-
-func (w *Encoder) scalar(val constant.Value) {
- switch v := constant.Val(val).(type) {
- default:
- errorf("unhandled %v (%v)", val, val.Kind())
- case bool:
- w.Code(ValBool)
- w.Bool(v)
- case string:
- w.Code(ValString)
- w.String(v)
- case int64:
- w.Code(ValInt64)
- w.Int64(v)
- case *big.Int:
- w.Code(ValBigInt)
- w.bigInt(v)
- case *big.Rat:
- w.Code(ValBigRat)
- w.bigInt(v.Num())
- w.bigInt(v.Denom())
- case *big.Float:
- w.Code(ValBigFloat)
- w.bigFloat(v)
- }
-}
-
-func (w *Encoder) bigInt(v *big.Int) {
- b := v.Bytes()
- w.String(string(b)) // TODO: More efficient encoding.
- w.Bool(v.Sign() < 0)
-}
-
-func (w *Encoder) bigFloat(v *big.Float) {
- b := v.Append(nil, 'p', -1)
- w.String(string(b)) // TODO: More efficient encoding.
-}
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/flags.go b/vendor/golang.org/x/tools/go/internal/pkgbits/flags.go
deleted file mode 100644
index 65422274..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/flags.go
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package pkgbits
-
-const (
- flagSyncMarkers = 1 << iota // file format contains sync markers
-)
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/frames_go1.go b/vendor/golang.org/x/tools/go/internal/pkgbits/frames_go1.go
deleted file mode 100644
index 5294f6a6..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/frames_go1.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build !go1.7
-// +build !go1.7
-
-// TODO(mdempsky): Remove after #44505 is resolved
-
-package pkgbits
-
-import "runtime"
-
-func walkFrames(pcs []uintptr, visit frameVisitor) {
- for _, pc := range pcs {
- fn := runtime.FuncForPC(pc)
- file, line := fn.FileLine(pc)
-
- visit(file, line, fn.Name(), pc-fn.Entry())
- }
-}
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/frames_go17.go b/vendor/golang.org/x/tools/go/internal/pkgbits/frames_go17.go
deleted file mode 100644
index 2324ae7a..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/frames_go17.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build go1.7
-// +build go1.7
-
-package pkgbits
-
-import "runtime"
-
-// walkFrames 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) {
- if len(pcs) == 0 {
- return
- }
-
- frames := runtime.CallersFrames(pcs)
- for {
- frame, more := frames.Next()
- visit(frame.File, frame.Line, frame.Function, frame.PC-frame.Entry)
- if !more {
- return
- }
- }
-}
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/reloc.go b/vendor/golang.org/x/tools/go/internal/pkgbits/reloc.go
deleted file mode 100644
index 7a8f04ab..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/reloc.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package pkgbits
-
-// A RelocKind indicates a particular section within a unified IR export.
-type RelocKind int
-
-// An Index represents a bitstream element index within a particular
-// section.
-type Index 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
-}
-
-// Reserved indices within the meta relocation section.
-const (
- PublicRootIdx Index = 0
- PrivateRootIdx Index = 1
-)
-
-const (
- RelocString RelocKind = iota
- RelocMeta
- RelocPosBase
- RelocPkg
- RelocName
- RelocType
- RelocObj
- RelocObjExt
- RelocObjDict
- RelocBody
-
- numRelocs = iota
-)
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/support.go b/vendor/golang.org/x/tools/go/internal/pkgbits/support.go
deleted file mode 100644
index ad26d3b2..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/support.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package pkgbits
-
-import "fmt"
-
-func assert(b bool) {
- if !b {
- panic("assertion failed")
- }
-}
-
-func errorf(format string, args ...interface{}) {
- panic(fmt.Errorf(format, args...))
-}
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/sync.go b/vendor/golang.org/x/tools/go/internal/pkgbits/sync.go
deleted file mode 100644
index 5bd51ef7..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/sync.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2021 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package pkgbits
-
-import (
- "fmt"
- "strings"
-)
-
-// fmtFrames formats a backtrace for reporting reader/writer desyncs.
-func fmtFrames(pcs ...uintptr) []string {
- res := make([]string, 0, len(pcs))
- walkFrames(pcs, func(file string, line int, name string, offset uintptr) {
- // Trim package from function name. It's just redundant noise.
- name = strings.TrimPrefix(name, "cmd/compile/internal/noder.")
-
- res = append(res, fmt.Sprintf("%s:%v: %s +0x%v", file, line, name, offset))
- })
- return res
-}
-
-type frameVisitor func(file string, line int, name string, offset uintptr)
-
-// SyncMarker is an enum type that represents markers that may be
-// written to export data to ensure the reader and writer stay
-// synchronized.
-type SyncMarker int
-
-//go:generate stringer -type=SyncMarker -trimprefix=Sync
-
-const (
- _ SyncMarker = iota
-
- // Public markers (known to go/types importers).
-
- // Low-level coding markers.
- SyncEOF
- SyncBool
- SyncInt64
- SyncUint64
- SyncString
- SyncValue
- SyncVal
- SyncRelocs
- SyncReloc
- SyncUseReloc
-
- // Higher-level object and type markers.
- SyncPublic
- SyncPos
- SyncPosBase
- SyncObject
- SyncObject1
- SyncPkg
- SyncPkgDef
- SyncMethod
- SyncType
- SyncTypeIdx
- SyncTypeParamNames
- SyncSignature
- SyncParams
- SyncParam
- SyncCodeObj
- SyncSym
- SyncLocalIdent
- SyncSelector
-
- // Private markers (only known to cmd/compile).
- SyncPrivate
-
- SyncFuncExt
- SyncVarExt
- SyncTypeExt
- SyncPragma
-
- SyncExprList
- SyncExprs
- SyncExpr
- SyncExprType
- SyncAssign
- SyncOp
- SyncFuncLit
- SyncCompLit
-
- SyncDecl
- SyncFuncBody
- SyncOpenScope
- SyncCloseScope
- SyncCloseAnotherScope
- SyncDeclNames
- SyncDeclName
-
- SyncStmts
- SyncBlockStmt
- SyncIfStmt
- SyncForStmt
- SyncSwitchStmt
- SyncRangeStmt
- SyncCaseClause
- SyncCommClause
- SyncSelectStmt
- SyncDecls
- SyncLabeledStmt
- SyncUseObjLocal
- SyncAddLocal
- SyncLinkname
- SyncStmt1
- SyncStmtsEnd
- SyncLabel
- SyncOptLabel
-)
diff --git a/vendor/golang.org/x/tools/go/internal/pkgbits/syncmarker_string.go b/vendor/golang.org/x/tools/go/internal/pkgbits/syncmarker_string.go
deleted file mode 100644
index 4a5b0ca5..00000000
--- a/vendor/golang.org/x/tools/go/internal/pkgbits/syncmarker_string.go
+++ /dev/null
@@ -1,89 +0,0 @@
-// Code generated by "stringer -type=SyncMarker -trimprefix=Sync"; DO NOT EDIT.
-
-package pkgbits
-
-import "strconv"
-
-func _() {
- // An "invalid array index" compiler error signifies that the constant values have changed.
- // Re-run the stringer command to generate them again.
- var x [1]struct{}
- _ = x[SyncEOF-1]
- _ = x[SyncBool-2]
- _ = x[SyncInt64-3]
- _ = x[SyncUint64-4]
- _ = x[SyncString-5]
- _ = x[SyncValue-6]
- _ = x[SyncVal-7]
- _ = x[SyncRelocs-8]
- _ = x[SyncReloc-9]
- _ = x[SyncUseReloc-10]
- _ = x[SyncPublic-11]
- _ = x[SyncPos-12]
- _ = x[SyncPosBase-13]
- _ = x[SyncObject-14]
- _ = x[SyncObject1-15]
- _ = x[SyncPkg-16]
- _ = x[SyncPkgDef-17]
- _ = x[SyncMethod-18]
- _ = x[SyncType-19]
- _ = x[SyncTypeIdx-20]
- _ = x[SyncTypeParamNames-21]
- _ = x[SyncSignature-22]
- _ = x[SyncParams-23]
- _ = x[SyncParam-24]
- _ = x[SyncCodeObj-25]
- _ = x[SyncSym-26]
- _ = x[SyncLocalIdent-27]
- _ = x[SyncSelector-28]
- _ = x[SyncPrivate-29]
- _ = x[SyncFuncExt-30]
- _ = x[SyncVarExt-31]
- _ = x[SyncTypeExt-32]
- _ = x[SyncPragma-33]
- _ = x[SyncExprList-34]
- _ = x[SyncExprs-35]
- _ = x[SyncExpr-36]
- _ = x[SyncExprType-37]
- _ = x[SyncAssign-38]
- _ = x[SyncOp-39]
- _ = x[SyncFuncLit-40]
- _ = x[SyncCompLit-41]
- _ = x[SyncDecl-42]
- _ = x[SyncFuncBody-43]
- _ = x[SyncOpenScope-44]
- _ = x[SyncCloseScope-45]
- _ = x[SyncCloseAnotherScope-46]
- _ = x[SyncDeclNames-47]
- _ = x[SyncDeclName-48]
- _ = x[SyncStmts-49]
- _ = x[SyncBlockStmt-50]
- _ = x[SyncIfStmt-51]
- _ = x[SyncForStmt-52]
- _ = x[SyncSwitchStmt-53]
- _ = x[SyncRangeStmt-54]
- _ = x[SyncCaseClause-55]
- _ = x[SyncCommClause-56]
- _ = x[SyncSelectStmt-57]
- _ = x[SyncDecls-58]
- _ = x[SyncLabeledStmt-59]
- _ = x[SyncUseObjLocal-60]
- _ = x[SyncAddLocal-61]
- _ = x[SyncLinkname-62]
- _ = x[SyncStmt1-63]
- _ = x[SyncStmtsEnd-64]
- _ = x[SyncLabel-65]
- _ = x[SyncOptLabel-66]
-}
-
-const _SyncMarker_name = "EOFBoolInt64Uint64StringValueValRelocsRelocUseRelocPublicPosPosBaseObjectObject1PkgPkgDefMethodTypeTypeIdxTypeParamNamesSignatureParamsParamCodeObjSymLocalIdentSelectorPrivateFuncExtVarExtTypeExtPragmaExprListExprsExprExprTypeAssignOpFuncLitCompLitDeclFuncBodyOpenScopeCloseScopeCloseAnotherScopeDeclNamesDeclNameStmtsBlockStmtIfStmtForStmtSwitchStmtRangeStmtCaseClauseCommClauseSelectStmtDeclsLabeledStmtUseObjLocalAddLocalLinknameStmt1StmtsEndLabelOptLabel"
-
-var _SyncMarker_index = [...]uint16{0, 3, 7, 12, 18, 24, 29, 32, 38, 43, 51, 57, 60, 67, 73, 80, 83, 89, 95, 99, 106, 120, 129, 135, 140, 147, 150, 160, 168, 175, 182, 188, 195, 201, 209, 214, 218, 226, 232, 234, 241, 248, 252, 260, 269, 279, 296, 305, 313, 318, 327, 333, 340, 350, 359, 369, 379, 389, 394, 405, 416, 424, 432, 437, 445, 450, 458}
-
-func (i SyncMarker) String() string {
- i -= 1
- if i < 0 || i >= SyncMarker(len(_SyncMarker_index)-1) {
- return "SyncMarker(" + strconv.FormatInt(int64(i+1), 10) + ")"
- }
- return _SyncMarker_name[_SyncMarker_index[i]:_SyncMarker_index[i+1]]
-}
diff --git a/vendor/golang.org/x/tools/go/packages/golist.go b/vendor/golang.org/x/tools/go/packages/golist.go
index de881562..6bb7168d 100644
--- a/vendor/golang.org/x/tools/go/packages/golist.go
+++ b/vendor/golang.org/x/tools/go/packages/golist.go
@@ -60,6 +60,7 @@ func (r *responseDeduper) addAll(dr *driverResponse) {
for _, root := range dr.Roots {
r.addRoot(root)
}
+ r.dr.GoVersion = dr.GoVersion
}
func (r *responseDeduper) addPackage(p *Package) {
@@ -454,11 +455,14 @@ func (state *golistState) createDriverResponse(words ...string) (*driverResponse
if err != nil {
return nil, err
}
+
seen := make(map[string]*jsonPackage)
pkgs := make(map[string]*Package)
additionalErrors := make(map[string][]Error)
// Decode the JSON and convert it to Package form.
- var response driverResponse
+ response := &driverResponse{
+ GoVersion: goVersion,
+ }
for dec := json.NewDecoder(buf); dec.More(); {
p := new(jsonPackage)
if err := dec.Decode(p); err != nil {
@@ -600,17 +604,12 @@ func (state *golistState) createDriverResponse(words ...string) (*driverResponse
// Work around https://golang.org/issue/28749:
// cmd/go puts assembly, C, and C++ files in CompiledGoFiles.
- // Filter out any elements of CompiledGoFiles that are also in OtherFiles.
- // We have to keep this workaround in place until go1.12 is a distant memory.
- if len(pkg.OtherFiles) > 0 {
- other := make(map[string]bool, len(pkg.OtherFiles))
- for _, f := range pkg.OtherFiles {
- other[f] = true
- }
-
+ // Remove files from CompiledGoFiles that are non-go files
+ // (or are not files that look like they are from the cache).
+ if len(pkg.CompiledGoFiles) > 0 {
out := pkg.CompiledGoFiles[:0]
for _, f := range pkg.CompiledGoFiles {
- if other[f] {
+ if ext := filepath.Ext(f); ext != ".go" && ext != "" { // ext == "" means the file is from the cache, so probably cgo-processed file
continue
}
out = append(out, f)
@@ -730,7 +729,7 @@ func (state *golistState) createDriverResponse(words ...string) (*driverResponse
}
sort.Slice(response.Packages, func(i, j int) bool { return response.Packages[i].ID < response.Packages[j].ID })
- return &response, nil
+ return response, nil
}
func (state *golistState) shouldAddFilenameFromError(p *jsonPackage) bool {
@@ -756,6 +755,7 @@ func (state *golistState) shouldAddFilenameFromError(p *jsonPackage) bool {
return len(p.Error.ImportStack) == 0 || p.Error.ImportStack[len(p.Error.ImportStack)-1] == p.ImportPath
}
+// getGoVersion returns the effective minor version of the go command.
func (state *golistState) getGoVersion() (int, error) {
state.goVersionOnce.Do(func() {
state.goVersion, state.goVersionError = gocommand.GoVersion(state.ctx, state.cfgInvocation(), state.cfg.gocmdRunner)
diff --git a/vendor/golang.org/x/tools/go/packages/packages.go b/vendor/golang.org/x/tools/go/packages/packages.go
index a93dc6ad..0f1505b8 100644
--- a/vendor/golang.org/x/tools/go/packages/packages.go
+++ b/vendor/golang.org/x/tools/go/packages/packages.go
@@ -15,10 +15,12 @@ import (
"go/scanner"
"go/token"
"go/types"
+ "io"
"io/ioutil"
"log"
"os"
"path/filepath"
+ "runtime"
"strings"
"sync"
"time"
@@ -233,6 +235,11 @@ type driverResponse struct {
// Imports will be connected and then type and syntax information added in a
// later pass (see refine).
Packages []*Package
+
+ // GoVersion is the minor version number used by the driver
+ // (e.g. the go command on the PATH) when selecting .go files.
+ // Zero means unknown.
+ GoVersion int
}
// Load loads and returns the Go packages named by the given patterns.
@@ -256,7 +263,7 @@ func Load(cfg *Config, patterns ...string) ([]*Package, error) {
return nil, err
}
l.sizes = response.Sizes
- return l.refine(response.Roots, response.Packages...)
+ return l.refine(response)
}
// defaultDriver is a driver that implements go/packages' fallback behavior.
@@ -297,6 +304,9 @@ type Package struct {
// of the package, or while parsing or type-checking its files.
Errors []Error
+ // TypeErrors contains the subset of errors produced during type checking.
+ TypeErrors []types.Error
+
// GoFiles lists the absolute file paths of the package's Go source files.
GoFiles []string
@@ -532,6 +542,7 @@ type loaderPackage struct {
needsrc bool // load from source (Mode >= LoadTypes)
needtypes bool // type information is either requested or depended on
initial bool // package was matched by a pattern
+ goVersion int // minor version number of go command on PATH
}
// loader holds the working state of a single call to load.
@@ -618,7 +629,8 @@ func newLoader(cfg *Config) *loader {
// refine connects the supplied packages into a graph and then adds type and
// and syntax information as requested by the LoadMode.
-func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
+func (ld *loader) refine(response *driverResponse) ([]*Package, error) {
+ roots := response.Roots
rootMap := make(map[string]int, len(roots))
for i, root := range roots {
rootMap[root] = i
@@ -626,7 +638,7 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
ld.pkgs = make(map[string]*loaderPackage)
// first pass, fixup and build the map and roots
var initial = make([]*loaderPackage, len(roots))
- for _, pkg := range list {
+ for _, pkg := range response.Packages {
rootIndex := -1
if i, found := rootMap[pkg.ID]; found {
rootIndex = i
@@ -648,6 +660,7 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
Package: pkg,
needtypes: needtypes,
needsrc: needsrc,
+ goVersion: response.GoVersion,
}
ld.pkgs[lpkg.ID] = lpkg
if rootIndex >= 0 {
@@ -865,12 +878,19 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
// never has to create a types.Package for an indirect dependency,
// which would then require that such created packages be explicitly
// inserted back into the Import graph as a final step after export data loading.
+ // (Hence this return is after the Types assignment.)
// The Diamond test exercises this case.
if !lpkg.needtypes && !lpkg.needsrc {
return
}
if !lpkg.needsrc {
- ld.loadFromExportData(lpkg)
+ if err := ld.loadFromExportData(lpkg); err != nil {
+ lpkg.Errors = append(lpkg.Errors, Error{
+ Pos: "-",
+ Msg: err.Error(),
+ Kind: UnknownError, // e.g. can't find/open/parse export data
+ })
+ }
return // not a source package, don't get syntax trees
}
@@ -902,6 +922,7 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
case types.Error:
// from type checker
+ lpkg.TypeErrors = append(lpkg.TypeErrors, err)
errs = append(errs, Error{
Pos: err.Fset.Position(err.Pos).String(),
Msg: err.Msg,
@@ -923,11 +944,41 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
lpkg.Errors = append(lpkg.Errors, errs...)
}
+ // If the go command on the PATH is newer than the runtime,
+ // then the go/{scanner,ast,parser,types} packages from the
+ // standard library may be unable to process the files
+ // selected by go list.
+ //
+ // There is currently no way to downgrade the effective
+ // version of the go command (see issue 52078), so we proceed
+ // with the newer go command but, in case of parse or type
+ // errors, we emit an additional diagnostic.
+ //
+ // See:
+ // - golang.org/issue/52078 (flag to set release tags)
+ // - golang.org/issue/50825 (gopls legacy version support)
+ // - golang.org/issue/55883 (go/packages confusing error)
+ //
+ // Should we assert a hard minimum of (currently) go1.16 here?
+ var runtimeVersion int
+ if _, err := fmt.Sscanf(runtime.Version(), "go1.%d", &runtimeVersion); err == nil && runtimeVersion < lpkg.goVersion {
+ defer func() {
+ if len(lpkg.Errors) > 0 {
+ appendError(Error{
+ Pos: "-",
+ Msg: fmt.Sprintf("This application uses version go1.%d of the source-processing packages but runs version go1.%d of 'go list'. It may fail to process source files that rely on newer language features. If so, rebuild the application using a newer version of Go.", runtimeVersion, lpkg.goVersion),
+ Kind: UnknownError,
+ })
+ }
+ }()
+ }
+
if ld.Config.Mode&NeedTypes != 0 && len(lpkg.CompiledGoFiles) == 0 && lpkg.ExportFile != "" {
// The config requested loading sources and types, but sources are missing.
// Add an error to the package and fall back to loading from export data.
appendError(Error{"-", fmt.Sprintf("sources missing for package %s", lpkg.ID), ParseError})
- ld.loadFromExportData(lpkg)
+ _ = ld.loadFromExportData(lpkg) // ignore any secondary errors
+
return // can't get syntax trees for this package
}
@@ -981,7 +1032,7 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
tc := &types.Config{
Importer: importer,
- // Type-check bodies of functions only in non-initial packages.
+ // Type-check bodies of functions only in initial packages.
// Example: for import graph A->B->C and initial packages {A,C},
// we can ignore function bodies in B.
IgnoreFuncBodies: ld.Mode&NeedDeps == 0 && !lpkg.initial,
@@ -1151,9 +1202,10 @@ func sameFile(x, y string) bool {
return false
}
-// loadFromExportData returns type information for the specified
+// loadFromExportData ensures that type information is present for the specified
// package, loading it from an export data file on the first request.
-func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error) {
+// On success it sets lpkg.Types to a new Package.
+func (ld *loader) loadFromExportData(lpkg *loaderPackage) error {
if lpkg.PkgPath == "" {
log.Fatalf("internal error: Package %s has no PkgPath", lpkg)
}
@@ -1164,8 +1216,8 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
// must be sequential. (Finer-grained locking would require
// changes to the gcexportdata API.)
//
- // The exportMu lock guards the Package.Pkg field and the
- // types.Package it points to, for each Package in the graph.
+ // The exportMu lock guards the lpkg.Types field and the
+ // types.Package it points to, for each loaderPackage in the graph.
//
// Not all accesses to Package.Pkg need to be protected by exportMu:
// graph ordering ensures that direct dependencies of source
@@ -1174,18 +1226,18 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
defer ld.exportMu.Unlock()
if tpkg := lpkg.Types; tpkg != nil && tpkg.Complete() {
- return tpkg, nil // cache hit
+ return nil // cache hit
}
lpkg.IllTyped = true // fail safe
if lpkg.ExportFile == "" {
// Errors while building export data will have been printed to stderr.
- return nil, fmt.Errorf("no export data file")
+ return fmt.Errorf("no export data file")
}
f, err := os.Open(lpkg.ExportFile)
if err != nil {
- return nil, err
+ return err
}
defer f.Close()
@@ -1197,7 +1249,7 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
// queries.)
r, err := gcexportdata.NewReader(f)
if err != nil {
- return nil, fmt.Errorf("reading %s: %v", lpkg.ExportFile, err)
+ return fmt.Errorf("reading %s: %v", lpkg.ExportFile, err)
}
// Build the view.
@@ -1241,7 +1293,7 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
// (May modify incomplete packages in view but not create new ones.)
tpkg, err := gcexportdata.Read(r, ld.Fset, view, lpkg.PkgPath)
if err != nil {
- return nil, fmt.Errorf("reading %s: %v", lpkg.ExportFile, err)
+ return fmt.Errorf("reading %s: %v", lpkg.ExportFile, err)
}
if _, ok := view["go.shape"]; ok {
// Account for the pseudopackage "go.shape" that gets
@@ -1254,8 +1306,7 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
lpkg.Types = tpkg
lpkg.IllTyped = false
-
- return tpkg, nil
+ return nil
}
// impliedLoadMode returns loadMode with its dependencies.
@@ -1271,3 +1322,5 @@ func impliedLoadMode(loadMode LoadMode) LoadMode {
func usesExportData(cfg *Config) bool {
return cfg.Mode&NeedExportFile != 0 || cfg.Mode&NeedTypes != 0 && cfg.Mode&NeedDeps == 0
}
+
+var _ interface{} = io.Discard // assert build toolchain is go1.16 or later