summaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/alg.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-12-12 18:50:21 -0500
committerRuss Cox <rsc@golang.org>2020-12-17 03:50:26 +0000
commitf6efa3d4a4a10c28d7bf13f8416022aa5fc4fa1c (patch)
tree11ff93488fe4bb05a733925b7b7220d495478efb /src/cmd/compile/internal/gc/alg.go
parentf6d2834f8f78447a06fdb05f85a2c5690e915892 (diff)
downloadgo-git-f6efa3d4a4a10c28d7bf13f8416022aa5fc4fa1c.tar.gz
[dev.regabi] cmd/compile: simplify ir.Find, replace ir.Inspect with ir.Visit
It seems clear after using these for a week that Find need not return anything other than a bool saying whether the target was found. The main reason for not using the boolean earlier was to avoid confusion with Inspect: for Find, returning true means "it was found! stop walking" while for Inspect, returning true means "keep walking the children". But it turns out that none of the uses of Inspect need the boolean. This makes sense because types can contain expressions, expressions can contain statements (inside function literals), and so on, so there are essentially no times when you can say based on the current AST node that the children are irrelevant to a particular operation. So this CL makes two changes: 1) Change Find to return a boolean and to take a callback function returning a boolean. This simplifies all existing calls to Find. 2) Rename Inspect to Visit and change it to take a callback with no result at all. This simplifies all existing calls to Inspect. Removing the boolean result from Inspect's callback avoids having two callbacks with contradictory boolean results in different APIs. Renaming Inspect to Visit avoids confusion with ast.Inspect. Passes buildall w/ toolstash -cmp. Change-Id: I344ebb5e00b6842012be33e779db483c28e5f350 Reviewed-on: https://go-review.googlesource.com/c/go/+/277919 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/alg.go')
-rw-r--r--src/cmd/compile/internal/gc/alg.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/gc/alg.go b/src/cmd/compile/internal/gc/alg.go
index 8550edb9e0..3938dce46c 100644
--- a/src/cmd/compile/internal/gc/alg.go
+++ b/src/cmd/compile/internal/gc/alg.go
@@ -783,13 +783,11 @@ func geneq(t *types.Type) *obj.LSym {
}
func hasCall(fn *ir.Func) bool {
- found := ir.Find(fn, func(n ir.Node) interface{} {
- if op := n.Op(); op == ir.OCALL || op == ir.OCALLFUNC {
- return n
- }
- return nil
+ return ir.Find(fn, func(n ir.Node) bool {
+ // TODO(rsc): No methods?
+ op := n.Op()
+ return op == ir.OCALL || op == ir.OCALLFUNC
})
- return found != nil
}
// eqfield returns the node