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"
|
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 {
|
type exporter struct {
|
||||||
fset *token.FileSet
|
fset *token.FileSet
|
||||||
out bytes.Buffer
|
out bytes.Buffer
|
||||||
|
@ -79,6 +90,12 @@ func BExportData(fset *token.FileSet, pkg *types.Package) []byte {
|
||||||
}
|
}
|
||||||
p.rawByte(format)
|
p.rawByte(format)
|
||||||
|
|
||||||
|
format = 'n' // track named types only
|
||||||
|
if trackAllTypes {
|
||||||
|
format = 'a'
|
||||||
|
}
|
||||||
|
p.rawByte(format)
|
||||||
|
|
||||||
// posInfo exported or not?
|
// posInfo exported or not?
|
||||||
p.bool(p.posInfoFormat)
|
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
|
// otherwise, remember the type, write the type tag (< 0) and type data
|
||||||
index := len(p.typIndex)
|
if trackAllTypes {
|
||||||
if trace {
|
if trace {
|
||||||
p.tracef("T%d = {>\n", index)
|
p.tracef("T%d = {>\n", len(p.typIndex))
|
||||||
defer p.tracef("<\n} ")
|
defer p.tracef("<\n} ")
|
||||||
|
}
|
||||||
|
p.typIndex[t] = len(p.typIndex)
|
||||||
}
|
}
|
||||||
p.typIndex[t] = index
|
|
||||||
|
|
||||||
switch t := t.(type) {
|
switch t := t.(type) {
|
||||||
case *types.Named:
|
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.tag(namedTag)
|
||||||
p.pos(t.Obj())
|
p.pos(t.Obj())
|
||||||
p.qualifiedName(t.Obj())
|
p.qualifiedName(t.Obj())
|
||||||
|
|
|
@ -28,9 +28,10 @@ type importer struct {
|
||||||
buf []byte // for reading strings
|
buf []byte // for reading strings
|
||||||
|
|
||||||
// object lists
|
// object lists
|
||||||
strList []string // in order of appearance
|
strList []string // in order of appearance
|
||||||
pkgList []*types.Package // in order of appearance
|
pkgList []*types.Package // in order of appearance
|
||||||
typList []types.Type // in order of appearance
|
typList []types.Type // in order of appearance
|
||||||
|
trackAllTypes bool
|
||||||
|
|
||||||
// position encoding
|
// position encoding
|
||||||
posInfoFormat bool
|
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)
|
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
|
p.posInfoFormat = p.int() != 0
|
||||||
|
|
||||||
// --- generic export data ---
|
// --- generic export data ---
|
||||||
|
@ -102,7 +105,12 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
|
||||||
|
|
||||||
// complete interfaces
|
// complete interfaces
|
||||||
for _, typ := range p.typList {
|
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()
|
it.Complete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,7 +352,9 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||||
|
|
||||||
case arrayTag:
|
case arrayTag:
|
||||||
t := new(types.Array)
|
t := new(types.Array)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
n := p.int64()
|
n := p.int64()
|
||||||
*t = *types.NewArray(p.typ(parent), n)
|
*t = *types.NewArray(p.typ(parent), n)
|
||||||
|
@ -352,35 +362,45 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||||
|
|
||||||
case sliceTag:
|
case sliceTag:
|
||||||
t := new(types.Slice)
|
t := new(types.Slice)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
*t = *types.NewSlice(p.typ(parent))
|
*t = *types.NewSlice(p.typ(parent))
|
||||||
return t
|
return t
|
||||||
|
|
||||||
case dddTag:
|
case dddTag:
|
||||||
t := new(dddSlice)
|
t := new(dddSlice)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
t.elem = p.typ(parent)
|
t.elem = p.typ(parent)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
case structTag:
|
case structTag:
|
||||||
t := new(types.Struct)
|
t := new(types.Struct)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
*t = *types.NewStruct(p.fieldList(parent))
|
*t = *types.NewStruct(p.fieldList(parent))
|
||||||
return t
|
return t
|
||||||
|
|
||||||
case pointerTag:
|
case pointerTag:
|
||||||
t := new(types.Pointer)
|
t := new(types.Pointer)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
*t = *types.NewPointer(p.typ(parent))
|
*t = *types.NewPointer(p.typ(parent))
|
||||||
return t
|
return t
|
||||||
|
|
||||||
case signatureTag:
|
case signatureTag:
|
||||||
t := new(types.Signature)
|
t := new(types.Signature)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
params, isddd := p.paramList()
|
params, isddd := p.paramList()
|
||||||
result, _ := 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
|
// such cycle must contain a named type which would have been
|
||||||
// first defined earlier.
|
// first defined earlier.
|
||||||
n := len(p.typList)
|
n := len(p.typList)
|
||||||
p.record(nil)
|
if p.trackAllTypes {
|
||||||
|
p.record(nil)
|
||||||
|
}
|
||||||
|
|
||||||
// no embedded interfaces with gc compiler
|
// no embedded interfaces with gc compiler
|
||||||
if p.int() != 0 {
|
if p.int() != 0 {
|
||||||
|
@ -401,12 +423,16 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
t := types.NewInterface(p.methodList(parent), nil)
|
t := types.NewInterface(p.methodList(parent), nil)
|
||||||
p.typList[n] = t
|
if p.trackAllTypes {
|
||||||
|
p.typList[n] = t
|
||||||
|
}
|
||||||
return t
|
return t
|
||||||
|
|
||||||
case mapTag:
|
case mapTag:
|
||||||
t := new(types.Map)
|
t := new(types.Map)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
key := p.typ(parent)
|
key := p.typ(parent)
|
||||||
val := p.typ(parent)
|
val := p.typ(parent)
|
||||||
|
@ -415,7 +441,9 @@ func (p *importer) typ(parent *types.Package) types.Type {
|
||||||
|
|
||||||
case chanTag:
|
case chanTag:
|
||||||
t := new(types.Chan)
|
t := new(types.Chan)
|
||||||
p.record(t)
|
if p.trackAllTypes {
|
||||||
|
p.record(t)
|
||||||
|
}
|
||||||
|
|
||||||
var dir types.ChanDir
|
var dir types.ChanDir
|
||||||
// tag values must match the constants in cmd/compile/internal/gc/go.go
|
// tag values must match the constants in cmd/compile/internal/gc/go.go
|
||||||
|
|
Loading…
Reference in New Issue