Skip to content

Implement "VisitFlow" - #1263

Merged
keithamus merged 2 commits into
mainfrom
implement-visitflow
Jul 4, 2026
Merged

Implement "VisitFlow"#1263
keithamus merged 2 commits into
mainfrom
implement-visitflow

Conversation

@keithamus

Copy link
Copy Markdown
Member

Currently the AST traversal visitor pattern walks the entire tree, even when it
doesn't strictly need to. This is bad for performance, which is especially
wasteful as we precompute alot of metadata while building the AST. This also
means some code (e.g. reduce_colors) needs to manage its own control flow to
avoid "over reducing" some nodes. Really we should be able to skip descending
into subtrees.

This change refactors the Visit code to return a ControlFlow type, with subtype
enums that control how visitors should descend into the tree. Each visit method
can either break (stop the whole visit flow), skip children (so only the exit_
fires) or descend (the default). This also refactors the various consumers to
take advantage of this new feature, including the selector engine in csskit_ast.

@keithamus
keithamus enabled auto-merge (squash) July 4, 2026 09:05
@keithamus
keithamus force-pushed the implement-visitflow branch from c67e61c to 7cec54f Compare July 4, 2026 09:06
Currently the AST traversal visitor pattern walks the entire tree, even when it
doesn't strictly need to. This is bad for performance, which is especially
wasteful as we precompute alot of metadata while building the AST. This also
means some code (e.g. reduce_colors) needs to manage its own control flow to
avoid "over reducing" some nodes. Really we should be able to skip descending
into subtrees.

This change refactors the Visit code to return a ControlFlow type, with subtype
enums that control how visitors should descend into the tree. Each visit method
can either break (stop the whole visit flow), skip children (so only the exit_
fires) or descend (the default). This also refactors the various consumers to
take advantage of this new feature, including the selector engine in csskit_ast.
@keithamus
keithamus force-pushed the implement-visitflow branch from 7cec54f to ec58c93 Compare July 4, 2026 09:09
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

✅ CI passed

Job Result
Build & Test (win32-x64, win32-arm64, linux-x64, linux-arm64, darwin-x64, darwin-arm64) ✅ success
Build & Test (default features) ✅ success
Build & Test (nightly) ✅ success
Build each library ✅ success
Build benches ✅ success
Acceptance Tests ✅ success
Fuzz Corpus Replay ✅ success

@keithamus
keithamus merged commit 2cc1459 into main Jul 4, 2026
18 of 19 checks passed
@keithamus
keithamus deleted the implement-visitflow branch July 4, 2026 13:09
github-actions Bot pushed a commit that referenced this pull request Jul 4, 2026
## [0.0.27] - 2026-07-04

### Other Changes
- Fuzz: minimize corpus, and do so on nightly fuzz build (#1257) ([#1257](#1257))
- CI: Ensure benches build (#1259) ([#1259](#1259))

### Css_ast
- css_ast/css_parse: Improve peeking robustness. (#1238) ([#1238](#1238))
- Regenerate css_ast/src/values from csswg drafts (#1242) ([#1242](#1242))
- Regenerate css_ast/src/values from csswg drafts (#1254) ([#1254](#1254))
- fuzz: new parser findings 2026-06-19 (#1232) ([#1232](#1232))
- css_ast: Refactor assert_specificity to use closure pattern (#1261) ([#1261](#1261))
- css_ast: derive(ToSpan) on WebkitFunctionalPseudoClass (#1262) ([#1262](#1262))
- Implement "VisitFlow" (#1263) ([#1263](#1263))

### Css_parse
- fuzz: new parser findings 2026-07-01 (#1260) ([#1260](#1260))

### Csskit
- chore(deps): update dependencies (patch) (#1243) ([#1243](#1243))

### Csskit_derives
- chore(deps): update rust crate itertools to 0.15.0 (#1246) ([#1246](#1246))

### Csskit_vscode
- chore(deps): update dependencies to v1.68.0 (#1247) ([#1247](#1247))
- fix(deps): update dependencies (patch) (#1255) ([#1255](#1255))

[forcebuild]
@keithamus keithamus mentioned this pull request Jul 4, 2026
github-actions Bot pushed a commit that referenced this pull request Jul 4, 2026
## [0.0.27] - 2026-07-04

### Other Changes
- Fuzz: minimize corpus, and do so on nightly fuzz build (#1257) ([#1257](#1257))
- CI: Ensure benches build (#1259) ([#1259](#1259))

### Css_ast
- css_ast/css_parse: Improve peeking robustness. (#1238) ([#1238](#1238))
- Regenerate css_ast/src/values from csswg drafts (#1242) ([#1242](#1242))
- Regenerate css_ast/src/values from csswg drafts (#1254) ([#1254](#1254))
- fuzz: new parser findings 2026-06-19 (#1232) ([#1232](#1232))
- css_ast: Refactor assert_specificity to use closure pattern (#1261) ([#1261](#1261))
- css_ast: derive(ToSpan) on WebkitFunctionalPseudoClass (#1262) ([#1262](#1262))
- Implement "VisitFlow" (#1263) ([#1263](#1263))

### Css_parse
- fuzz: new parser findings 2026-07-01 (#1260) ([#1260](#1260))

### Csskit
- chore(deps): update dependencies (patch) (#1243) ([#1243](#1243))

### Csskit_derives
- chore(deps): update rust crate itertools to 0.15.0 (#1246) ([#1246](#1246))

### Csskit_vscode
- chore(deps): update dependencies to v1.68.0 (#1247) ([#1247](#1247))
- fix(deps): update dependencies (patch) (#1255) ([#1255](#1255))
keithamus added a commit that referenced this pull request Jul 4, 2026
## [0.0.27] - 2026-07-04

### Other Changes
- Fuzz: minimize corpus, and do so on nightly fuzz build (#1257)
([#1257](#1257))
- CI: Ensure benches build (#1259)
([#1259](#1259))


### Css_ast
- css_ast/css_parse: Improve peeking robustness. (#1238)
([#1238](#1238))
- Regenerate css_ast/src/values from csswg drafts (#1242)
([#1242](#1242))
- Regenerate css_ast/src/values from csswg drafts (#1254)
([#1254](#1254))
- fuzz: new parser findings 2026-06-19 (#1232)
([#1232](#1232))
- css_ast: Refactor assert_specificity to use closure pattern (#1261)
([#1261](#1261))
- css_ast: derive(ToSpan) on WebkitFunctionalPseudoClass (#1262)
([#1262](#1262))
- Implement "VisitFlow" (#1263)
([#1263](#1263))


### Css_parse
- fuzz: new parser findings 2026-07-01 (#1260)
([#1260](#1260))


### Csskit
- chore(deps): update dependencies (patch) (#1243)
([#1243](#1243))


### Csskit_derives
- chore(deps): update rust crate itertools to 0.15.0 (#1246)
([#1246](#1246))


### Csskit_vscode
- chore(deps): update dependencies to v1.68.0 (#1247)
([#1247](#1247))
- fix(deps): update dependencies (patch) (#1255)
([#1255](#1255))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant