aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2023-08-09 08:39:47 -0700
committerGopher Robot <gobot@golang.org>2023-08-11 18:12:07 +0000
commite7e5913161e94f77f29443e8b8ddd22714a0f01d (patch)
treed31538891e0709be705d6b12c8e67244af3c1374 /src/cmd/compile/internal/noder
parent59037ac93a49889eb6a7d6b3b8fbc70321615f1f (diff)
downloadgo-e7e5913161e94f77f29443e8b8ddd22714a0f01d.tar.xz
cmd/compile: cleanup ir.Package
Decls used to contain initializer statement for package-level variables, but now it only contains ir.Funcs. So we might as well rename it to Funcs and tighten its type to []*ir.Func. Similarly, Externs always contains *ir.Names, so its type can be constrained too. Change-Id: I85b833e2f83d9d3559ab0ef8ab5d8324f4bc37b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/517855 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/reader.go19
-rw-r--r--src/cmd/compile/internal/noder/unified.go32
2 files changed, 23 insertions, 28 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index a92a890437..0f936b4764 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -3015,7 +3015,14 @@ func (r *reader) tempCopy(pos src.XPos, expr ir.Node, init *ir.Nodes) *ir.Name {
assign.Def = true
tmp.Defn = assign
- typecheck.Target.Decls = append(typecheck.Target.Decls, typecheck.Stmt(assign))
+ // TODO(mdempsky): This code doesn't work anymore, because we now
+ // rely on types2 to compute InitOrder. If it's going to be used
+ // for testing again, the assignment here probably needs to be
+ // added to typecheck.Target.InitOrder somewhere.
+ //
+ // Probably just easier to address the escape analysis limitation.
+ //
+ // typecheck.Target.Decls = append(typecheck.Target.Decls, typecheck.Stmt(assign))
return tmp
}
@@ -3353,14 +3360,14 @@ func (r *reader) pkgDecls(target *ir.Package) {
case declFunc:
names := r.pkgObjs(target)
assert(len(names) == 1)
- target.Decls = append(target.Decls, names[0].Func)
+ target.Funcs = append(target.Funcs, names[0].Func)
case declMethod:
typ := r.typ()
_, sym := r.selector()
method := typecheck.Lookdot1(nil, sym, typ, typ.Methods(), 0)
- target.Decls = append(target.Decls, method.Nname.(*ir.Name).Func)
+ target.Funcs = append(target.Funcs, method.Nname.(*ir.Name).Func)
case declVar:
names := r.pkgObjs(target)
@@ -3629,7 +3636,7 @@ func expandInline(fn *ir.Func, pri pkgReaderIndex) {
// with the same information some other way.
fndcls := len(fn.Dcl)
- topdcls := len(typecheck.Target.Decls)
+ topdcls := len(typecheck.Target.Funcs)
tmpfn := ir.NewFunc(fn.Pos())
tmpfn.Nname = ir.NewNameAt(fn.Nname.Pos(), fn.Sym())
@@ -3661,7 +3668,7 @@ func expandInline(fn *ir.Func, pri pkgReaderIndex) {
// typecheck.Stmts may have added function literals to
// typecheck.Target.Decls. Remove them again so we don't risk trying
// to compile them multiple times.
- typecheck.Target.Decls = typecheck.Target.Decls[:topdcls]
+ typecheck.Target.Funcs = typecheck.Target.Funcs[:topdcls]
}
// usedLocals returns a set of local variables that are used within body.
@@ -3925,7 +3932,7 @@ func finishWrapperFunc(fn *ir.Func, target *ir.Package) {
}
})
- target.Decls = append(target.Decls, fn)
+ target.Funcs = append(target.Funcs, fn)
}
// newWrapperType returns a copy of the given signature type, but with
diff --git a/src/cmd/compile/internal/noder/unified.go b/src/cmd/compile/internal/noder/unified.go
index 0afa505550..3e5ab2ec39 100644
--- a/src/cmd/compile/internal/noder/unified.go
+++ b/src/cmd/compile/internal/noder/unified.go
@@ -91,27 +91,17 @@ func unified(m posMap, noders []*noder) {
r := localPkgReader.newReader(pkgbits.RelocMeta, pkgbits.PrivateRootIdx, pkgbits.SyncPrivate)
r.pkgInit(types.LocalPkg, target)
- // Type-check any top-level assignments. We ignore non-assignments
- // here because other declarations are typechecked as they're
- // constructed.
- for i, ndecls := 0, len(target.Decls); i < ndecls; i++ {
- switch n := target.Decls[i]; n.Op() {
- case ir.OAS, ir.OAS2:
- target.Decls[i] = typecheck.Stmt(n)
- }
- }
-
readBodies(target, false)
// Check that nothing snuck past typechecking.
- for _, n := range target.Decls {
- if n.Typecheck() == 0 {
- base.FatalfAt(n.Pos(), "missed typecheck: %v", n)
+ for _, fn := range target.Funcs {
+ if fn.Typecheck() == 0 {
+ base.FatalfAt(fn.Pos(), "missed typecheck: %v", fn)
}
// For functions, check that at least their first statement (if
// any) was typechecked too.
- if fn, ok := n.(*ir.Func); ok && len(fn.Body) != 0 {
+ if len(fn.Body) != 0 {
if stmt := fn.Body[0]; stmt.Typecheck() == 0 {
base.FatalfAt(stmt.Pos(), "missed typecheck: %v", stmt)
}
@@ -120,11 +110,9 @@ func unified(m posMap, noders []*noder) {
// For functions originally came from package runtime,
// mark as norace to prevent instrumenting, see issue #60439.
- for _, n := range target.Decls {
- if fn, ok := n.(*ir.Func); ok {
- if !base.Flag.CompilingRuntime && types.IsRuntimePkg(fn.Sym().Pkg) {
- fn.Pragma |= ir.Norace
- }
+ for _, fn := range target.Funcs {
+ if !base.Flag.CompilingRuntime && types.IsRuntimePkg(fn.Sym().Pkg) {
+ fn.Pragma |= ir.Norace
}
}
@@ -138,7 +126,7 @@ func unified(m posMap, noders []*noder) {
// necessary on instantiations of imported generic functions, so their
// inlining costs can be computed.
func readBodies(target *ir.Package, duringInlining bool) {
- var inlDecls []ir.Node
+ var inlDecls []*ir.Func
// Don't use range--bodyIdx can add closures to todoBodies.
for {
@@ -175,7 +163,7 @@ func readBodies(target *ir.Package, duringInlining bool) {
if duringInlining && canSkipNonGenericMethod {
inlDecls = append(inlDecls, fn)
} else {
- target.Decls = append(target.Decls, fn)
+ target.Funcs = append(target.Funcs, fn)
}
}
@@ -208,7 +196,7 @@ func readBodies(target *ir.Package, duringInlining bool) {
base.Flag.LowerM = oldLowerM
for _, fn := range inlDecls {
- fn.(*ir.Func).Body = nil // free memory
+ fn.Body = nil // free memory
}
}
}