Skip to content

Commit

Permalink
[dev.unified] cmd/compile/internal/walk: minor prep refactoring
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mdempsky committed Jun 21, 2022
1 parent 1f4e8af commit fc5dad6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/walk/complit.go
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/compile/internal/walk/range.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fc5dad6

Please sign in to comment.