refactor(ast_macros): calculate which enums are fieldless in ast_tools#23957
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
916651c to
ee3fd99
Compare
f8f702a to
796ff09
Compare
|
@claude review |
Merge activity
|
796ff09 to
3a843c0
Compare
…ls` (#23957) Move work from `#[ast]` macro into `ast_tools`. Calculate whether an enum is fieldless or not in `ast_tools` and pass that info to `#[ast]` macro via an `EnumDetails` struct. This avoids having to iterate over all variants of each enum in the macro. This is preferable because `ast_tools` runs only after changes to AST, whereas the macro code runs every time `oxc_ast` crate is compiled.
ee3fd99 to
735949f
Compare
…#23958) Similar to #23957. Move work from `#[ast]` macro into `ast_tools`. Calculate whether a struct can be marked `#[repr(transparent)]` or not in `ast_tools` and pass that info to `#[ast]` macro via the `StructDetails` struct. This has 2 advantages: 1. Avoids having to iterate over all fields of each struct in the macro. 2. It's more accurate. `ast_tools` knows the size of fields, so it can exclude ZST fields from the count. A struct like this will now be marked `#[repr(transparent)]` despite having more than 1 field, because 2 of the fields contain ZSTs: ```rust struct Foo<'a> { num: u32, _align: [usize; 0], _marker: PhantomData<&'a ()>, } ``` Moving work from macro into `ast_tools` is preferable because `ast_tools` runs only after changes to AST, whereas the macro code runs every time `oxc_ast` crate is compiled.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…ls` (#23957) Move work from `#[ast]` macro into `ast_tools`. Calculate whether an enum is fieldless or not in `ast_tools` and pass that info to `#[ast]` macro via an `EnumDetails` struct. This avoids having to iterate over all variants of each enum in the macro. This is preferable because `ast_tools` runs only after changes to AST, whereas the macro code runs every time `oxc_ast` crate is compiled.
735949f to
e94b6cd
Compare
3a843c0 to
287a0c3
Compare
…#23958) Similar to #23957. Move work from `#[ast]` macro into `ast_tools`. Calculate whether a struct can be marked `#[repr(transparent)]` or not in `ast_tools` and pass that info to `#[ast]` macro via the `StructDetails` struct. This has 2 advantages: 1. Avoids having to iterate over all fields of each struct in the macro. 2. It's more accurate. `ast_tools` knows the size of fields, so it can exclude ZST fields from the count. A struct like this will now be marked `#[repr(transparent)]` despite having more than 1 field, because 2 of the fields contain ZSTs: ```rust struct Foo<'a> { num: u32, _empty: [u8; 0], _marker: PhantomData<&'a ()>, } ``` Moving work from macro into `ast_tools` is preferable because `ast_tools` runs only after changes to AST, whereas the macro code runs every time `oxc_ast` crate is compiled.
…ls` (#23957) Move work from `#[ast]` macro into `ast_tools`. Calculate whether an enum is fieldless or not in `ast_tools` and pass that info to `#[ast]` macro via an `EnumDetails` struct. This avoids having to iterate over all variants of each enum in the macro. This is preferable because `ast_tools` runs only after changes to AST, whereas the macro code runs every time `oxc_ast` crate is compiled.
…#23958) Similar to #23957. Move work from `#[ast]` macro into `ast_tools`. Calculate whether a struct can be marked `#[repr(transparent)]` or not in `ast_tools` and pass that info to `#[ast]` macro via the `StructDetails` struct. This has 2 advantages: 1. Avoids having to iterate over all fields of each struct in the macro. 2. It's more accurate. `ast_tools` knows the size of fields, so it can exclude ZST fields from the count. A struct like this will now be marked `#[repr(transparent)]` despite having more than 1 field, because 2 of the fields contain ZSTs: ```rust struct Foo<'a> { num: u32, _empty: [u8; 0], _marker: PhantomData<&'a ()>, } ``` Moving work from macro into `ast_tools` is preferable because `ast_tools` runs only after changes to AST, whereas the macro code runs every time `oxc_ast` crate is compiled.

Move work from
#[ast]macro intoast_tools. Calculate whether an enum is fieldless or not inast_toolsand pass that info to#[ast]macro via anEnumDetailsstruct. This avoids having to iterate over all variants of each enum in the macro.This is preferable because
ast_toolsruns only after changes to AST, whereas the macro code runs every timeoxc_astcrate is compiled.