]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use Node.Right for OAS2* nodes (cleanup)
authorMohit Verma <vmohit.93@gmail.com>
Fri, 27 Sep 2019 22:59:03 +0000 (15:59 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 28 Sep 2019 05:04:49 +0000 (05:04 +0000)
This CL changes cmd/compile to use Node.Right instead of
Node.Rlist for OAS2FUNC/OAS2RECV/OAS2MAPR/OAS2DOTTYPE nodes.
Fixes #32293

Change-Id: I4c9d9100be2d98d15e016797f934f64d385f5faa
Reviewed-on: https://go-review.googlesource.com/c/go/+/197817
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
12 files changed:
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/gc/initorder.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/range.go
src/cmd/compile/internal/gc/select.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index d04303134ab16cea2f8e5a797faad177134b3b3c..ebe54031866d2d436fc1882ca6417c807c2024d5 100644 (file)
@@ -361,18 +361,18 @@ func (e *Escape) stmt(n *Node) {
                }
 
        case OAS2DOTTYPE: // v, ok = x.(type)
-               e.assign(n.List.First(), n.Rlist.First(), "assign-pair-dot-type", n)
+               e.assign(n.List.First(), n.Right, "assign-pair-dot-type", n)
                e.assign(n.List.Second(), nil, "assign-pair-dot-type", n)
        case OAS2MAPR: // v, ok = m[k]
-               e.assign(n.List.First(), n.Rlist.First(), "assign-pair-mapr", n)
+               e.assign(n.List.First(), n.Right, "assign-pair-mapr", n)
                e.assign(n.List.Second(), nil, "assign-pair-mapr", n)
        case OAS2RECV: // v, ok = <-ch
-               e.assign(n.List.First(), n.Rlist.First(), "assign-pair-receive", n)
+               e.assign(n.List.First(), n.Right, "assign-pair-receive", n)
                e.assign(n.List.Second(), nil, "assign-pair-receive", n)
 
        case OAS2FUNC:
-               e.stmts(n.Rlist.First().Ninit)
-               e.call(e.addrs(n.List), n.Rlist.First(), nil)
+               e.stmts(n.Right.Ninit)
+               e.call(e.addrs(n.List), n.Right, nil)
        case ORETURN:
                results := e.curfn.Type.Results().FieldSlice()
                for i, v := range n.List.Slice() {
index 7b974cc8662bec3f257c45a7ea1b83e148e20255..b401215898e1accda945ed2feb00f43938a9e85d 100644 (file)
@@ -945,8 +945,7 @@ func (n *Node) stmtfmt(s fmt.State, mode fmtMode) {
                fallthrough
 
        case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
-               mode.Fprintf(s, "%.v = %.v", n.List, n.Rlist)
-
+               mode.Fprintf(s, "%.v = %.v", n.List, n.Right)
        case ORETURN:
                mode.Fprintf(s, "return %.v", n.List)
 
index a5acd26c7fabe70455062b80a49a3690fc91ed7b..54b87ab1e40d250d9dadfa9d3594459c3b1f9daf 100644 (file)
@@ -1044,12 +1044,18 @@ func (w *exportWriter) stmt(n *Node) {
                        w.expr(n.Right)
                }
 
-       case OAS2, OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
+       case OAS2:
                w.op(OAS2)
                w.pos(n.Pos)
                w.exprList(n.List)
                w.exprList(n.Rlist)
 
+       case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
+               w.op(OAS2)
+               w.pos(n.Pos)
+               w.exprList(n.List)
+               w.exprList(asNodes([]*Node{n.Right}))
+
        case ORETURN:
                w.op(ORETURN)
                w.pos(n.Pos)
index be1e671d17761d975aeb57935d1885633ff86348..41f1349bbe64ff2ad8e5b13c033e9a390b7835f8 100644 (file)
@@ -254,7 +254,7 @@ func collectDeps(n *Node, transitive bool) NodeSet {
        case OAS:
                d.inspect(n.Right)
        case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
-               d.inspect(n.Rlist.First())
+               d.inspect(n.Right)
        case ODCLFUNC:
                d.inspectList(n.Nbody)
        default:
index b41b8cb1a490bb3debce6c0619ea433384707593..4a376305bb3091d8480f1548ce402abaae27749d 100644 (file)
@@ -580,6 +580,12 @@ func inlnode(n *Node, maxCost int32) *Node {
        if n.Right != nil && n.Right.Op == OINLCALL {
                if n.Op == OFOR || n.Op == OFORUNTIL {
                        inlconv2stmt(n.Right)
+               } else if n.Op == OAS2FUNC {
+                       n.Rlist.Set(inlconv2list(n.Right))
+                       n.Right = nil
+                       n.Op = OAS2
+                       n.SetTypecheck(0)
+                       n = typecheck(n, ctxStmt)
                } else {
                        n.Right = inlconv2expr(n.Right)
                }
@@ -602,20 +608,13 @@ func inlnode(n *Node, maxCost int32) *Node {
        }
 
        inlnodelist(n.Rlist, maxCost)
-       if n.Op == OAS2FUNC && n.Rlist.First().Op == OINLCALL {
-               n.Rlist.Set(inlconv2list(n.Rlist.First()))
-               n.Op = OAS2
-               n.SetTypecheck(0)
-               n = typecheck(n, ctxStmt)
-       } else {
-               s := n.Rlist.Slice()
-               for i1, n1 := range s {
-                       if n1.Op == OINLCALL {
-                               if n.Op == OIF {
-                                       inlconv2stmt(n1)
-                               } else {
-                                       s[i1] = inlconv2expr(s[i1])
-                               }
+       s := n.Rlist.Slice()
+       for i1, n1 := range s {
+               if n1.Op == OINLCALL {
+                       if n.Op == OIF {
+                               inlconv2stmt(n1)
+                       } else {
+                               s[i1] = inlconv2expr(s[i1])
                        }
                }
        }
index e6350ef721e1d3a194ce14663adff866d2a911a9..786067c49c9f441e0ba3c079ac408cbe369566b9 100644 (file)
@@ -567,7 +567,7 @@ func (o *Order) stmt(n *Node) {
        case OAS2MAPR:
                t := o.markTemp()
                o.exprList(n.List)
-               r := n.Rlist.First()
+               r := n.Right
                r.Left = o.expr(r.Left, nil)
                r.Right = o.expr(r.Right, nil)
 
@@ -582,8 +582,8 @@ func (o *Order) stmt(n *Node) {
        case OAS2FUNC:
                t := o.markTemp()
                o.exprList(n.List)
-               o.init(n.Rlist.First())
-               o.call(n.Rlist.First())
+               o.init(n.Right)
+               o.call(n.Right)
                o.as2(n)
                o.cleanTemp(t)
 
@@ -593,7 +593,7 @@ func (o *Order) stmt(n *Node) {
        case OAS2DOTTYPE:
                t := o.markTemp()
                o.exprList(n.List)
-               n.Rlist.First().Left = o.expr(n.Rlist.First().Left, nil) // i in i.(T)
+               n.Right.Left = o.expr(n.Right.Left, nil) // i in i.(T)
                o.okAs2(n)
                o.cleanTemp(t)
 
@@ -602,8 +602,8 @@ func (o *Order) stmt(n *Node) {
        case OAS2RECV:
                t := o.markTemp()
                o.exprList(n.List)
-               n.Rlist.First().Left = o.expr(n.Rlist.First().Left, nil) // arg to recv
-               ch := n.Rlist.First().Left.Type
+               n.Right.Left = o.expr(n.Right.Left, nil) // arg to recv
+               ch := n.Right.Left.Type
                tmp1 := o.newTemp(ch.Elem(), types.Haspointers(ch.Elem()))
                tmp2 := o.newTemp(types.Types[TBOOL], false)
                o.out = append(o.out, n)
@@ -1343,7 +1343,7 @@ func (o *Order) as2(n *Node) {
 func (o *Order) okAs2(n *Node) {
        var tmp1, tmp2 *Node
        if !n.List.First().isBlank() {
-               typ := n.Rlist.First().Type
+               typ := n.Right.Type
                tmp1 = o.newTemp(typ, types.Haspointers(typ))
        }
 
index 4d354f23cf1bc3704d6d70b2f1c4df9e5254b3a6..4744324a7c8fbc519cfb4691be8e275711ff0ef7 100644 (file)
@@ -343,7 +343,7 @@ func walkrange(n *Node) *Node {
                a := nod(OAS2RECV, nil, nil)
                a.SetTypecheck(1)
                a.List.Set2(hv1, hb)
-               a.Rlist.Set1(nod(ORECV, ha, nil))
+               a.Right = nod(ORECV, ha, nil)
                n.Left.Ninit.Set1(a)
                if v1 == nil {
                        body = nil
index 07c5c5a2a963cef17e4dcf68c08287f2e210ba26..49cc23cd3de236b6edc60e867e7cb7004ba2400f 100644 (file)
@@ -60,7 +60,7 @@ func typecheckselect(sel *Node) {
 
                                // convert x, ok = <-c into OSELRECV2(x, <-c) with ntest=ok
                        case OAS2RECV:
-                               if n.Rlist.First().Op != ORECV {
+                               if n.Right.Op != ORECV {
                                        yyerrorl(n.Pos, "select assignment must have receive on right hand side")
                                        break
                                }
@@ -68,8 +68,6 @@ func typecheckselect(sel *Node) {
                                n.Op = OSELRECV2
                                n.Left = n.List.First()
                                n.List.Set1(n.List.Second())
-                               n.Right = n.Rlist.First()
-                               n.Rlist.Set(nil)
 
                                // convert <-c into OSELRECV(N, <-c)
                        case ORECV:
index 7b0c7e5c4331aed0e20acb1b04d651c5267e46f7..efc7d1eb5192e4af945f5ec0321a316b202a11c7 100644 (file)
@@ -874,9 +874,9 @@ func (s *state) stmt(n *Node) {
                s.call(n.Left, callGo)
 
        case OAS2DOTTYPE:
-               res, resok := s.dottype(n.Rlist.First(), true)
+               res, resok := s.dottype(n.Right, true)
                deref := false
-               if !canSSAType(n.Rlist.First().Type) {
+               if !canSSAType(n.Right.Type) {
                        if res.Op != ssa.OpLoad {
                                s.Fatalf("dottype of non-load")
                        }
@@ -896,10 +896,10 @@ func (s *state) stmt(n *Node) {
 
        case OAS2FUNC:
                // We come here only when it is an intrinsic call returning two values.
-               if !isIntrinsicCall(n.Rlist.First()) {
-                       s.Fatalf("non-intrinsic AS2FUNC not expanded %v", n.Rlist.First())
+               if !isIntrinsicCall(n.Right) {
+                       s.Fatalf("non-intrinsic AS2FUNC not expanded %v", n.Right)
                }
-               v := s.intrinsicCall(n.Rlist.First())
+               v := s.intrinsicCall(n.Right)
                v1 := s.newValue1(ssa.OpSelect0, n.List.First().Type, v)
                v2 := s.newValue1(ssa.OpSelect1, n.List.Second().Type, v)
                s.assign(n.List.First(), v1, false, 0)
index c26ed6251b5bc1dcf60797d6e8c96d4a001b4b17..c1df046654f06c7b10a06aef8782bdd2fd512e88 100644 (file)
@@ -600,10 +600,10 @@ const (
        OSTR2RUNES    // Type(Left) (Type is []rune, Left is a string)
        OAS           // Left = Right or (if Colas=true) Left := Right
        OAS2          // List = Rlist (x, y, z = a, b, c)
-       OAS2DOTTYPE   // List = Rlist (x, ok = I.(int))
-       OAS2FUNC      // List = Rlist (x, y = f())
-       OAS2MAPR      // List = Rlist (x, ok = m["foo"])
-       OAS2RECV      // List = Rlist (x, ok = <-c)
+       OAS2DOTTYPE   // List = Right (x, ok = I.(int))
+       OAS2FUNC      // List = Right (x, y = f())
+       OAS2MAPR      // List = Right (x, ok = m["foo"])
+       OAS2RECV      // List = Right (x, ok = <-c)
        OASOP         // Left Etype= Right (x += y)
        OCALL         // Left(List) (function call, method call or type conversion)
 
index ab45fb5a2d64758b5c7d6db6131b85f392ec9dc8..c9b7e3b1e85c5e8320af0c3f5175fb44ba69f0d8 100644 (file)
@@ -3275,6 +3275,8 @@ func typecheckas2(n *Node) {
                                goto mismatch
                        }
                        n.Op = OAS2FUNC
+                       n.Right = r
+                       n.Rlist.Set(nil)
                        for i, l := range n.List.Slice() {
                                f := r.Type.Field(i)
                                if f.Type != nil && l.Type != nil {
@@ -3298,15 +3300,14 @@ func typecheckas2(n *Node) {
                        switch r.Op {
                        case OINDEXMAP:
                                n.Op = OAS2MAPR
-
                        case ORECV:
                                n.Op = OAS2RECV
-
                        case ODOTTYPE:
                                n.Op = OAS2DOTTYPE
                                r.Op = ODOTTYPE2
                        }
-
+                       n.Right = r
+                       n.Rlist.Set(nil)
                        if l.Type != nil {
                                checkassignto(r.Type, l)
                        }
index ceec1b4dc1e1dac0562290ff5b4f204643af5d2e..7f73d416e81021a3772dbb66152ae43c1042f18f 100644 (file)
@@ -691,12 +691,12 @@ opswitch:
        case OAS2FUNC:
                init.AppendNodes(&n.Ninit)
 
-               r := n.Rlist.First()
+               r := n.Right
                walkexprlistsafe(n.List.Slice(), init)
                r = walkexpr(r, init)
 
                if isIntrinsicCall(r) {
-                       n.Rlist.Set1(r)
+                       n.Right = r
                        break
                }
                init.Append(r)
@@ -709,7 +709,7 @@ opswitch:
        case OAS2RECV:
                init.AppendNodes(&n.Ninit)
 
-               r := n.Rlist.First()
+               r := n.Right
                walkexprlistsafe(n.List.Slice(), init)
                r.Left = walkexpr(r.Left, init)
                var n1 *Node
@@ -728,7 +728,7 @@ opswitch:
        case OAS2MAPR:
                init.AppendNodes(&n.Ninit)
 
-               r := n.Rlist.First()
+               r := n.Right
                walkexprlistsafe(n.List.Slice(), init)
                r.Left = walkexpr(r.Left, init)
                r.Right = walkexpr(r.Right, init)
@@ -767,7 +767,7 @@ opswitch:
                if ok := n.List.Second(); !ok.isBlank() && ok.Type.IsBoolean() {
                        r.Type.Field(1).Type = ok.Type
                }
-               n.Rlist.Set1(r)
+               n.Right = r
                n.Op = OAS2FUNC
 
                // don't generate a = *var if a is _
@@ -801,7 +801,7 @@ opswitch:
 
        case OAS2DOTTYPE:
                walkexprlistsafe(n.List.Slice(), init)
-               n.Rlist.SetFirst(walkexpr(n.Rlist.First(), init))
+               n.Right = walkexpr(n.Right, init)
 
        case OCONVIFACE:
                n.Left = walkexpr(n.Left, init)