mirror of
https://github.com/golang/go
synced 2024-11-18 19:24:39 -07:00
go/gcimporter15: match recent changes to export format
This is a copy&paste fix of the changes in golang.org/cl/22839. Fixes https://github.com/golang/lint/issues/207 . Change-Id: I2c4850395c8aa330ea27ad629b21ac21b973ef75 Reviewed-on: https://go-review.googlesource.com/22963 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
3f1f7eeff1
commit
fbb6674a74
@ -42,6 +42,17 @@ const trace = false // default: false
|
||||
|
||||
const exportVersion = "v0"
|
||||
|
||||
// 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
|
||||
@ -79,6 +90,12 @@ func BExportData(fset *token.FileSet, pkg *types.Package) []byte {
|
||||
}
|
||||
p.rawByte(format)
|
||||
|
||||
format = 'n' // track named types only
|
||||
if trackAllTypes {
|
||||
format = 'a'
|
||||
}
|
||||
p.rawByte(format)
|
||||
|
||||
// posInfo exported or not?
|
||||
p.bool(p.posInfoFormat)
|
||||
|
||||
@ -283,15 +300,21 @@ func (p *exporter) typ(t types.Type) {
|
||||
}
|
||||
|
||||
// otherwise, remember the type, write the type tag (< 0) and type data
|
||||
index := len(p.typIndex)
|
||||
if trackAllTypes {
|
||||
if trace {
|
||||
p.tracef("T%d = {>\n", index)
|
||||
p.tracef("T%d = {>\n", len(p.typIndex))
|
||||
defer p.tracef("<\n} ")
|
||||
}
|
||||
p.typIndex[t] = index
|
||||
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())
|
||||
|
@ -31,6 +31,7 @@ type importer struct {
|
||||
strList []string // in order of appearance
|
||||
pkgList []*types.Package // in order of appearance
|
||||
typList []types.Type // in order of appearance
|
||||
trackAllTypes bool
|
||||
|
||||
// position encoding
|
||||
posInfoFormat bool
|
||||
@ -68,6 +69,8 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
|
||||
return p.read, nil, fmt.Errorf("invalid encoding format in export data: got %q; want 'c' or 'd'", format)
|
||||
}
|
||||
|
||||
p.trackAllTypes = p.rawByte() == 'a'
|
||||
|
||||
p.posInfoFormat = p.int() != 0
|
||||
|
||||
// --- generic export data ---
|
||||
@ -102,7 +105,12 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
|
||||
|
||||
// complete interfaces
|
||||
for _, typ := range p.typList {
|
||||
if it, ok := typ.(*types.Interface); ok {
|
||||
// If we only record named types (!p.trackAllTypes),
|
||||
// we must check the underlying types here. If we
|
||||
// track all types, the Underlying() method call is
|
||||
// not needed.
|
||||
// TODO(gri) Remove if p.trackAllTypes is gone.
|
||||
if it, ok := typ.Underlying().(*types.Interface); ok {
|
||||
it.Complete()
|
||||
}
|
||||
}
|
||||
@ -344,7 +352,9 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||
|
||||
case arrayTag:
|
||||
t := new(types.Array)
|
||||
if p.trackAllTypes {
|
||||
p.record(t)
|
||||
}
|
||||
|
||||
n := p.int64()
|
||||
*t = *types.NewArray(p.typ(parent), n)
|
||||
@ -352,35 +362,45 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||
|
||||
case sliceTag:
|
||||
t := new(types.Slice)
|
||||
if p.trackAllTypes {
|
||||
p.record(t)
|
||||
}
|
||||
|
||||
*t = *types.NewSlice(p.typ(parent))
|
||||
return t
|
||||
|
||||
case dddTag:
|
||||
t := new(dddSlice)
|
||||
if p.trackAllTypes {
|
||||
p.record(t)
|
||||
}
|
||||
|
||||
t.elem = p.typ(parent)
|
||||
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))
|
||||
return t
|
||||
|
||||
case signatureTag:
|
||||
t := new(types.Signature)
|
||||
if p.trackAllTypes {
|
||||
p.record(t)
|
||||
}
|
||||
|
||||
params, isddd := p.paramList()
|
||||
result, _ := p.paramList()
|
||||
@ -393,7 +413,9 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||
// such cycle must contain a named type which would have been
|
||||
// first defined earlier.
|
||||
n := len(p.typList)
|
||||
if p.trackAllTypes {
|
||||
p.record(nil)
|
||||
}
|
||||
|
||||
// no embedded interfaces with gc compiler
|
||||
if p.int() != 0 {
|
||||
@ -401,12 +423,16 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||
}
|
||||
|
||||
t := types.NewInterface(p.methodList(parent), nil)
|
||||
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)
|
||||
val := p.typ(parent)
|
||||
@ -415,7 +441,9 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||
|
||||
case chanTag:
|
||||
t := new(types.Chan)
|
||||
if p.trackAllTypes {
|
||||
p.record(t)
|
||||
}
|
||||
|
||||
var dir types.ChanDir
|
||||
// tag values must match the constants in cmd/compile/internal/gc/go.go
|
||||
|
Loading…
Reference in New Issue
Block a user