refactor(ast): remove inherit_variants! macro#23960
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
fb873ae to
36bf6df
Compare
36bf6df to
77fd40f
Compare
0f34447 to
42dd69e
Compare
|
@claude review |
Merge activity
|
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.
42dd69e to
f7e10d3
Compare
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.
77fd40f to
ae158ec
Compare
|
@codex review |
There was a problem hiding this comment.
💡 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".
f7e10d3 to
c604411
Compare
ae158ec to
c16f762
Compare
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.
c604411 to
37cbf88
Compare
c16f762 to
be17950
Compare
…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.
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.
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.

Remove the
inherit_variants!macro fromoxc_ast.Before:
After:
The way it works now is that
ast_toolsgenerates the data the#[ast]macro needs to add the inherited enum variants, and#[ast]macro uses that data to add the variants (fromMemberExpression, in this case).This has a few advantages:
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.MemberExpressioninINHERIT(MemberExpression<'a>)now jumps toMemberExpression's definition.Only changes the means by which enum inheritance is implemented, does not change how it operates.