]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove refersToCommonName
authorMatthew Dempsky <mdempsky@google.com>
Sun, 27 Dec 2020 05:33:17 +0000 (21:33 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 28 Dec 2020 07:44:35 +0000 (07:44 +0000)
After reorder3's simplification, the only remaining use of
refersToCommonName is in oaslit, where the LHS expression is always a
single name. We can replace the now overly-generalized
refersToCommonName with a simple ir.Any traversal with ir.Uses.

Passes toolstash -cmp.

Change-Id: Ice3020cdbbf6083d52e07866a687580f4eb134b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/280439
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/walk/assign.go
src/cmd/compile/internal/walk/complit.go

index 99541c58d9d06a281827592d2a83657e11a40c0a..c01079d236bc03b0626bfe7c17971738ae1f9d2e 100644 (file)
@@ -495,55 +495,6 @@ func readsMemory(n ir.Node) bool {
        return true
 }
 
-// refersToCommonName reports whether any name
-// appears in common between l and r.
-// This is called from sinit.go.
-func refersToCommonName(l ir.Node, r ir.Node) bool {
-       if l == nil || r == nil {
-               return false
-       }
-
-       // This could be written elegantly as a Find nested inside a Find:
-       //
-       //      found := ir.Find(l, func(l ir.Node) interface{} {
-       //              if l.Op() == ir.ONAME {
-       //                      return ir.Find(r, func(r ir.Node) interface{} {
-       //                              if r.Op() == ir.ONAME && l.Name() == r.Name() {
-       //                                      return r
-       //                              }
-       //                              return nil
-       //                      })
-       //              }
-       //              return nil
-       //      })
-       //      return found != nil
-       //
-       // But that would allocate a new closure for the inner Find
-       // for each name found on the left side.
-       // It may not matter at all, but the below way of writing it
-       // only allocates two closures, not O(|L|) closures.
-
-       var doL, doR func(ir.Node) error
-       var targetL *ir.Name
-       doR = func(r ir.Node) error {
-               if r.Op() == ir.ONAME && r.Name() == targetL {
-                       return stop
-               }
-               return ir.DoChildren(r, doR)
-       }
-       doL = func(l ir.Node) error {
-               if l.Op() == ir.ONAME {
-                       l := l.(*ir.Name)
-                       targetL = l.Name()
-                       if doR(r) == stop {
-                               return stop
-                       }
-               }
-               return ir.DoChildren(l, doL)
-       }
-       return doL(l) == stop
-}
-
 // expand append(l1, l2...) to
 //   init {
 //     s := l1
index b53fe2e935abf55c5ebd2578786cbb1ec8ebb9a0..8c4f9583ef5df7075caa056b434cc25272812a70 100644 (file)
@@ -629,6 +629,7 @@ func oaslit(n *ir.AssignStmt, init *ir.Nodes) bool {
                // not a special composite literal assignment
                return false
        }
+       x := n.X.(*ir.Name)
        if !types.Identical(n.X.Type(), n.Y.Type()) {
                // not a special composite literal assignment
                return false
@@ -640,7 +641,7 @@ func oaslit(n *ir.AssignStmt, init *ir.Nodes) bool {
                return false
 
        case ir.OSTRUCTLIT, ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
-               if refersToCommonName(n.X, n.Y) {
+               if ir.Any(n.Y, func(y ir.Node) bool { return ir.Uses(y, x) }) {
                        // not a special composite literal assignment
                        return false
                }