Skip to content

refactor(ast): remove inherit_variants! macro#23960

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

refactor(ast): remove inherit_variants! macro#23960
graphite-app[bot] merged 1 commit into
mainfrom
om/06-29-refactor_ast_remove_inherit_variants_macro

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jun 30, 2026

Copy link
Copy Markdown
Member

Remove the inherit_variants! macro from oxc_ast.

Before:

inherit_variants! {
    #[ast]
    pub enum Expression<'a> {
        // ... own variants ...
        INHERIT(MemberExpression<'a>),
    }
}

After:

#[ast]
pub enum Expression<'a> {
    // ... own variants ...
    INHERIT(MemberExpression<'a>),
}

The way it works now is that ast_tools generates the data the #[ast] macro needs to add the inherited enum variants, and #[ast] macro uses that data to add the variants (from MemberExpression, in this case).

This has a few advantages:

  • Wrapping enums in inherit_variants! { ... } was ugly. Now it's gone.
  • inherit_variants! macro no longer needs to be maintained by hand. Changes to AST will now be reflected automatically.
  • Inherited variants are auto-generated, so it's now statically guaranteed by codegen that variants' "payloads" and discriminants match between the inheriting and inherited enums, so we can remove 2000 lines of const assertions which checked this.
  • Better IDE experience. "Jump to definition" on MemberExpression in INHERIT(MemberExpression<'a>) now jumps to MemberExpression's definition.

Only changes the means by which enum inheritance is implemented, does not change how it operates.

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_remove_inherit_variants_macro (be17950) 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 (37cbf88) 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 force-pushed the om/06-29-refactor_ast_remove_inherit_variants_macro branch from fb873ae to 36bf6df Compare June 30, 2026 00:34
@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_remove_inherit_variants_macro branch from 36bf6df to 77fd40f Compare June 30, 2026 10:12
@overlookmotel
overlookmotel force-pushed the om/06-29-docs_ast_macros_document_fields_of_structdetails_ branch from 0f34447 to 42dd69e 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 Bot pushed a commit that referenced this pull request Jun 30, 2026
Change the syntax used to declare that one enum inherits the variants from another.

Before:

```rust
enum Expression<'a> {
    // ... own variants ...
    @inherit MemberExpression
}
```

After:

```rust
enum Expression<'a> {
    // ... own variants ...
    INHERIT(MemberExpression<'a>),
}
```

Reason for this change is that the latter is valid Rust code, and can be parsed normally by Rust compiler and `syn`.

This removes the need for custom parsing logic in `ast_tools` - now we can just use `syn`'s standard parser for enums.

The downside it that this complicates the `inherit_variants!` macro - this PR reimplements it as a TT-muncher. But this macro is removed entirely in a later PR (#23960).

No change to behavior - only affects _how_ inheritance is declared, not how it works.
@graphite-app
graphite-app Bot force-pushed the om/06-29-docs_ast_macros_document_fields_of_structdetails_ branch from 42dd69e to f7e10d3 Compare June 30, 2026 13:10
graphite-app Bot pushed a commit that referenced this pull request Jun 30, 2026
Remove the `inherit_variants!` macro from `oxc_ast`.

Before:

```rust
inherit_variants! {
    #[ast]
    pub enum Expression<'a> {
        // ... own variants ...
        INHERIT(MemberExpression<'a>),
    }
}
```

After:

```rust
#[ast]
pub enum Expression<'a> {
    // ... own variants ...
    INHERIT(MemberExpression<'a>),
}
```

The way it works now is that `ast_tools` generates the data the `#[ast]` macro needs to add the inherited enum variants, and `#[ast]` macro uses that data to add the variants (from `MemberExpression`, in this case).

This has a few advantages:

- Wrapping enums in `inherit_variants! { ... }` was ugly. Now it's gone.
- `inherit_variants!` macro no longer needs to be maintained by hand. Changes to AST will now be reflected automatically.
- Inherited variants are auto-generated, so it's now statically guaranteed by codegen that variants' "payloads" and discriminants match between the inheriting and inherited enums, so we can remove 2000 lines of const assertions which checked this.
- Better IDE experience. "Jump to definition" on `MemberExpression` in `INHERIT(MemberExpression<'a>)` now jumps to `MemberExpression`'s definition.

Only changes the _means_ by which enum inheritance is implemented, does not change how it operates.
@graphite-app
graphite-app Bot force-pushed the om/06-29-refactor_ast_remove_inherit_variants_macro branch from 77fd40f to ae158ec Compare June 30, 2026 13:11
@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: ae158ec2c7

ℹ️ 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/inherit_variants.rs
@overlookmotel
overlookmotel force-pushed the om/06-29-docs_ast_macros_document_fields_of_structdetails_ branch from f7e10d3 to c604411 Compare June 30, 2026 14:47
@overlookmotel
overlookmotel force-pushed the om/06-29-refactor_ast_remove_inherit_variants_macro branch from ae158ec to c16f762 Compare June 30, 2026 14:47
Remove the `inherit_variants!` macro from `oxc_ast`.

Before:

```rust
inherit_variants! {
    #[ast]
    pub enum Expression<'a> {
        // ... own variants ...
        INHERIT(MemberExpression<'a>),
    }
}
```

After:

```rust
#[ast]
pub enum Expression<'a> {
    // ... own variants ...
    INHERIT(MemberExpression<'a>),
}
```

The way it works now is that `ast_tools` generates the data the `#[ast]` macro needs to add the inherited enum variants, and `#[ast]` macro uses that data to add the variants (from `MemberExpression`, in this case).

This has a few advantages:

- Wrapping enums in `inherit_variants! { ... }` was ugly. Now it's gone.
- `inherit_variants!` macro no longer needs to be maintained by hand. Changes to AST will now be reflected automatically.
- Inherited variants are auto-generated, so it's now statically guaranteed by codegen that variants' "payloads" and discriminants match between the inheriting and inherited enums, so we can remove 2000 lines of const assertions which checked this.
- Better IDE experience. "Jump to definition" on `MemberExpression` in `INHERIT(MemberExpression<'a>)` now jumps to `MemberExpression`'s definition.

Only changes the _means_ by which enum inheritance is implemented, does not change how it operates.
@graphite-app
graphite-app Bot force-pushed the om/06-29-docs_ast_macros_document_fields_of_structdetails_ branch from c604411 to 37cbf88 Compare June 30, 2026 16:32
@graphite-app
graphite-app Bot force-pushed the om/06-29-refactor_ast_remove_inherit_variants_macro branch from c16f762 to be17950 Compare June 30, 2026 16:33
Base automatically changed from om/06-29-docs_ast_macros_document_fields_of_structdetails_ to main June 30, 2026 16:41
@graphite-app
graphite-app Bot merged commit be17950 into main Jun 30, 2026
41 checks passed
@graphite-app
graphite-app Bot deleted the om/06-29-refactor_ast_remove_inherit_variants_macro branch June 30, 2026 16:43
nhojb pushed a commit to raycast/oxc that referenced this pull request Jun 30, 2026
…3953)

Change the syntax used to declare that one enum inherits the variants from another.

Before:

```rust
enum Expression<'a> {
    // ... own variants ...
    @inherit MemberExpression
}
```

After:

```rust
enum Expression<'a> {
    // ... own variants ...
    INHERIT(MemberExpression<'a>),
}
```

Reason for this change is that the latter is valid Rust code, and can be parsed normally by Rust compiler and `syn`.

This removes the need for custom parsing logic in `ast_tools` - now we can just use `syn`'s standard parser for enums.

The downside it that this complicates the `inherit_variants!` macro - this PR reimplements it as a TT-muncher. But this macro is removed entirely in a later PR (oxc-project#23960).

No change to behavior - only affects _how_ inheritance is declared, not how it works.
camc314 pushed a commit that referenced this pull request Jul 3, 2026
Change the syntax used to declare that one enum inherits the variants from another.

Before:

```rust
enum Expression<'a> {
    // ... own variants ...
    @inherit MemberExpression
}
```

After:

```rust
enum Expression<'a> {
    // ... own variants ...
    INHERIT(MemberExpression<'a>),
}
```

Reason for this change is that the latter is valid Rust code, and can be parsed normally by Rust compiler and `syn`.

This removes the need for custom parsing logic in `ast_tools` - now we can just use `syn`'s standard parser for enums.

The downside it that this complicates the `inherit_variants!` macro - this PR reimplements it as a TT-muncher. But this macro is removed entirely in a later PR (#23960).

No change to behavior - only affects _how_ inheritance is declared, not how it works.
camc314 pushed a commit that referenced this pull request Jul 3, 2026
Remove the `inherit_variants!` macro from `oxc_ast`.

Before:

```rust
inherit_variants! {
    #[ast]
    pub enum Expression<'a> {
        // ... own variants ...
        INHERIT(MemberExpression<'a>),
    }
}
```

After:

```rust
#[ast]
pub enum Expression<'a> {
    // ... own variants ...
    INHERIT(MemberExpression<'a>),
}
```

The way it works now is that `ast_tools` generates the data the `#[ast]` macro needs to add the inherited enum variants, and `#[ast]` macro uses that data to add the variants (from `MemberExpression`, in this case).

This has a few advantages:

- Wrapping enums in `inherit_variants! { ... }` was ugly. Now it's gone.
- `inherit_variants!` macro no longer needs to be maintained by hand. Changes to AST will now be reflected automatically.
- Inherited variants are auto-generated, so it's now statically guaranteed by codegen that variants' "payloads" and discriminants match between the inheriting and inherited enums, so we can remove 2000 lines of const assertions which checked this.
- Better IDE experience. "Jump to definition" on `MemberExpression` in `INHERIT(MemberExpression<'a>)` now jumps to `MemberExpression`'s definition.

Only changes the _means_ by which enum inheritance is implemented, does not change how it operates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-ast-tools Area - AST tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants