[dev.unified] cmd/compile/internal/walk: minor prep refactoring

Two small refactorings that will make it easier to thread through
RType parameters later. Behavior preserving, but seemed worth
separating out.

Passes toolstash -cmp.

Change-Id: I77905775015b6582bad2b32dd7700880c415893f
Reviewed-on: https://go-review.googlesource.com/c/go/+/413354
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2022-06-14 15:34:05 -07:00
parent 1f4e8afafe
commit fc5dad6646
2 changed files with 8 additions and 8 deletions

View File

@ -414,9 +414,9 @@ func slicelit(ctxt initContext, n *ir.CompLitExpr, var_ ir.Node, init *ir.Nodes)
func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
// make the map var
a := ir.NewCallExpr(base.Pos, ir.OMAKE, nil, nil)
args := []ir.Node{ir.TypeNode(n.Type()), ir.NewInt(n.Len + int64(len(n.List)))}
a := typecheck.Expr(ir.NewCallExpr(base.Pos, ir.OMAKE, nil, args)).(*ir.MakeExpr)
a.SetEsc(n.Esc())
a.Args = []ir.Node{ir.TypeNode(n.Type()), ir.NewInt(n.Len + int64(len(n.List)))}
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, m, a))
entries := n.List

View File

@ -38,11 +38,7 @@ func cheapComputableIndex(width int64) bool {
// the returned node.
func walkRange(nrange *ir.RangeStmt) ir.Node {
if isMapClear(nrange) {
m := nrange.X
lno := ir.SetPos(m)
n := mapClear(m)
base.Pos = lno
return n
return mapClear(nrange)
}
nfor := ir.NewForStmt(nrange.Pos(), nil, nil, nil, nil)
@ -360,7 +356,11 @@ func isMapClear(n *ir.RangeStmt) bool {
}
// mapClear constructs a call to runtime.mapclear for the map m.
func mapClear(m ir.Node) ir.Node {
func mapClear(nrange *ir.RangeStmt) ir.Node {
m := nrange.X
origPos := ir.SetPos(m)
defer func() { base.Pos = origPos }()
t := m.Type()
// instantiate mapclear(typ *type, hmap map[any]any)