[dev.regabi] cmd/compile: remove Func.ClosureType

The closure's type always matches the corresponding function's type,
so just use one instance rather than carrying around two. Simplifies
construction of closures, rewriting them during walk, and shrinks
memory usage.

Passes toolstash -cmp.

Change-Id: I83b8b8f435b02ab25a30fb7aa15d5ec7ad97189d
Reviewed-on: https://go-review.googlesource.com/c/go/+/283152
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Matthew Dempsky 2021-01-12 12:25:33 -08:00
parent 41352fd401
commit d9acf6f3a3
5 changed files with 8 additions and 12 deletions

View file

@ -64,10 +64,12 @@ func directClosureCall(n *ir.CallExpr) {
// f is ONAME of the actual function.
f := clofn.Nname
// Prepend params and decls.
typ := f.Type()
typ.Params().SetFields(append(params, typ.Params().FieldSlice()...))
// Create new function type with parameters prepended, and
// then update type and declarations.
typ = types.NewSignature(typ.Pkg(), nil, append(params, typ.Params().FieldSlice()...), typ.Results().FieldSlice())
f.SetType(typ)
clofn.Dcl = append(decls, clofn.Dcl...)
// Rewrite call.
@ -78,8 +80,6 @@ func directClosureCall(n *ir.CallExpr) {
// because typecheck gave it the result type of the OCLOSURE
// node, but we only rewrote the ONAME node's type. Logically,
// they're the same, but the stack offsets probably changed.
//
// TODO(mdempsky): Reuse a single type for both.
if typ.NumResults() == 1 {
n.SetType(typ.Results().Field(0).Type)
} else {