mirror of https://github.com/golang/go.git
[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:
parent
1f4e8afafe
commit
fc5dad6646
|
|
@ -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) {
|
func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
|
||||||
// make the map var
|
// 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.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))
|
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, m, a))
|
||||||
|
|
||||||
entries := n.List
|
entries := n.List
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,7 @@ func cheapComputableIndex(width int64) bool {
|
||||||
// the returned node.
|
// the returned node.
|
||||||
func walkRange(nrange *ir.RangeStmt) ir.Node {
|
func walkRange(nrange *ir.RangeStmt) ir.Node {
|
||||||
if isMapClear(nrange) {
|
if isMapClear(nrange) {
|
||||||
m := nrange.X
|
return mapClear(nrange)
|
||||||
lno := ir.SetPos(m)
|
|
||||||
n := mapClear(m)
|
|
||||||
base.Pos = lno
|
|
||||||
return n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nfor := ir.NewForStmt(nrange.Pos(), nil, nil, nil, nil)
|
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.
|
// 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()
|
t := m.Type()
|
||||||
|
|
||||||
// instantiate mapclear(typ *type, hmap map[any]any)
|
// instantiate mapclear(typ *type, hmap map[any]any)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue