]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.unified] cmd/compile: plumb rtype through for OMAPLIT
authorMatthew Dempsky <mdempsky@google.com>
Tue, 21 Jun 2022 09:29:49 +0000 (02:29 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 23 Jun 2022 21:52:53 +0000 (21:52 +0000)
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>

src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/reflectdata/helpers.go
src/cmd/compile/internal/walk/complit.go
src/cmd/compile/internal/walk/order.go

index 4a8db70904bb67fdc08661f87fc3708822d942dd..0058a98824e102ffc67a3bf70cc29d868b611c74 100644 (file)
@@ -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
index 7588e52d96032178f53b840c86d9085efc4e0a46..32276e75537ff288ff8a1a1bf6f189f5043f14f6 100644 (file)
@@ -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)
index 22431a2bcb4c2fb1f29bca431366d59fe3e54c89..66f1864474525f95415ec7f1f5015a3bfeb84627 100644 (file)
@@ -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())
index d8e5a955c29ba4aaecca92714fd5ee1dc1df8132..7dec9ae6d8b4fbb768253a4d88b46e3786961f61 100644 (file)
@@ -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)
index 2602e205635df4a36d97e692614a1fa14a3b555a..525c29b96f48342ff810e82e8b3d020fed073d84 100644 (file)
@@ -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)