[dev.typeparams] cmd/compile: refactor noder/irgen helpers

This CL refactors the code for invoking the types2 checker and for
validating //go:embed directives to be easier to reuse separately.
No functional change.

Change-Id: I706f4ea4a26b1f1d2f4064befcc0777a1067383d
Reviewed-on: https://go-review.googlesource.com/c/go/+/323310
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Matthew Dempsky 2021-05-27 02:47:25 -07:00
parent 4b10e4c547
commit 2580e9a160
3 changed files with 75 additions and 62 deletions

View file

@ -18,9 +18,9 @@ import (
"cmd/internal/src"
)
// check2 type checks a Go package using types2, and then generates IR
// using the results.
func check2(noders []*noder) {
// checkFiles configures and runs the types2 checker on the given
// parsed source files and then returns the result.
func checkFiles(noders []*noder, importer types2.Importer) (posMap, *types2.Package, *types2.Info) {
if base.SyntaxErrors() != 0 {
base.ErrorExit()
}
@ -42,12 +42,10 @@ func check2(noders []*noder) {
terr := err.(types2.Error)
base.ErrorfAt(m.makeXPos(terr.Pos), "%s", terr.Msg)
},
Importer: &gcimports{
packages: make(map[string]*types2.Package),
},
Sizes: &gcSizes{},
Importer: importer,
Sizes: &gcSizes{},
}
info := types2.Info{
info := &types2.Info{
Types: make(map[syntax.Expr]types2.TypeAndValue),
Defs: make(map[*syntax.Name]types2.Object),
Uses: make(map[*syntax.Name]types2.Object),
@ -57,12 +55,25 @@ func check2(noders []*noder) {
Inferred: make(map[syntax.Expr]types2.Inferred),
// expand as needed
}
pkg, err := conf.Check(base.Ctxt.Pkgpath, files, &info)
files = nil
pkg, err := conf.Check(base.Ctxt.Pkgpath, files, info)
base.ExitIfErrors()
if err != nil {
base.FatalfAt(src.NoXPos, "conf.Check error: %v", err)
}
return m, pkg, info
}
// check2 type checks a Go package using types2, and then generates IR
// using the results.
func check2(noders []*noder) {
importer := &gcimports{
packages: make(map[string]*types2.Package),
}
m, pkg, info := checkFiles(noders, importer)
if base.Flag.G < 2 {
os.Exit(0)
}
@ -70,7 +81,7 @@ func check2(noders []*noder) {
g := irgen{
target: typecheck.Target,
self: pkg,
info: &info,
info: info,
posMap: m,
objs: make(map[types2.Object]*ir.Name),
typs: make(map[types2.Type]*types.Type),