perf(ast): use bitflags for storing comment newline state#11096
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #11096 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the custom CommentNewlines enum with a bitflags-based struct for simpler flag manipulation and updates all usages to the new constants.
- Introduces
bitflagsforCommentNewlinesincrates/oxc_ast/src/ast/comment.rs - Rewrites newline setter/getter logic to use
insert/remove/contains - Updates test fixtures in
crates/oxc_parser/src/lexer/trivia_builder.rsto reference new flag names
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_ast/src/ast/comment.rs | Replaced enum with bitflags for newline state and updated related impls |
| crates/oxc_parser/src/lexer/trivia_builder.rs | Updated expected comment newlines in tests to use new CommentNewlines constants |
1105ff9 to
3f90352
Compare
overlookmotel
left a comment
There was a problem hiding this comment.
Great. Thank you for persisting, despite my misdirection (twice!)
Merge activity
|
- supersedes #11090 This switches the newline flags to using `bitflags` to make the setting of the flags a little bit simpler and also makes checking the flag state easier too. Rather than using all flags in a bitflags, this is simpler because we don't need a custom serializer for comments for ESTree.
3f90352 to
6571b9b
Compare
Follow-on after #11096. Add `#[inline]` to these trivial functions. Usually they're called with a static value, so if they're inlined compiler will be able to remove the branch. Probably compiler would inline these anyway as they're so small, but just to make sure.
Follow-on after #11096. Pure refactor. Our naming convention for `bitflags!` fields is not completely consistent, but mostly we use mixed case. Rename them to match that style. Also, remove the `LEADING_AND_TRAILING` option, as it's only used in tests.
Follow-on after #11096. Pure refactor. Shorten the setter methods. Also move them to after the getters and in same order.

This switches the newline flags to using
bitflagsto make the setting of the flags a little bit simpler and also makes checking the flag state easier too. Rather than using all flags in a bitflags, this is simpler because we don't need a custom serializer for comments for ESTree.