Skip to content

Commit a3b95ce

Browse files
authored
Merge pull request #279 from adamslc/walk_docs
Document the behavior Walk with bare rewriters
2 parents 8fae11b + 26fdce4 commit a3b95ce

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

page/rewrite.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ rewriters.
156156
- `If(cond, rw)` is the same as `IfElse(cond, rw, Empty())`
157157
- `Prewalk(rw; threaded=false, thread_cutoff=100)` returns a rewriter which does a pre-order
158158
(*from top to bottom and from left to right*) traversal of a given expression and applies
159-
the rewriter `rw`. `threaded=true` will use multi threading for traversal. `thread_cutoff`
159+
the rewriter `rw`. `threaded=true` will use multi threading for traversal.
160+
Note that if `rw` returns `nothing` when a match is not found, then `Prewalk(rw)` will
161+
also return nothing unless a match is found at every level of the walk. If you are
162+
applying multiple rules, then `Chain` already has the appropriate passthrough behavior.
163+
If you only want to apply one rule, then consider using `PassThrough`.
164+
`thread_cutoff`
160165
is the minimum number of nodes in a subtree which should be walked in a threaded spawn.
161166
- `Postwalk(rw; threaded=false, thread_cutoff=100)` similarly does post-order
162167
(*from left to right and from bottom to top*) traversal.

src/rewriters.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ rewriters.
1616
returns true, `rw2` if it retuns false
1717
- `If(cond, rw)` is the same as `IfElse(cond, rw, Empty())`
1818
- `Prewalk(rw; threaded=false, thread_cutoff=100)` returns a rewriter which does a pre-order
19-
traversal of a given expression and applies the rewriter `rw`. `threaded=true` will
20-
use multi threading for traversal. `thread_cutoff` is the minimum number of nodes
21-
in a subtree which should be walked in a threaded spawn.
19+
traversal of a given expression and applies the rewriter `rw`. Note that if
20+
`rw` returns `nothing` when a match is not found, then `Prewalk(rw)` will
21+
also return nothing unless a match is found at every level of the walk.
22+
`threaded=true` will use multi threading for traversal. `thread_cutoff` is
23+
the minimum number of nodes in a subtree which should be walked in a
24+
threaded spawn.
2225
- `Postwalk(rw; threaded=false, thread_cutoff=100)` similarly does post-order traversal.
2326
- `Fixpoint(rw)` returns a rewriter which applies `rw` repeatedly until there are no changes to be made.
2427
- `PassThrough(rw)` returns a rewriter which if `rw(x)` returns `nothing` will instead

0 commit comments

Comments
 (0)