From 5da1e91fb2cc877989e7c73748b505a0612956f2 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 12 Apr 2016 22:06:59 -0700 Subject: [PATCH] go/gcimporter15: match https://golang.org/cl/21939/ Plus cleanups from https://golang.org/cl/21963/. Change-Id: Ifb216081581950f38d73bcb5f22e2ca7acd64f01 Reviewed-on: https://go-review.googlesource.com/21965 Reviewed-by: Alan Donovan --- go/gcimporter15/bexport.go | 2 -- go/gcimporter15/bimport.go | 48 +++++++++++++++----------------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/go/gcimporter15/bexport.go b/go/gcimporter15/bexport.go index 22bad6d2..7bdffe4e 100644 --- a/go/gcimporter15/bexport.go +++ b/go/gcimporter15/bexport.go @@ -177,7 +177,6 @@ func (p *exporter) obj(obj types.Object) { sig := obj.Type().(*types.Signature) p.paramList(sig.Params(), sig.Variadic()) p.paramList(sig.Results(), false) - p.int(-1) // no inlined function bodies default: log.Fatalf("gcimporter: unexpected object %v (%T)", obj, obj) @@ -300,7 +299,6 @@ func (p *exporter) assocMethods(named *types.Named) { p.paramList(types.NewTuple(sig.Recv()), false) p.paramList(sig.Params(), sig.Variadic()) p.paramList(sig.Results(), false) - p.int(-1) // no inlining } if trace && methods != nil { diff --git a/go/gcimporter15/bimport.go b/go/gcimporter15/bimport.go index ec429cff..31c34bc9 100644 --- a/go/gcimporter15/bimport.go +++ b/go/gcimporter15/bimport.go @@ -20,12 +20,15 @@ import ( ) type importer struct { - imports map[string]*types.Package - data []byte + imports map[string]*types.Package + data []byte + path string + buf []byte // for reading strings bufarray [64]byte // initial underlying array for buf, large enough to avoid allocation when compiling std lib - pkgList []*types.Package - typList []types.Type + + pkgList []*types.Package + typList []types.Type debugFormat bool read int // bytes read @@ -39,6 +42,7 @@ func BImportData(imports map[string]*types.Package, data []byte, path string) (i p := importer{ imports: imports, data: data, + path: path, } p.buf = p.bufarray[:] @@ -62,25 +66,7 @@ func BImportData(imports map[string]*types.Package, data []byte, path string) (i p.typList = append(p.typList, predeclared...) // read package data - // TODO(gri) clean this up - i := p.tagOrIndex() - if i != packageTag { - panic(fmt.Sprintf("package tag expected, got %d", i)) - } - name := p.string() - if s := p.string(); s != "" { - panic(fmt.Sprintf("empty path expected, got %s", s)) - } - pkg := p.imports[path] - if pkg == nil { - pkg = types.NewPackage(path, name) - p.imports[path] = pkg - } - p.pkgList = append(p.pkgList, pkg) - - if debug && p.pkgList[0] != pkg { - panic("imported packaged not found in pkgList[0]") - } + pkg := p.pkg() // read objects of phase 1 only (see cmd/compiler/internal/gc/bexport.go) objcount := 0 @@ -95,7 +81,7 @@ func BImportData(imports map[string]*types.Package, data []byte, path string) (i // self-verification if count := p.int(); count != objcount { - panic(fmt.Sprintf("importer: got %d objects; want %d", objcount, count)) + panic(fmt.Sprintf("got %d objects; want %d", objcount, count)) } // ignore compiler-specific import data @@ -139,16 +125,22 @@ func (p *importer) pkg() *types.Package { panic("empty package name in import") } - // we should never see an empty import path - if path == "" { - panic("empty import path") + // an empty path denotes the package we are currently importing; + // it must be the first package we see + if (path == "") != (len(p.pkgList) == 0) { + panic(fmt.Sprintf("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.path + } pkg := p.imports[path] if pkg == nil { pkg = types.NewPackage(path, name) p.imports[path] = pkg + } else if pkg.Name() != name { + panic(fmt.Sprintf("conflicting names %s and %s for package %q", pkg.Name(), name, path)) } p.pkgList = append(p.pkgList, pkg) @@ -190,7 +182,6 @@ func (p *importer) obj(tag int) { params, isddd := p.paramList() result, _ := p.paramList() sig := types.NewSignature(nil, params, result, isddd) - p.int() // read and discard index of inlined function body p.declare(types.NewFunc(token.NoPos, pkg, name, sig)) default: @@ -273,7 +264,6 @@ func (p *importer) typ(parent *types.Package) types.Type { recv, _ := p.paramList() // TODO(gri) do we need a full param list for the receiver? params, isddd := p.paramList() result, _ := p.paramList() - p.int() // read and discard index of inlined function body sig := types.NewSignature(recv.At(0), params, result, isddd) t0.AddMethod(types.NewFunc(token.NoPos, parent, name, sig))