]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: apply FixVariadicCall and FixMethodCall during typecheck
authorMatthew Dempsky <mdempsky@google.com>
Tue, 20 Dec 2022 19:23:23 +0000 (11:23 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 27 Jan 2023 03:37:13 +0000 (03:37 +0000)
To simplify backend analysis, we normalize variadic and method calls:
variadic calls are rewritten with an explicit slice argument, and
method calls are turned into function calls that pass the receiver
argument as the first parameter.

But because we've been supporting multiple frontends, this
normalization was scattered in various later passes. Now that we're
back to just one frontend, we can move the normalization forward into
typecheck (where most other IR normalization already happens).

Change-Id: Idd05ae231fc180ae3dd1664452414f6b6d578962
Reviewed-on: https://go-review.googlesource.com/c/go/+/463737
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/escape/call.go
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/walk/order.go

index 94bc8874dac58da86cf9f5ce7246b7ffb242a0df..f1c2c306a2a4b3034a68e3f7638cadc10d6dd060 100644 (file)
@@ -45,8 +45,7 @@ func (e *escape) callCommon(ks []hole, call ir.Node, init *ir.Nodes, wrapper *ir
 
        case ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER:
                call := call.(*ir.CallExpr)
-               typecheck.FixVariadicCall(call)
-               typecheck.FixMethodCall(call)
+               typecheck.AssertFixedCall(call)
 
                // Pick out the function callee, if statically known.
                //
index 99cbda8e9c91213a193d6a37780760fffe3d41d6..781dae1396b206e71db037f4a9a6d34df2531961 100644 (file)
@@ -981,7 +981,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlCalls *[]*ir.Inlin
                }
        }
 
-       typecheck.FixVariadicCall(n)
+       typecheck.AssertFixedCall(n)
 
        inlIndex := base.Ctxt.InlTree.Add(parent, n.Pos(), sym)
 
index bc27f20cd000e759e61323577b5dc10c49fa702f..065007b04eacd4f28b2ba1da80cdbeefaa65ccaa 100644 (file)
@@ -76,6 +76,15 @@ func FixMethodCall(call *ir.CallExpr) {
        call.Args = args
 }
 
+func AssertFixedCall(call *ir.CallExpr) {
+       if call.X.Type().IsVariadic() && !call.IsDDD {
+               base.FatalfAt(call.Pos(), "missed FixVariadicCall")
+       }
+       if call.Op() == ir.OCALLMETH {
+               base.FatalfAt(call.Pos(), "missed FixMethodCall")
+       }
+}
+
 // ClosureType returns the struct type used to hold all the information
 // needed in the closure for clo (clo must be a OCLOSURE node).
 // The address of a variable of the returned type can be cast to a func.
@@ -339,6 +348,7 @@ func tcCall(n *ir.CallExpr, top int) ir.Node {
        }
 
        typecheckaste(ir.OCALL, n.X, n.IsDDD, t.Params(), n.Args, func() string { return fmt.Sprintf("argument to %v", n.X) })
+       FixVariadicCall(n)
        FixMethodCall(n)
        if t.NumResults() == 0 {
                return n
index c7c3d97621f914c0dd929c726a2341b4a597e62c..d6712ae0fc4a569c3a6489dca1d6d825178745eb 100644 (file)
@@ -536,7 +536,7 @@ func (o *orderState) call(nn ir.Node) {
        }
 
        n := nn.(*ir.CallExpr)
-       typecheck.FixVariadicCall(n)
+       typecheck.AssertFixedCall(n)
 
        if isFuncPCIntrinsic(n) && isIfaceOfFunc(n.Args[0]) {
                // For internal/abi.FuncPCABIxxx(fn), if fn is a defined function,