Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 13, 2025

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:

const UNI: ByteHandler = {
    #[expect(non_snake_case)]
    fn UNI(lexer: &mut Lexer) -> Kind {
        lexer.unicode_char_handler()
    }
    UNI
};

After:

#[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.

@github-actions github-actions bot added A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Aug 13, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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-hq
Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed Instrumentation Performance Report

Merging #13057 will improve performances by 3.09%

Comparing 08-12-refactor_lexer_simplify_byte_handler_macros (fdfec21) with main (b0558a4)1

Summary

⚡ 1 improvements
✅ 33 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
minifier[cal.com.tsx] 34.1 ms 33.1 ms +3.09%

Footnotes

  1. No successful run was found on main (fdfec21) during the generation of this report, so b0558a4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel marked this pull request as ready for review August 13, 2025 11:57
Copilot AI review requested due to automatic review settings August 13, 2025 11:57
Copy link
Contributor

Copilot AI left a 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.

@overlookmotel overlookmotel requested a review from Boshen August 13, 2025 12:00
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Aug 13, 2025
Copy link
Member

Boshen commented Aug 13, 2025

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.
@graphite-app graphite-app bot force-pushed the 08-12-refactor_lexer_simplify_byte_handler_macros branch from 102c916 to fdfec21 Compare August 13, 2025 15:33
@graphite-app graphite-app bot merged commit fdfec21 into main Aug 13, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 08-12-refactor_lexer_simplify_byte_handler_macros branch August 13, 2025 15:38
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants