]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove Func.ClosureType
authorMatthew Dempsky <mdempsky@google.com>
Tue, 12 Jan 2021 20:25:33 +0000 (12:25 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 12 Jan 2021 23:23:14 +0000 (23:23 +0000)
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>
src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/ir/sizeof_test.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/walk/closure.go

index 3fe23635f42859e09c5d39988a620e1aeed34737..30cddd298ef52ed26d0d8136a3cc1cc28e5772f5 100644 (file)
@@ -71,8 +71,6 @@ type Func struct {
        // Anonymous and blank PPARAMOUTs are declared as ~rNN and ~bNN Names, respectively.
        Dcl []*Name
 
-       ClosureType Ntype // closure representation type
-
        // ClosureVars lists the free variables that are used within a
        // function literal, but formally declared in an enclosing
        // function. The variables in this slice are the closure function's
index f95f77d6a2f09274550d093beb3fd0b42f131028..553dc5376098b209c24b9570d23dbc50fb566708 100644 (file)
@@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
                _32bit uintptr     // size on 32bit platforms
                _64bit uintptr     // size on 64bit platforms
        }{
-               {Func{}, 196, 344},
+               {Func{}, 188, 328},
                {Name{}, 116, 208},
        }
 
index ec0debdbbd6e932e59220b22449b1a40ab604cfb..edd30a1fc1200f14694cffe7f2eeffc4bf8ba57c 100644 (file)
@@ -1856,7 +1856,6 @@ func fakeRecv() *ir.Field {
 
 func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
        xtype := p.typeExpr(expr.Type)
-       ntype := p.typeExpr(expr.Type)
 
        fn := ir.NewFunc(p.pos(expr))
        fn.SetIsHiddenClosure(ir.CurFunc != nil)
@@ -1867,7 +1866,6 @@ func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
        fn.Nname.Defn = fn
 
        clo := ir.NewClosureExpr(p.pos(expr), fn)
-       fn.ClosureType = ntype
        fn.OClosure = clo
 
        p.funcBody(fn, expr.Body)
index 8f7411daecee7dca53af9357798abf826395a0d0..03a10f594ab243814cde37bcf334cb10645dd0d5 100644 (file)
@@ -293,20 +293,20 @@ func tcClosure(clo *ir.ClosureExpr, top int) {
                fn.Iota = x
        }
 
-       fn.ClosureType = typecheckNtype(fn.ClosureType)
-       clo.SetType(fn.ClosureType.Type())
        fn.SetClosureCalled(top&ctxCallee != 0)
 
        // Do not typecheck fn twice, otherwise, we will end up pushing
        // fn to Target.Decls multiple times, causing initLSym called twice.
        // See #30709
        if fn.Typecheck() == 1 {
+               clo.SetType(fn.Type())
                return
        }
 
        fn.Nname.SetSym(closurename(ir.CurFunc))
        ir.MarkFunc(fn.Nname)
        Func(fn)
+       clo.SetType(fn.Type())
 
        // Type check the body now, but only if we're inside a function.
        // At top level (in a variable initialization: curfn==nil) we're not
index e9b369808067407bbdd26e08dc56b492bb130722..694aa999407f23b05229e25179cc41df50e67436 100644 (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 {