Skip to content

refactor(ast): calculate which structs are transparent in ast_tools#23958

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_
Jun 30, 2026
Merged

refactor(ast): calculate which structs are transparent in ast_tools#23958
graphite-app[bot] merged 1 commit into
mainfrom
om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jun 30, 2026

Copy link
Copy Markdown
Member

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:

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.

overlookmotel commented Jun 30, 2026

Copy link
Copy Markdown
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 changes, fast-track this PR to the front of 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-hq

codspeed-hq Bot commented Jun 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_ (ca13cdd) with main (e94b6cd)2

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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

@overlookmotel overlookmotel self-assigned this Jun 30, 2026
@overlookmotel
overlookmotel marked this pull request as ready for review June 30, 2026 10:09
Copilot AI review requested due to automatic review settings June 30, 2026 10:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@overlookmotel
overlookmotel force-pushed the om/06-29-refactor_ast_macros_calculate_which_enums_are_fieldless_in_ast_tools_ branch from 916651c to ee3fd99 Compare June 30, 2026 10:12
@overlookmotel
overlookmotel force-pushed the om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_ branch from 9d0721b to e575745 Compare June 30, 2026 10:12
@overlookmotel

Copy link
Copy Markdown
Member Author

@claude review

@graphite-app

graphite-app Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Merge activity

@graphite-app
graphite-app Bot force-pushed the om/06-29-refactor_ast_macros_calculate_which_enums_are_fieldless_in_ast_tools_ branch from ee3fd99 to 735949f Compare June 30, 2026 13:09
graphite-app Bot pushed a commit that referenced this pull request Jun 30, 2026
…#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.
@graphite-app
graphite-app Bot force-pushed the om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_ branch from e575745 to d9a1829 Compare June 30, 2026 13:10
@camc314

camc314 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9a1829a1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread tasks/ast_tools/src/generators/assert_layouts.rs Outdated
@overlookmotel
overlookmotel force-pushed the om/06-29-refactor_ast_macros_calculate_which_enums_are_fieldless_in_ast_tools_ branch from 735949f to e94b6cd Compare June 30, 2026 14:47
@overlookmotel
overlookmotel force-pushed the om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_ branch from d9a1829 to a30c73f Compare June 30, 2026 14:47
Base automatically changed from om/06-29-refactor_ast_macros_calculate_which_enums_are_fieldless_in_ast_tools_ to main June 30, 2026 16:31
…#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.
@graphite-app
graphite-app Bot force-pushed the om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_ branch from a30c73f to ca13cdd Compare June 30, 2026 16:32
@graphite-app
graphite-app Bot merged commit ca13cdd into main Jun 30, 2026
38 checks passed
@graphite-app
graphite-app Bot deleted the om/06-29-refactor_ast_calculate_which_structs_are_transparent_in_ast_tools_ branch June 30, 2026 16:40
camc314 pushed a commit that referenced this pull request Jul 3, 2026
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants