From: Dan Scales Date: Tue, 30 Mar 2021 23:03:26 +0000 (-0700) Subject: cmd/compile: deal with call.Use correctly for noder2, allow inlining of stenciled... X-Git-Tag: go1.17beta1~912 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6d2a557a4d;p=gostls13.git cmd/compile: deal with call.Use correctly for noder2, allow inlining of stenciled functions 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 Run-TryBot: Dan Scales TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/compile/internal/noder/helpers.go b/src/cmd/compile/internal/noder/helpers.go index e5a6dbcb01..6320b30e50 100644 --- a/src/cmd/compile/internal/noder/helpers.go +++ b/src/cmd/compile/internal/noder/helpers.go @@ -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. diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 1dff4e294c..350f8f8c2a 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -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) diff --git a/src/cmd/compile/internal/noder/transform.go b/src/cmd/compile/internal/noder/transform.go index 7f926dc70a..021d3a9fa7 100644 --- a/src/cmd/compile/internal/noder/transform.go +++ b/src/cmd/compile/internal/noder/transform.go @@ -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)