]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: remove CallExpr.PreserveClosure
authorMatthew Dempsky <mdempsky@google.com>
Wed, 23 Jun 2021 03:37:42 +0000 (20:37 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 23 Jun 2021 04:47:24 +0000 (04:47 +0000)
This flag is only needed to prevent the directClosureCall optimization
in walkCall, when called for walkGoDefer. But walkGoDefer don't need
to call walkCall: at this point in the compile, the call expression
isn't a real call anymore.

Instead, we just need to walkExpr on the function expression.

Change-Id: I8a5176cfe1bff53700cbd21ed1b479ebd9a839ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/330271
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/walk/closure.go
src/cmd/compile/internal/walk/order.go
src/cmd/compile/internal/walk/stmt.go

index 779793b2f264af8dbdaed477617ce4e763fd1e19..b46fd905fe783f1da2ac5e5af6d7b178fe9917a3 100644 (file)
@@ -157,13 +157,12 @@ const (
 type CallExpr struct {
        miniExpr
        origNode
-       X               Node
-       Args            Nodes
-       KeepAlive       []*Name // vars to be kept alive until call returns
-       IsDDD           bool
-       Use             CallUse
-       NoInline        bool
-       PreserveClosure bool // disable directClosureCall for this call
+       X         Node
+       Args      Nodes
+       KeepAlive []*Name // vars to be kept alive until call returns
+       IsDDD     bool
+       Use       CallUse
+       NoInline  bool
 }
 
 func NewCallExpr(pos src.XPos, op Op, fun Node, args []Node) *CallExpr {
index 5db907d01dc0967961afddc62887dcbb96a68101..2b7fe8f926b38d2e2f8d8de368a9b7ed21bbeb15 100644 (file)
@@ -37,14 +37,6 @@ func directClosureCall(n *ir.CallExpr) {
                return // leave for walkClosure to handle
        }
 
-       // If wrapGoDefer() in the order phase has flagged this call,
-       // avoid eliminating the closure even if there is a direct call to
-       // (the closure is needed to simplify the register ABI). See
-       // wrapGoDefer for more details.
-       if n.PreserveClosure {
-               return
-       }
-
        // We are going to insert captured variables before input args.
        var params []*types.Field
        var decls []*ir.Name
index 4d40cf890e6d910bd0cf35e4121afd90a216722a..c24f80508a046718621587ea8ba8e294205a76f5 100644 (file)
@@ -1564,11 +1564,10 @@ func (o *orderState) wrapGoDefer(n *ir.GoDeferStmt) {
        // TODO: maybe not wrap if the called function has no arguments and
        // only in-register results?
        if len(callArgs) == 0 && call.Op() == ir.OCALLFUNC && callX.Type().NumResults() == 0 {
-               if c, ok := call.(*ir.CallExpr); ok && callX != nil && callX.Op() == ir.OCLOSURE {
+               if callX.Op() == ir.OCLOSURE {
                        clo := callX.(*ir.ClosureExpr)
                        clo.Func.SetClosureCalled(false)
                        clo.IsGoWrap = true
-                       c.PreserveClosure = true
                }
                return
        }
@@ -1771,9 +1770,6 @@ func (o *orderState) wrapGoDefer(n *ir.GoDeferStmt) {
        topcall := ir.NewCallExpr(n.Pos(), ir.OCALL, clo, nil)
        typecheck.Call(topcall)
 
-       // Tag the call to insure that directClosureCall doesn't undo our work.
-       topcall.PreserveClosure = true
-
        fn.SetClosureCalled(false)
 
        // Finally, point the defer statement at the newly generated call.
index e1ac6523643e0ca9d7e5af7e4288bfecb2432e7d..2352719da3f8ef2ac2e23c6cb37671b6bf3bbe48 100644 (file)
@@ -204,7 +204,9 @@ func walkGoDefer(n *ir.GoDeferStmt) ir.Node {
        }
 
        var init ir.Nodes
-       n.Call = walkExpr(n.Call, &init)
+
+       call := n.Call.(*ir.CallExpr)
+       call.X = walkExpr(call.X, &init)
 
        if len(init) > 0 {
                init.Append(n)