mirror of https://github.com/golang/go.git
[dev.unified] cmd/compile: plumb rtype through for OMAPLIT
OMAPLIT gets lowered into a bunch of OINDEXMAP operations, which in general may require a *runtime._type argument. This CL adds CompLitExpr.RType, updates the GOEXPERIMENT=unified frontend to start setting it, and updates walk to propagate it through to any generated OINDEXMAP operations. Change-Id: I278e7e8e615ea6d01f65a5eba6d6fc8e00045735 Reviewed-on: https://go-review.googlesource.com/c/go/+/413360 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
7368647ac6
commit
3d432b6c4b
|
|
@ -194,6 +194,7 @@ type CompLitExpr struct {
|
||||||
miniExpr
|
miniExpr
|
||||||
origNode
|
origNode
|
||||||
List Nodes // initialized values
|
List Nodes // initialized values
|
||||||
|
RType Node `mknode:"-"` // *runtime._type for OMAPLIT map types
|
||||||
Prealloc *Name
|
Prealloc *Name
|
||||||
// For OSLICELIT, Len is the backing array length.
|
// For OSLICELIT, Len is the backing array length.
|
||||||
// For OMAPLIT, Len is the number of entries that we've removed from List and
|
// For OMAPLIT, Len is the number of entries that we've removed from List and
|
||||||
|
|
|
||||||
|
|
@ -1812,6 +1812,11 @@ func (r *reader) compLit() ir.Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
lit := typecheck.Expr(ir.NewCompLitExpr(pos, ir.OCOMPLIT, typ, elems))
|
lit := typecheck.Expr(ir.NewCompLitExpr(pos, ir.OCOMPLIT, typ, elems))
|
||||||
|
switch lit.Op() {
|
||||||
|
case ir.OMAPLIT:
|
||||||
|
lit := lit.(*ir.CompLitExpr)
|
||||||
|
lit.RType = reflectdata.TypePtrAt(pos, typ)
|
||||||
|
}
|
||||||
if typ0.IsPtr() {
|
if typ0.IsPtr() {
|
||||||
lit = typecheck.Expr(typecheck.NodAddrAt(pos, lit))
|
lit = typecheck.Expr(typecheck.NodAddrAt(pos, lit))
|
||||||
lit.SetType(typ0)
|
lit.SetType(typ0)
|
||||||
|
|
|
||||||
|
|
@ -160,9 +160,7 @@ func DeleteMapRType(pos src.XPos, n *ir.CallExpr) ir.Node {
|
||||||
// map type.
|
// map type.
|
||||||
func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node {
|
func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node {
|
||||||
assertOp(n, ir.OINDEXMAP)
|
assertOp(n, ir.OINDEXMAP)
|
||||||
// TODO(mdempsky): Need to propagate RType from OMAPLIT nodes to
|
if haveRType(n, n.RType, "RType", true) {
|
||||||
// emitted OINDEXMAP nodes.
|
|
||||||
if haveRType(n, n.RType, "RType", false) {
|
|
||||||
return n.RType
|
return n.RType
|
||||||
}
|
}
|
||||||
return mapRType(pos, n.X.Type())
|
return mapRType(pos, n.X.Type())
|
||||||
|
|
@ -184,9 +182,7 @@ func MakeChanRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
|
||||||
// representing that map type.
|
// representing that map type.
|
||||||
func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
|
func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
|
||||||
assertOp(n, ir.OMAKEMAP)
|
assertOp(n, ir.OMAKEMAP)
|
||||||
// TODO(mdempsky): Need to propagate RType from OMAPLIT nodes to
|
if haveRType(n, n.RType, "RType", true) {
|
||||||
// emitted OMAKEMAP nodes.
|
|
||||||
if haveRType(n, n.RType, "RType", false) {
|
|
||||||
return n.RType
|
return n.RType
|
||||||
}
|
}
|
||||||
return mapRType(pos, n.Type())
|
return mapRType(pos, n.Type())
|
||||||
|
|
|
||||||
|
|
@ -416,6 +416,7 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
|
||||||
// make the map var
|
// make the map var
|
||||||
args := []ir.Node{ir.TypeNode(n.Type()), ir.NewInt(n.Len + int64(len(n.List)))}
|
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 := typecheck.Expr(ir.NewCallExpr(base.Pos, ir.OMAKE, nil, args)).(*ir.MakeExpr)
|
||||||
|
a.RType = n.RType
|
||||||
a.SetEsc(n.Esc())
|
a.SetEsc(n.Esc())
|
||||||
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, m, a))
|
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, m, a))
|
||||||
|
|
||||||
|
|
@ -471,6 +472,7 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
|
||||||
// typechecker rewrites OINDEX to OINDEXMAP
|
// typechecker rewrites OINDEX to OINDEXMAP
|
||||||
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, kidx)).(*ir.IndexExpr)
|
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, kidx)).(*ir.IndexExpr)
|
||||||
base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
|
base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
|
||||||
|
lhs.RType = n.RType
|
||||||
|
|
||||||
zero := ir.NewAssignStmt(base.Pos, i, ir.NewInt(0))
|
zero := ir.NewAssignStmt(base.Pos, i, ir.NewInt(0))
|
||||||
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, ir.NewInt(tk.NumElem()))
|
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, ir.NewInt(tk.NumElem()))
|
||||||
|
|
@ -510,6 +512,7 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
|
||||||
// typechecker rewrites OINDEX to OINDEXMAP
|
// typechecker rewrites OINDEX to OINDEXMAP
|
||||||
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, tmpkey)).(*ir.IndexExpr)
|
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, tmpkey)).(*ir.IndexExpr)
|
||||||
base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
|
base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
|
||||||
|
lhs.RType = n.RType
|
||||||
|
|
||||||
var a ir.Node = ir.NewAssignStmt(base.Pos, lhs, tmpelem)
|
var a ir.Node = ir.NewAssignStmt(base.Pos, lhs, tmpelem)
|
||||||
a = typecheck.Stmt(a)
|
a = typecheck.Stmt(a)
|
||||||
|
|
|
||||||
|
|
@ -1452,6 +1452,7 @@ func (o *orderState) expr1(n, lhs ir.Node) ir.Node {
|
||||||
for _, r := range dynamics {
|
for _, r := range dynamics {
|
||||||
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, r.Key)).(*ir.IndexExpr)
|
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, r.Key)).(*ir.IndexExpr)
|
||||||
base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
|
base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
|
||||||
|
lhs.RType = n.RType
|
||||||
|
|
||||||
as := ir.NewAssignStmt(base.Pos, lhs, r.Value)
|
as := ir.NewAssignStmt(base.Pos, lhs, r.Value)
|
||||||
typecheck.Stmt(as)
|
typecheck.Stmt(as)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue