diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-05-27 02:48:33 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-05-27 23:54:29 +0000 |
commit | 22f5ece3b13b7e5f6dece399c96d1d665b3a05bc (patch) | |
tree | 0917173ad8bfb39b97334c06bdb5d8f595e23983 /src/cmd/compile/internal/noder/decl.go | |
parent | 417955d151359629ca11be968e3056e6636b828e (diff) | |
download | go-22f5ece3b13b7e5f6dece399c96d1d665b3a05bc.tar.gz go-22f5ece3b13b7e5f6dece399c96d1d665b3a05bc.zip |
[dev.typeparams] cmd/compile/internal/noder: refactor irgen import handling
Rather than re-parsing and re-resolving the import path string, use
the PkgName object provided by types2 to determine what package path
it refers to.
Also, decompose importfile into smaller functions, so that we can
directly pass the already-resolved package path to the importer.
Finally, switch to simply using height as calculated by types2 rather
than redoing the calculations.
Change-Id: I3338f4e68387b2835b2e58d6df65d740d6a648cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/323309
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/decl.go')
-rw-r--r-- | src/cmd/compile/internal/noder/decl.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go index 40cbe50aff..375eb41898 100644 --- a/src/cmd/compile/internal/noder/decl.go +++ b/src/cmd/compile/internal/noder/decl.go @@ -46,7 +46,12 @@ func (g *irgen) importDecl(p *noder, decl *syntax.ImportDecl) { g.pragmaFlags(decl.Pragma, 0) - ipkg := importfile(decl) + // Get the imported package's path, as resolved already by types2 + // and gcimporter. This is the same path as would be computed by + // parseImportPath. + path := pkgNameOf(g.info, decl).Imported().Path() + + ipkg := readImportFile(g.target, path) if ipkg == ir.Pkgs.Unsafe { p.importedUnsafe = true } @@ -55,6 +60,14 @@ func (g *irgen) importDecl(p *noder, decl *syntax.ImportDecl) { } } +// pkgNameOf returns the PkgName associated with the given ImportDecl. +func pkgNameOf(info *types2.Info, decl *syntax.ImportDecl) *types2.PkgName { + if name := decl.LocalPkgName; name != nil { + return info.Defs[name].(*types2.PkgName) + } + return info.Implicits[decl].(*types2.PkgName) +} + func (g *irgen) constDecl(out *ir.Nodes, decl *syntax.ConstDecl) { g.pragmaFlags(decl.Pragma, 0) |