[PATCH] [llgo] llgoi: Fix type identity for imported binary packages.

Peter Collingbourne peter at pcc.me.uk
Wed Mar 18 00:40:08 PDT 2015


Hi axw,

go/loader creates a fresh package map for each source package it imports. In
llgoi this caused binary imported packages to be imported anew for every
input line, resulting in spurious type errors and panics in go/ssa when
encountering previously imported types. Fix this by ignoring the provided
package map completely in the importer wrapper and using our own.

http://reviews.llvm.org/D8409

Files:
  cmd/llgoi/llgoi.go
  test/llgoi/import-source.test

Index: cmd/llgoi/llgoi.go
===================================================================
--- cmd/llgoi/llgoi.go
+++ cmd/llgoi/llgoi.go
@@ -76,8 +76,8 @@
 	imports []*types.Package
 	scope   map[string]types.Object
 
-	pkgmap, inputPkgmap map[string]*types.Package
-	pkgnum              int
+	pkgmap map[string]*types.Package
+	pkgnum int
 }
 
 func (in *interp) makeCompilerOptions() error {
@@ -98,22 +98,18 @@
 	}
 
 	origImporter := in.copts.Importer
-	in.copts.Importer = func(pkgmap map[string]*types.Package, pkgpath string) (*types.Package, error) {
-		if pkg, ok := in.inputPkgmap[pkgpath]; ok {
+	in.copts.Importer = func(_ map[string]*types.Package, pkgpath string) (*types.Package, error) {
+		if pkg, ok := in.pkgmap[pkgpath]; ok && pkg.Complete() {
 			return pkg, nil
 		}
-		if pkg, ok := pkgmap[pkgpath]; ok && pkg.Complete() {
-			return pkg, nil
-		}
-		return origImporter(pkgmap, pkgpath)
+		return origImporter(in.pkgmap, pkgpath)
 	}
 	return nil
 }
 
 func (in *interp) init() error {
 	in.scope = make(map[string]types.Object)
 	in.pkgmap = make(map[string]*types.Package)
-	in.inputPkgmap = make(map[string]*types.Package)
 
 	err := in.makeCompilerOptions()
 	if err != nil {
@@ -174,7 +170,7 @@
 		}
 	}()
 	importfunc()
-	in.inputPkgmap[pkgpath] = pkg
+	in.pkgmap[pkgpath] = pkg
 	return
 }
 
Index: test/llgoi/import-source.test
===================================================================
--- test/llgoi/import-source.test
+++ test/llgoi/import-source.test
@@ -1,4 +1,4 @@
-// RUN: env GOPATH=%S/Inputs llgoi < %s | FileCheck %s
+// RUN: env GOPATH=%S/Inputs llgoi < %s 2>&1 | FileCheck %s
 
 // make sure user symbols do not conflict with imported source package
 Answer := 1
@@ -16,5 +16,15 @@
 strconv.FormatBool(true)
 // CHECK: #0 string = true
 
+var v1 strconv.NumError
+var v2 strconv.NumError
+
+// v1 and v2 should have the same type identity.
+// CHECK-NOT: cannot assign
+v1 = v2
+
+// Method lookup relies on v1 having a consistent type.
+v1.Error
+
 import "foo_cgo"
 // CHECK: foo_cgo: cannot load cgo package

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8409.22162.patch
Type: text/x-patch
Size: 2067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150318/df319762/attachment.bin>


More information about the llvm-commits mailing list