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
|
||||
origNode
|
||||
List Nodes // initialized values
|
||||
RType Node `mknode:"-"` // *runtime._type for OMAPLIT map types
|
||||
Prealloc *Name
|
||||
// For OSLICELIT, Len is the backing array length.
|
||||
// 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))
|
||||
switch lit.Op() {
|
||||
case ir.OMAPLIT:
|
||||
lit := lit.(*ir.CompLitExpr)
|
||||
lit.RType = reflectdata.TypePtrAt(pos, typ)
|
||||
}
|
||||
if typ0.IsPtr() {
|
||||
lit = typecheck.Expr(typecheck.NodAddrAt(pos, lit))
|
||||
lit.SetType(typ0)
|
||||
|
|
|
|||
|
|
@ -160,9 +160,7 @@ func DeleteMapRType(pos src.XPos, n *ir.CallExpr) ir.Node {
|
|||
// map type.
|
||||
func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node {
|
||||
assertOp(n, ir.OINDEXMAP)
|
||||
// TODO(mdempsky): Need to propagate RType from OMAPLIT nodes to
|
||||
// emitted OINDEXMAP nodes.
|
||||
if haveRType(n, n.RType, "RType", false) {
|
||||
if haveRType(n, n.RType, "RType", true) {
|
||||
return n.RType
|
||||
}
|
||||
return mapRType(pos, n.X.Type())
|
||||
|
|
@ -184,9 +182,7 @@ func MakeChanRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
|
|||
// representing that map type.
|
||||
func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node {
|
||||
assertOp(n, ir.OMAKEMAP)
|
||||
// TODO(mdempsky): Need to propagate RType from OMAPLIT nodes to
|
||||
// emitted OMAKEMAP nodes.
|
||||
if haveRType(n, n.RType, "RType", false) {
|
||||
if haveRType(n, n.RType, "RType", true) {
|
||||
return n.RType
|
||||
}
|
||||
return mapRType(pos, n.Type())
|
||||
|
|
|
|||
|
|
@ -416,6 +416,7 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
|
|||
// make the map var
|
||||
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.RType = n.RType
|
||||
a.SetEsc(n.Esc())
|
||||
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
|
||||
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, kidx)).(*ir.IndexExpr)
|
||||
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))
|
||||
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
|
||||
lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, tmpkey)).(*ir.IndexExpr)
|
||||
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)
|
||||
a = typecheck.Stmt(a)
|
||||
|
|
|
|||
|
|
@ -1452,6 +1452,7 @@ func (o *orderState) expr1(n, lhs ir.Node) ir.Node {
|
|||
for _, r := range dynamics {
|
||||
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)
|
||||
lhs.RType = n.RType
|
||||
|
||||
as := ir.NewAssignStmt(base.Pos, lhs, r.Value)
|
||||
typecheck.Stmt(as)
|
||||
|
|
|
|||
Loading…
Reference in New Issue