aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/noder.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-08 23:44:31 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-12 02:16:50 +0000
commit099599662d15598fc2690e60bd36bc087a3bdec5 (patch)
tree9d6c8e6ba2c2fccd97983ff46e354ed10ee94110 /src/cmd/compile/internal/noder/noder.go
parent106aa941dfda45d4aa5235b12317124aaf8941a0 (diff)
downloadgo-099599662d15598fc2690e60bd36bc087a3bdec5.tar.gz
go-099599662d15598fc2690e60bd36bc087a3bdec5.zip
[dev.typeparams] cmd/compile: refactor import logic
This CL refactors noder's package import logic so it's easier to reuse with types2 and gcimports. In particular, this allows the types2 integration to now support vendored packages. Change-Id: I1fd98ad612b4683d2e1ac640839e64de1fa7324b Reviewed-on: https://go-review.googlesource.com/c/go/+/282919 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/noder.go')
-rw-r--r--src/cmd/compile/internal/noder/noder.go33
1 files changed, 1 insertions, 32 deletions
diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go
index 71a5df082b..5a9e37af7d 100644
--- a/src/cmd/compile/internal/noder/noder.go
+++ b/src/cmd/compile/internal/noder/noder.go
@@ -9,7 +9,6 @@ import (
"fmt"
"go/constant"
"go/token"
- "io"
"os"
"path/filepath"
"runtime"
@@ -20,7 +19,6 @@ import (
"cmd/compile/internal/base"
"cmd/compile/internal/dwarfgen"
- "cmd/compile/internal/importer"
"cmd/compile/internal/ir"
"cmd/compile/internal/syntax"
"cmd/compile/internal/typecheck"
@@ -126,13 +124,6 @@ func ParseFiles(filenames []string) (lines uint) {
},
Importer: &gcimports{
packages: make(map[string]*types2.Package),
- lookup: func(path string) (io.ReadCloser, error) {
- file, ok := findpkg(path)
- if !ok {
- return nil, fmt.Errorf("can't find import: %q", path)
- }
- return os.Open(file)
- },
},
Sizes: &gcSizes{},
}
@@ -255,23 +246,6 @@ func Package() {
}
-// Temporary import helper to get type2-based type-checking going.
-type gcimports struct {
- packages map[string]*types2.Package
- lookup func(path string) (io.ReadCloser, error)
-}
-
-func (m *gcimports) Import(path string) (*types2.Package, error) {
- return m.ImportFrom(path, "" /* no vendoring */, 0)
-}
-
-func (m *gcimports) ImportFrom(path, srcDir string, mode types2.ImportMode) (*types2.Package, error) {
- if mode != 0 {
- panic("mode must be 0")
- }
- return importer.Import(m.packages, path, srcDir, m.lookup)
-}
-
func (p *noder) errorAt(pos syntax.Pos, format string, args ...interface{}) {
base.ErrorfAt(p.makeXPos(pos), format, args...)
}
@@ -483,7 +457,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
p.checkUnused(pragma)
}
- ipkg := importfile(p.basicLit(imp.Path))
+ ipkg := importfile(imp)
if ipkg == nil {
if base.Errors() == 0 {
base.Fatalf("phase error in import")
@@ -498,11 +472,6 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
p.importedEmbed = true
}
- if !ipkg.Direct {
- typecheck.Target.Imports = append(typecheck.Target.Imports, ipkg)
- }
- ipkg.Direct = true
-
var my *types.Sym
if imp.LocalPkgName != nil {
my = p.name(imp.LocalPkgName)