]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: deal with call.Use correctly for noder2, allow inlining of stenciled...
authorDan Scales <danscales@google.com>
Tue, 30 Mar 2021 23:03:26 +0000 (16:03 -0700)
committerDan Scales <danscales@google.com>
Wed, 31 Mar 2021 00:52:58 +0000 (00:52 +0000)
The setting of n.Use for a call node in transformCall() (and previously
in Call()), was not corrrect, since it was trying to use the number of
results of the call, rather than whether the call result was actually
used. We are already setting n.Use to ir.CallUseStmt if the call node is
directly a statement, so we just need to initialize n.Use to
ir.CallExprStmt in Call(), which will get changed to ir.CallUseStmt at
the statement level if it's used as a statement.

Enable inlining of stenciled functions (just disabled for testing,
easier debugging). The above n.Use fix was required for the inlining
to work for two cases.

Change-Id: Ie4ef6cd53fd4b20a4f3be31e629280909a545b7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/305913
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/noder/helpers.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/noder/transform.go

index e5a6dbcb013567ce2eb59554c94287cfe81c5d82..6320b30e5044e506cae059935e4cd2d634baf46a 100644 (file)
@@ -87,6 +87,9 @@ func Binary(pos src.XPos, op ir.Op, typ *types.Type, x, y ir.Node) ir.Node {
 func Call(pos src.XPos, typ *types.Type, fun ir.Node, args []ir.Node, dots bool) ir.Node {
        n := ir.NewCallExpr(pos, ir.OCALL, fun, args)
        n.IsDDD = dots
+       // n.Use will be changed to ir.CallUseStmt in g.stmt() if this call is
+       // just a statement (any return values are ignored).
+       n.Use = ir.CallUseExpr
 
        if fun.Op() == ir.OTYPE {
                // Actually a type conversion, not a function call.
index 1dff4e294c30d797e4447ce48d46e80e70249bac..350f8f8c2a1e68ae5be8dc83d5a931f47e031d4c 100644 (file)
@@ -303,8 +303,6 @@ func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, targs []ir.No
        ir.MarkFunc(newf.Nname)
        newf.SetTypecheck(1)
        newf.Nname.SetTypecheck(1)
-       // TODO(danscales) - remove later, but avoid confusion for now.
-       newf.Pragma = ir.Noinline
 
        // Make sure name/type of newf is set before substituting the body.
        newf.Body = subst.list(gf.Body)
index 7f926dc70ae573ac592b93f04f0f092fd05c1350..021d3a9fa78c397810fc1cb1638f6b4e71980872 100644 (file)
@@ -143,11 +143,6 @@ func transformCall(n *ir.CallExpr) {
        }
 
        typecheckaste(ir.OCALL, n.X, n.IsDDD, t.Params(), n.Args)
-       if t.NumResults() == 0 {
-               n.Use = ir.CallUseStmt
-               return
-       }
-       n.Use = ir.CallUseExpr
        if t.NumResults() == 1 {
                n.SetType(l.Type().Results().Field(0).Type)