Skip to content

Commit 5a5ab24

Browse files
committed
[dev.regabi] cmd/compile: do not rely on CallExpr.Rargs for detect already walked calls
Currently, there's an awkward issue with walk pass. When walking the AST tree, the compiler generate code for runtime functions (using mkcall* variants), add/modify the AST tree and walk new generated tree again. This causes the double walking on some CallExpr, which is relying on checking Rargs to prevent that. But checking Rargs has its own issue as well. For functions that does not have arguments, this check is failed, and we still double walk the CallExpr node. This CL change the way that compiler detects double walking, by using separated field instead of relying on Rargs. In perfect world, we should make the compiler walks the AST tree just once, but it's not safe to do that at this moment. Passes toolstash -cmp. Change-Id: Ifdd1e0f98940ddb1f574af2da2ac7f005b5fcadd Reviewed-on: https://go-review.googlesource.com/c/go/+/283672 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 983ac4b commit 5a5ab24

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/cmd/compile/internal/ir/mini.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
miniTypecheckShift = 2
5959
miniDiag = 1 << 4
6060
miniHasCall = 1 << 5 // for miniStmt
61+
miniWalked = 1 << 6 // to prevent/catch re-walking
6162
)
6263

6364
func (n *miniNode) Typecheck() uint8 { return n.bits.get2(miniTypecheckShift) }
@@ -71,6 +72,9 @@ func (n *miniNode) SetTypecheck(x uint8) {
7172
func (n *miniNode) Diag() bool { return n.bits&miniDiag != 0 }
7273
func (n *miniNode) SetDiag(x bool) { n.bits.set(miniDiag, x) }
7374

75+
func (n *miniNode) Walked() bool { return n.bits&miniWalked != 0 }
76+
func (n *miniNode) SetWalked(x bool) { n.bits.set(miniWalked, x) }
77+
7478
// Empty, immutable graph structure.
7579

7680
func (n *miniNode) Init() Nodes { return Nodes{} }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,10 @@ func walkCall(n *ir.CallExpr, init *ir.Nodes) ir.Node {
497497
}
498498

499499
func walkCall1(n *ir.CallExpr, init *ir.Nodes) {
500-
if len(n.Rargs) != 0 {
500+
if n.Walked() {
501501
return // already walked
502502
}
503+
n.SetWalked(true)
503504

504505
// If this is a method call t.M(...),
505506
// rewrite into a function call T.M(t, ...).

0 commit comments

Comments
 (0)