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>
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
// 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)
}
// 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)