// 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 {
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
return origIntConst(n, int64(len(ir.StringVal(nl))))
}
case types.TARRAY:
- if !hasCallOrChan(nl) {
+ if !anyCallOrChan(nl) {
return origIntConst(n, nl.Type().NumElem())
}
}
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,
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
})
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 {
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
}
for _, r := range n.List().Slice() {
a, value := splitnode(r)
- if a == ir.BlankNode && !hasSideEffects(value) {
+ if a == ir.BlankNode && !anySideEffects(value) {
// Discard.
continue
}
// 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)
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
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:
// }
// }
//
-// 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)
// 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 {
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)
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
}
}