aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-12-20 11:23:23 -0800
committerGopher Robot <gobot@golang.org>2023-01-27 03:37:13 +0000
commit7cf8593140f41358f77041ab0fc6ca7e99f6e715 (patch)
tree753ffd849ef8fe4a0e6e0bf7f87b32c700524cb0 /src/cmd/compile
parent4e3abee245755d741987132fb22c442af2dab1de (diff)
downloadgo-7cf8593140f41358f77041ab0fc6ca7e99f6e715.tar.xz
cmd/compile: apply FixVariadicCall and FixMethodCall during typecheck
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>
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/escape/call.go3
-rw-r--r--src/cmd/compile/internal/inline/inl.go2
-rw-r--r--src/cmd/compile/internal/typecheck/func.go10
-rw-r--r--src/cmd/compile/internal/walk/order.go2
4 files changed, 13 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/escape/call.go b/src/cmd/compile/internal/escape/call.go
index 94bc8874da..f1c2c306a2 100644
--- a/src/cmd/compile/internal/escape/call.go
+++ b/src/cmd/compile/internal/escape/call.go
@@ -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.
//
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go
index 99cbda8e9c..781dae1396 100644
--- a/src/cmd/compile/internal/inline/inl.go
+++ b/src/cmd/compile/internal/inline/inl.go
@@ -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)
diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go
index bc27f20cd0..065007b04e 100644
--- a/src/cmd/compile/internal/typecheck/func.go
+++ b/src/cmd/compile/internal/typecheck/func.go
@@ -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
diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go
index c7c3d97621..d6712ae0fc 100644
--- a/src/cmd/compile/internal/walk/order.go
+++ b/src/cmd/compile/internal/walk/order.go
@@ -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,