Skip to content

Commit

Permalink
internal/gcimporter: remove indexed support from Import
Browse files Browse the repository at this point in the history
Removes support for the indexed binary format from the test
only function Import.

Additionally makes Import more similar to go/internal/gcimporter.Import
by taking a token.FileSet argument.

Updates golang/go#70651

Change-Id: I39f120adc554278adb3d114194c27fd5906985a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/633435
Commit-Queue: Tim King <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
timothy-king authored and Go LUCI committed Dec 9, 2024
1 parent 7790f2e commit 6ebf95a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
11 changes: 3 additions & 8 deletions internal/gcimporter/gcimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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':
Expand All @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions internal/gcimporter/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 6ebf95a

Please sign in to comment.