]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: rename ir.Find to ir.Any and update uses
authorRuss Cox <rsc@golang.org>
Wed, 16 Dec 2020 15:53:20 +0000 (10:53 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 18 Dec 2020 17:52:47 +0000 (17:52 +0000)
ir.Find is called "any" in C#, Dart, Haskell, Python, R, Ruby, and Rust,
and "any_of" in C++, "anyMatch" in Java, "some" in JavaScript,
"exists in OCaml, and "existsb" in Coq.
(Thanks to Matthew Dempsky for the research.)

This CL changes Find to Any to use the mostly standard name.

It also updates wrapper helpers to use the any terminology:
hasCall -> anyCall
hasCallOrChan -> anyCallOrChan
hasSideEffects -> anySideEffects

Unchanged are "hasNamedResults", "hasUniquePos", and "hasDefaultCase",
which are all about a single node, not any node in the IR tree.

I also renamed hasFall to endsInFallthrough, since its semantics are
neither that of "any" nor that of the remaining "has" functions.

So the new terminology helps separate different kinds of predicates nicely.

Change-Id: I9bb3c9ebf060a30447224be09a5c34ad5244ea0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/278912
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/alg.go
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/swt.go
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/ir/visit.go

index 3938dce46cebcfadeadbfad4fc934a6d4832b18f..3ada2581f711b43256c0262e3795501748b55fcd 100644 (file)
@@ -741,7 +741,7 @@ func geneq(t *types.Type) *obj.LSym {
        //   return (or goto ret)
        fn.PtrBody().Append(nodSym(ir.OLABEL, nil, neq))
        fn.PtrBody().Append(ir.Nod(ir.OAS, nr, nodbool(false)))
-       if EqCanPanic(t) || hasCall(fn) {
+       if EqCanPanic(t) || anyCall(fn) {
                // Epilogue is large, so share it with the equal case.
                fn.PtrBody().Append(nodSym(ir.OGOTO, nil, ret))
        } else {
@@ -782,8 +782,8 @@ func geneq(t *types.Type) *obj.LSym {
        return closure
 }
 
-func hasCall(fn *ir.Func) bool {
-       return ir.Find(fn, func(n ir.Node) bool {
+func anyCall(fn *ir.Func) bool {
+       return ir.Any(fn, func(n ir.Node) bool {
                // TODO(rsc): No methods?
                op := n.Op()
                return op == ir.OCALL || op == ir.OCALLFUNC
index 358eefd9bba21df851c33578134b1eae34ffd6a4..f8e60ea0a325009b7de52d4de65eeea899cad9d4 100644 (file)
@@ -574,7 +574,7 @@ func evalConst(n ir.Node) ir.Node {
                                return origIntConst(n, int64(len(ir.StringVal(nl))))
                        }
                case types.TARRAY:
-                       if !hasCallOrChan(nl) {
+                       if !anyCallOrChan(nl) {
                                return origIntConst(n, nl.Type().NumElem())
                        }
                }
@@ -803,9 +803,9 @@ func isGoConst(n ir.Node) bool {
        return n.Op() == ir.OLITERAL
 }
 
-// hasCallOrChan reports whether n contains any calls or channel operations.
-func hasCallOrChan(n ir.Node) bool {
-       return ir.Find(n, func(n ir.Node) bool {
+// anyCallOrChan reports whether n contains any calls or channel operations.
+func anyCallOrChan(n ir.Node) bool {
+       return ir.Any(n, func(n ir.Node) bool {
                switch n.Op() {
                case ir.OAPPEND,
                        ir.OCALL,
index e940e416fd3eb748d0f588ae4634f283bbada136..8467c20833589576ffb9def93cd5ca02a2399fe3 100644 (file)
@@ -465,7 +465,7 @@ func (v *hairyVisitor) doNode(n ir.Node) error {
 
 func isBigFunc(fn *ir.Func) bool {
        budget := inlineBigFunctionNodes
-       return ir.Find(fn, func(n ir.Node) bool {
+       return ir.Any(fn, func(n ir.Node) bool {
                budget--
                return budget <= 0
        })
@@ -733,7 +733,7 @@ func reassigned(name *ir.Name) bool {
        if name.Curfn == nil {
                return true
        }
-       return ir.Find(name.Curfn, func(n ir.Node) bool {
+       return ir.Any(name.Curfn, func(n ir.Node) bool {
                switch n.Op() {
                case ir.OAS:
                        if n.Left() == name && n != name.Defn {
index 14ff853ee5e62bdcb56a5f2eceedee2d258546c3..6d7a8bc5c91188ba963900b7768317addd8be995 100644 (file)
@@ -60,7 +60,7 @@ func (s *InitSchedule) tryStaticInit(n ir.Node) bool {
        if n.Op() != ir.OAS {
                return false
        }
-       if ir.IsBlank(n.Left()) && !hasSideEffects(n.Right()) {
+       if ir.IsBlank(n.Left()) && !anySideEffects(n.Right()) {
                // Discard.
                return true
        }
@@ -546,7 +546,7 @@ func fixedlit(ctxt initContext, kind initKind, n ir.Node, var_ ir.Node, init *ir
 
        for _, r := range n.List().Slice() {
                a, value := splitnode(r)
-               if a == ir.BlankNode && !hasSideEffects(value) {
+               if a == ir.BlankNode && !anySideEffects(value) {
                        // Discard.
                        continue
                }
index fd76a0a60a9d5b3544aa129cdbc24c6f3c6761bd..882feb47cc61f60a5fc66787b5d031b156b58382 100644 (file)
@@ -302,7 +302,7 @@ func walkExprSwitch(sw *ir.SwitchStmt) {
                // Process body.
                body.Append(npos(ncase.Pos(), nodSym(ir.OLABEL, nil, label)))
                body.Append(ncase.Body().Slice()...)
-               if fall, pos := hasFall(ncase.Body().Slice()); !fall {
+               if fall, pos := endsInFallthrough(ncase.Body().Slice()); !fall {
                        br := ir.Nod(ir.OBREAK, nil, nil)
                        br.SetPos(pos)
                        body.Append(br)
@@ -481,8 +481,8 @@ func allCaseExprsAreSideEffectFree(sw *ir.SwitchStmt) bool {
        return true
 }
 
-// hasFall reports whether stmts ends with a "fallthrough" statement.
-func hasFall(stmts []ir.Node) (bool, src.XPos) {
+// endsInFallthrough reports whether stmts ends with a "fallthrough" statement.
+func endsInFallthrough(stmts []ir.Node) (bool, src.XPos) {
        // Search backwards for the index of the fallthrough
        // statement. Do not assume it'll be in the last
        // position, since in some cases (e.g. when the statement
index f2d93df98831448d0c4a47ba57248c52870db777..420edd56949686d2014bd4df00cdcd7d5f09de16 100644 (file)
@@ -3765,9 +3765,9 @@ func usefield(n ir.Node) {
        Curfn.FieldTrack[sym] = struct{}{}
 }
 
-// hasSideEffects reports whether n contains any operations that could have observable side effects.
-func hasSideEffects(n ir.Node) bool {
-       return ir.Find(n, func(n ir.Node) bool {
+// anySideEffects reports whether n contains any operations that could have observable side effects.
+func anySideEffects(n ir.Node) bool {
+       return ir.Any(n, func(n ir.Node) bool {
                switch n.Op() {
                // Assume side effects unless we know otherwise.
                default:
index bc2b8083ba29865f4ffec69171844e8911589d8d..3f5af4ea0ecb8fa1dec6c9b2b1bc12d702c5edd2 100644 (file)
@@ -71,16 +71,16 @@ import (
 //             }
 //     }
 //
-// The Find function illustrates a different simplification of the pattern,
+// The Any function illustrates a different simplification of the pattern,
 // visiting each node and then its children, recursively, until finding
-// a node x for which find(x) returns true, at which point the entire
+// a node x for which cond(x) returns true, at which point the entire
 // traversal stops and returns true.
 //
-//     func Find(n ir.Node, find func(ir.Node)) bool {
+//     func Any(n ir.Node, find cond(ir.Node)) bool {
 //             stop := errors.New("stop")
 //             var do func(ir.Node) error
 //             do = func(x ir.Node) error {
-//                     if find(x) {
+//                     if cond(x) {
 //                             return stop
 //                     }
 //                     return ir.DoChildren(x, do)
@@ -88,9 +88,9 @@ import (
 //             return do(n) == stop
 //     }
 //
-// Visit and Find are presented above as examples of how to use
+// Visit and Any are presented above as examples of how to use
 // DoChildren effectively, but of course, usage that fits within the
-// simplifications captured by Visit or Find will be best served
+// simplifications captured by Visit or Any will be best served
 // by directly calling the ones provided by this package.
 func DoChildren(n Node, do func(Node) error) error {
        if n == nil {
@@ -138,19 +138,19 @@ func VisitList(list Nodes, visit func(Node)) {
 
 var stop = errors.New("stop")
 
-// Find looks for a non-nil node x in the IR tree rooted at n
-// for which find(x) returns true.
-// Find considers nodes in a depth-first, preorder traversal.
-// When Find finds a node x such that find(x) is true,
-// Find ends the traversal and returns true immediately.
-// Otherwise Find returns false after completing the entire traversal.
-func Find(n Node, find func(Node) bool) bool {
+// Any looks for a non-nil node x in the IR tree rooted at n
+// for which cond(x) returns true.
+// Any considers nodes in a depth-first, preorder traversal.
+// When Any finds a node x such that cond(x) is true,
+// Any ends the traversal and returns true immediately.
+// Otherwise Any returns false after completing the entire traversal.
+func Any(n Node, cond func(Node) bool) bool {
        if n == nil {
                return false
        }
        var do func(Node) error
        do = func(x Node) error {
-               if find(x) {
+               if cond(x) {
                        return stop
                }
                return DoChildren(x, do)
@@ -158,13 +158,13 @@ func Find(n Node, find func(Node) bool) bool {
        return do(n) == stop
 }
 
-// FindList calls Find(x, find) for each node x in the list, in order.
-// If any call Find(x, find) returns true, FindList stops and
-// returns that result, skipping the remainder of the list.
-// Otherwise FindList returns false.
-func FindList(list Nodes, find func(Node) bool) bool {
+// AnyList calls Any(x, cond) for each node x in the list, in order.
+// If any call returns true, AnyList stops and returns true.
+// Otherwise, AnyList returns false after calling Any(x, cond)
+// for every x in the list.
+func AnyList(list Nodes, cond func(Node) bool) bool {
        for _, x := range list.Slice() {
-               if Find(x, find) {
+               if Any(x, cond) {
                        return true
                }
        }