diff --git a/src/cmd/compile/internal/gc/alg.go b/src/cmd/compile/internal/gc/alg.go index 3938dce46c..3ada2581f7 100644 --- a/src/cmd/compile/internal/gc/alg.go +++ b/src/cmd/compile/internal/gc/alg.go @@ -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 diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 358eefd9bb..f8e60ea0a3 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -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, diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index e940e416fd..8467c20833 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -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 { diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index 14ff853ee5..6d7a8bc5c9 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -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 } diff --git a/src/cmd/compile/internal/gc/swt.go b/src/cmd/compile/internal/gc/swt.go index fd76a0a60a..882feb47cc 100644 --- a/src/cmd/compile/internal/gc/swt.go +++ b/src/cmd/compile/internal/gc/swt.go @@ -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 diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index f2d93df988..420edd5694 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -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: diff --git a/src/cmd/compile/internal/ir/visit.go b/src/cmd/compile/internal/ir/visit.go index bc2b8083ba..3f5af4ea0e 100644 --- a/src/cmd/compile/internal/ir/visit.go +++ b/src/cmd/compile/internal/ir/visit.go @@ -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 } }