Skip to content

Commit 7cf8593

Browse files
mdempskygopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 4e3abee commit 7cf8593

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/cmd/compile/internal/escape/call.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ func (e *escape) callCommon(ks []hole, call ir.Node, init *ir.Nodes, wrapper *ir
4545

4646
case ir.OCALLFUNC, ir.OCALLMETH, ir.OCALLINTER:
4747
call := call.(*ir.CallExpr)
48-
typecheck.FixVariadicCall(call)
49-
typecheck.FixMethodCall(call)
48+
typecheck.AssertFixedCall(call)
5049

5150
// Pick out the function callee, if statically known.
5251
//

src/cmd/compile/internal/inline/inl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlCalls *[]*ir.Inlin
981981
}
982982
}
983983

984-
typecheck.FixVariadicCall(n)
984+
typecheck.AssertFixedCall(n)
985985

986986
inlIndex := base.Ctxt.InlTree.Add(parent, n.Pos(), sym)
987987

src/cmd/compile/internal/typecheck/func.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ func FixMethodCall(call *ir.CallExpr) {
7676
call.Args = args
7777
}
7878

79+
func AssertFixedCall(call *ir.CallExpr) {
80+
if call.X.Type().IsVariadic() && !call.IsDDD {
81+
base.FatalfAt(call.Pos(), "missed FixVariadicCall")
82+
}
83+
if call.Op() == ir.OCALLMETH {
84+
base.FatalfAt(call.Pos(), "missed FixMethodCall")
85+
}
86+
}
87+
7988
// ClosureType returns the struct type used to hold all the information
8089
// needed in the closure for clo (clo must be a OCLOSURE node).
8190
// 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 {
339348
}
340349

341350
typecheckaste(ir.OCALL, n.X, n.IsDDD, t.Params(), n.Args, func() string { return fmt.Sprintf("argument to %v", n.X) })
351+
FixVariadicCall(n)
342352
FixMethodCall(n)
343353
if t.NumResults() == 0 {
344354
return n

src/cmd/compile/internal/walk/order.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ func (o *orderState) call(nn ir.Node) {
536536
}
537537

538538
n := nn.(*ir.CallExpr)
539-
typecheck.FixVariadicCall(n)
539+
typecheck.AssertFixedCall(n)
540540

541541
if isFuncPCIntrinsic(n) && isIfaceOfFunc(n.Args[0]) {
542542
// For internal/abi.FuncPCABIxxx(fn), if fn is a defined function,

0 commit comments

Comments
 (0)