Skip to content

feat(data_structures): add fieldless_enum! macro#19876

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/03-01-feat_data_structures_add_fieldless_enum_macro
Mar 1, 2026
Merged

feat(data_structures): add fieldless_enum! macro#19876
graphite-app[bot] merged 1 commit intomainfrom
om/03-01-feat_data_structures_add_fieldless_enum_macro

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 1, 2026

Add a fieldless_enum! macro. This macro generates a VARIANTS constant on the type that lists all the enum's variants.

fieldless_enum! {
    enum Foo {
        A,
        B,
        C,
    }
}

assert_eq!(Foo::VARIANTS, [Foo::A, Foo::B, Foo::C]);

This is useful for code which interacts with the enum, and needs to take some action on each variant.

Copy link
Member Author

overlookmotel commented Mar 1, 2026


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 Mar 1, 2026

Merging this PR will improve performance by 55.06%

⚡ 2 improved benchmarks
✅ 50 untouched benchmarks
🆕 1 new benchmark
⏩ 3 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation mangler[RadixUIAdoptionSection.jsx_keep_names] 20.3 µs 19.6 µs +3.3%
🆕 Simulation estree_tokens_raw[checker.ts] N/A 17.2 ms N/A
Simulation estree_tokens[checker.ts] 127.7 ms 82.3 ms +55.06%

Comparing om/03-01-feat_data_structures_add_fieldless_enum_macro (0442a25) with om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ (a0c0e12)

Open in CodSpeed

Footnotes

  1. 3 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.

@overlookmotel overlookmotel changed the base branch from om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ to graphite-base/19876 March 1, 2026 12:59
@overlookmotel overlookmotel self-assigned this Mar 1, 2026
@overlookmotel overlookmotel force-pushed the om/03-01-feat_data_structures_add_fieldless_enum_macro branch from 0442a25 to b270112 Compare March 1, 2026 13:18
@overlookmotel overlookmotel marked this pull request as ready for review March 1, 2026 13:23
Copilot AI review requested due to automatic review settings March 1, 2026 13:23
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

Adds a new optional fieldless_enum! macro to oxc_data_structures (behind a feature flag) to generate fieldless enums that expose a const VARIANTS array of all variants, enabling const-context iteration-like behavior.

Changes:

  • Introduces fieldless_enum! macro and unit tests under a new fieldless_enum feature.
  • Exposes the new module behind cfg(feature = "fieldless_enum") and wires the feature into the crate’s all feature set.
  • Documents the capability in the crate README.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_data_structures/src/lib.rs Feature-gated export of the new fieldless_enum module.
crates/oxc_data_structures/src/fieldless_enum.rs Implements and exports the fieldless_enum! macro + tests.
crates/oxc_data_structures/README.md Adds the macro to the “Key Features” list.
crates/oxc_data_structures/Cargo.toml Adds the fieldless_enum feature and includes it in all.

@overlookmotel overlookmotel changed the base branch from graphite-base/19876 to om/03-01-feat_parser_make_all_kind_is__methods_const_ March 1, 2026 16:04
@overlookmotel overlookmotel changed the base branch from om/03-01-feat_parser_make_all_kind_is__methods_const_ to graphite-base/19876 March 1, 2026 16:40
@overlookmotel overlookmotel force-pushed the om/03-01-feat_data_structures_add_fieldless_enum_macro branch from b270112 to 9715ef3 Compare March 1, 2026 17:27
@overlookmotel overlookmotel changed the base branch from graphite-base/19876 to main March 1, 2026 17:27
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 1, 2026
@overlookmotel overlookmotel force-pushed the om/03-01-feat_data_structures_add_fieldless_enum_macro branch from 9715ef3 to 904602d Compare March 1, 2026 17:29
@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 1, 2026

Merge activity

Add a `fieldless_enum!` macro. This macro generates a `VARIANTS` constant on the type that lists all the enum's variants.

```rs
fieldless_enum! {
    enum Foo {
        A,
        B,
        C,
    }
}

assert_eq!(Foo::VARIANTS, [Foo::A, Foo::B, Foo::C]);
```

This is useful for code which interacts with the enum, and needs to take some action on each variant.
@graphite-app graphite-app bot force-pushed the om/03-01-feat_data_structures_add_fieldless_enum_macro branch from 904602d to b3dceae Compare March 1, 2026 17:40
graphite-app bot pushed a commit that referenced this pull request Mar 1, 2026
…cro (#19877)

Use the `fieldless_enum!` macro introduced in #19876 to add a `VARIANTS` const to `Kind`. This is required for raw transfer of tokens.
@graphite-app graphite-app bot merged commit b3dceae into main Mar 1, 2026
22 checks passed
@graphite-app graphite-app bot deleted the om/03-01-feat_data_structures_add_fieldless_enum_macro branch March 1, 2026 17:46
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants