-
-
Notifications
You must be signed in to change notification settings - Fork 722
refactor(lexer): simplify byte handler macros #13057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(lexer): simplify byte handler macros #13057
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 #13057 will improve performances by 3.09%Comparing Summary
Benchmarks breakdown
Footnotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the byte handler macros in the lexer to simplify the generated code structure and improve readability. The changes eliminate unnecessary const wrappers, remove the intermediate byte_handler! macro, and reduce code duplication by hoisting common imports.
- Remove const wrappers from generated byte handler functions
- Eliminate the
byte_handler!macro and inline its functionality into the remaining macros - Hoist
use oxc_data_structures::assert_unchecked;to the top of the file to avoid repetition
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Merge activity
|
Pure refactor. Simplify the byte handler macros in lexer in 3 ways:
#### 1. Remove the `const BLAH: ByteHandler = { ... };` wrappers from generated code
I don't think they're necessary, and I'm not sure why I put them there in the first place.
Before:
```rs
const UNI: ByteHandler = {
#[expect(non_snake_case)]
fn UNI(lexer: &mut Lexer) -> Kind {
lexer.unicode_char_handler()
}
UNI
};
```
After:
```rs
#[expect(non_snake_case)]
fn UNI(lexer: &mut Lexer) -> Kind {
lexer.unicode_char_handler()
}
```
Each byte handler still has a useful name in CodSpeed flame graphs after this change.
#### 2. Remove the `byte_handler!` macro.
`ascii_byte_handler!` and `ascii_identifier_handler!` macros remain, but they no longer use `byte_handler!` macro internally.
Removing the macro-within-macro pattern may make this code easier for AI to understand (and probably ditto for humans!).
#### 3. Shorten macro expansion
Hoist `use oxc_data_structures::assert_unchecked;` to top of file, so it doesn't need to be repeated in each macro expansion.
102c916 to
fdfec21
Compare

Pure refactor. Simplify the byte handler macros in lexer in 3 ways:
1. Remove the
const BLAH: ByteHandler = { ... };wrappers from generated codeI don't think they're necessary, and I'm not sure why I put them there in the first place.
Before:
After:
Each byte handler still has a useful name in CodSpeed flame graphs after this change.
2. Remove the
byte_handler!macro.ascii_byte_handler!andascii_identifier_handler!macros remain, but they no longer usebyte_handler!macro internally.Removing the macro-within-macro pattern may make this code easier for AI to understand (and probably ditto for humans!).
3. Shorten macro expansion
Hoist
use oxc_data_structures::assert_unchecked;to top of file, so it doesn't need to be repeated in each macro expansion.