]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.regabi] cmd/compile: simplify ir.Find, replace ir.Inspect with ir.Visit
authorRuss Cox <rsc@golang.org>
Sat, 12 Dec 2020 23:50:21 +0000 (18:50 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 17 Dec 2020 03:50:26 +0000 (03:50 +0000)
commitf6efa3d4a4a10c28d7bf13f8416022aa5fc4fa1c
tree11ff93488fe4bb05a733925b7b7220d495478efb
parentf6d2834f8f78447a06fdb05f85a2c5690e915892
[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>
src/cmd/compile/internal/gc/alg.go
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/initorder.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/scc.go
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/ir/visit.go