diff --git a/internal/gcimporter/gcimporter.go b/internal/gcimporter/gcimporter.go index dbbca860432..c1136ea6439 100644 --- a/internal/gcimporter/gcimporter.go +++ b/internal/gcimporter/gcimporter.go @@ -162,8 +162,8 @@ func FindPkg(path, srcDir string) (filename, id string) { // the corresponding package object to the packages map, and returns the object. // The packages map must contain all packages already imported. // -// TODO(taking): Import is only used in tests. Move to gcimporter_test. -func Import(packages map[string]*types.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types.Package, err error) { +// Import is only used in tests. +func Import(fset *token.FileSet, 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 { @@ -227,10 +227,6 @@ func Import(packages map[string]*types.Package, path, srcDir string, lookup func return nil, fmt.Errorf("no data to load a package from for path %s", id) } - // TODO(gri): allow clients of go/importer to provide a FileSet. - // Or, define a new standard go/types/gcexportdata package. - fset := token.NewFileSet() - // Select appropriate importer. switch data[0] { case 'v', 'c', 'd': @@ -241,8 +237,7 @@ func Import(packages map[string]*types.Package, path, srcDir string, lookup func // indexed: emitted by cmd/compile till go1.19; // now used only for serializing go/types. // See https://github.com/golang/go/issues/69491. - _, pkg, err := IImportData(fset, packages, data[1:], id) - return pkg, err + return nil, fmt.Errorf("indexed (i) import format is no longer supported") case 'u': // unified: emitted by cmd/compile since go1.20. diff --git a/internal/gcimporter/gcimporter_test.go b/internal/gcimporter/gcimporter_test.go index 21dcf3d2e84..20fbdef7f93 100644 --- a/internal/gcimporter/gcimporter_test.go +++ b/internal/gcimporter/gcimporter_test.go @@ -93,7 +93,7 @@ func compilePkg(t *testing.T, dirname, filename, outdirname string, packagefiles func testPath(t *testing.T, path, srcDir string) *types.Package { t0 := time.Now() - pkg, err := gcimporter.Import(make(map[string]*types.Package), path, srcDir, nil) + pkg, err := gcimporter.Import(token.NewFileSet(), make(map[string]*types.Package), path, srcDir, nil) if err != nil { t.Errorf("testPath(%s): %s", path, err) return nil @@ -314,7 +314,7 @@ func TestVersionHandling(t *testing.T) { } // test that export data can be imported - _, err := gcimporter.Import(make(map[string]*types.Package), pkgpath, dir, nil) + _, err := gcimporter.Import(token.NewFileSet(), make(map[string]*types.Package), pkgpath, dir, nil) if err != nil { t.Errorf("import %q failed: %v", pkgpath, err) continue @@ -343,7 +343,7 @@ func TestVersionHandling(t *testing.T) { os.WriteFile(filename, data, 0666) // test that importing the corrupted file results in an error - _, err = gcimporter.Import(make(map[string]*types.Package), pkgpath, corruptdir, nil) + _, err = gcimporter.Import(token.NewFileSet(), make(map[string]*types.Package), pkgpath, corruptdir, nil) if err == nil { t.Errorf("import corrupted %q succeeded", pkgpath) } else if msg := err.Error(); !strings.Contains(msg, "internal error") { @@ -473,7 +473,7 @@ func importObject(t *testing.T, name string) types.Object { importPath := s[0] objName := s[1] - pkg, err := gcimporter.Import(make(map[string]*types.Package), importPath, ".", nil) + pkg, err := gcimporter.Import(token.NewFileSet(), make(map[string]*types.Package), importPath, ".", nil) if err != nil { t.Error(err) return nil @@ -555,7 +555,7 @@ func TestCorrectMethodPackage(t *testing.T) { testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache imports := make(map[string]*types.Package) - _, err := gcimporter.Import(imports, "net/http", ".", nil) + _, err := gcimporter.Import(token.NewFileSet(), imports, "net/http", ".", nil) if err != nil { t.Fatal(err) } @@ -613,7 +613,7 @@ func TestIssue13898(t *testing.T) { // import go/internal/gcimporter which imports go/types partially imports := make(map[string]*types.Package) - _, err := gcimporter.Import(imports, "go/internal/gcimporter", ".", nil) + _, err := gcimporter.Import(token.NewFileSet(), imports, "go/internal/gcimporter", ".", nil) if err != nil { t.Fatal(err) } @@ -673,7 +673,7 @@ func TestIssue15517(t *testing.T) { // The same issue occurs with vendoring.) imports := make(map[string]*types.Package) for i := 0; i < 3; i++ { - if _, err := gcimporter.Import(imports, "./././testdata/p", tmpdir, nil); err != nil { + if _, err := gcimporter.Import(token.NewFileSet(), imports, "./././testdata/p", tmpdir, nil); err != nil { t.Fatal(err) } } @@ -909,7 +909,7 @@ func TestIssue58296(t *testing.T) { } // make sure a and b are both imported by c. - pkg, err := gcimporter.Import(imports, "./c", testoutdir, nil) + pkg, err := gcimporter.Import(token.NewFileSet(), imports, "./c", testoutdir, nil) if err != nil { t.Fatal(err) } @@ -952,7 +952,7 @@ func TestIssueAliases(t *testing.T) { ) // import c from gc export data using a and b. - pkg, err := gcimporter.Import(map[string]*types.Package{ + pkg, err := gcimporter.Import(token.NewFileSet(), map[string]*types.Package{ apkg: types.NewPackage(apkg, "a"), bpkg: types.NewPackage(bpkg, "b"), }, "./c", testoutdir, nil) @@ -996,7 +996,7 @@ func apkg(testoutdir string) string { } func importPkg(t *testing.T, path, srcDir string) *types.Package { - pkg, err := gcimporter.Import(make(map[string]*types.Package), path, srcDir, nil) + pkg, err := gcimporter.Import(token.NewFileSet(), make(map[string]*types.Package), path, srcDir, nil) if err != nil { t.Fatal(err) } diff --git a/internal/gcimporter/testdata/versions/test_go1.16_i.a b/internal/gcimporter/testdata/versions/test_go1.16_i.a deleted file mode 100644 index 35dc863e81c..00000000000 Binary files a/internal/gcimporter/testdata/versions/test_go1.16_i.a and /dev/null differ diff --git a/internal/gcimporter/testdata/versions/test_go1.17_i.a b/internal/gcimporter/testdata/versions/test_go1.17_i.a deleted file mode 100644 index 7a8ecb75c7e..00000000000 Binary files a/internal/gcimporter/testdata/versions/test_go1.17_i.a and /dev/null differ diff --git a/internal/gcimporter/testdata/versions/test_go1.18.5_i.a b/internal/gcimporter/testdata/versions/test_go1.18.5_i.a deleted file mode 100644 index 6ed126f7e92..00000000000 Binary files a/internal/gcimporter/testdata/versions/test_go1.18.5_i.a and /dev/null differ diff --git a/internal/gcimporter/testdata/versions/test_go1.19_i.a b/internal/gcimporter/testdata/versions/test_go1.19_i.a deleted file mode 100644 index ff8f5995bb8..00000000000 Binary files a/internal/gcimporter/testdata/versions/test_go1.19_i.a and /dev/null differ