From 7cf8593140f41358f77041ab0fc6ca7e99f6e715 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 20 Dec 2022 11:23:23 -0800 Subject: [PATCH] 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 Auto-Submit: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Keith Randall Reviewed-by: Keith Randall --- src/cmd/compile/internal/escape/call.go | 3 +-- src/cmd/compile/internal/inline/inl.go | 2 +- src/cmd/compile/internal/typecheck/func.go | 10 ++++++++++ src/cmd/compile/internal/walk/order.go | 2 +- 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, -- 2.48.1