Skip to content

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Aug 7, 2025

No description provided.

Copy link
Member Author

Dunqing commented Aug 7, 2025


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 Aug 7, 2025

CodSpeed Instrumentation Performance Report

Merging #12864 will not alter performance

Comparing 08-07-feat_formatter_correct_ast_nodes_generator (bfacd66) with 08-07-feat_formatter_correct_formatting_for_trystatement (248fd94)

Summary

✅ 34 untouched benchmarks

@Dunqing Dunqing marked this pull request as ready for review August 7, 2025 07:18
@Dunqing Dunqing requested a review from overlookmotel as a code owner August 7, 2025 07:18
@Dunqing Dunqing removed the request for review from overlookmotel August 7, 2025 07:18
@Dunqing Dunqing force-pushed the 08-07-feat_formatter_correct_formatting_for_trystatement branch from a5bd6b4 to dd5283c Compare August 7, 2025 07:28
@Dunqing Dunqing force-pushed the 08-07-feat_formatter_correct_ast_nodes_generator branch from 30dcb9e to de8558f Compare August 7, 2025 07:28
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Aug 7, 2025
Copy link
Member

Boshen commented Aug 7, 2025

Merge activity

@Dunqing Dunqing force-pushed the 08-07-feat_formatter_correct_formatting_for_trystatement branch from dd5283c to 76de684 Compare August 7, 2025 14:13
@Dunqing Dunqing force-pushed the 08-07-feat_formatter_correct_ast_nodes_generator branch from de8558f to 40affe9 Compare August 7, 2025 14:13
@graphite-app graphite-app bot force-pushed the 08-07-feat_formatter_correct_formatting_for_trystatement branch from 76de684 to 56ecd0a Compare August 7, 2025 14:28
@graphite-app graphite-app bot force-pushed the 08-07-feat_formatter_correct_ast_nodes_generator branch from 40affe9 to 00f736a Compare August 7, 2025 14:29
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 7, 2025
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Aug 7, 2025
@graphite-app graphite-app bot force-pushed the 08-07-feat_formatter_correct_formatting_for_trystatement branch from 56ecd0a to ce27298 Compare August 7, 2025 14:59
@graphite-app graphite-app bot force-pushed the 08-07-feat_formatter_correct_ast_nodes_generator branch from 00f736a to 8316ceb Compare August 7, 2025 15:00
@graphite-app graphite-app bot force-pushed the 08-07-feat_formatter_correct_formatting_for_trystatement branch from ce27298 to 248fd94 Compare August 7, 2025 15:06
@graphite-app graphite-app bot force-pushed the 08-07-feat_formatter_correct_ast_nodes_generator branch from 8316ceb to bfacd66 Compare August 7, 2025 15:06
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 7, 2025
Base automatically changed from 08-07-feat_formatter_correct_formatting_for_trystatement to main August 7, 2025 15:17
@graphite-app graphite-app bot merged commit bfacd66 into main Aug 7, 2025
27 checks passed
@graphite-app graphite-app bot deleted the 08-07-feat_formatter_correct_ast_nodes_generator branch August 7, 2025 15:18
graphite-app bot pushed a commit that referenced this pull request Aug 9, 2025
Follow-on after #12864. Pure refactor, does not alter generated code.

Shorten code by using `Schema::type_by_name` and `EnumDef::all_variants` methods.

`EnumDef::all_variants` iterates over all variants of an enum, including inherited variants. As well as being shorter, it also correctly handles multiple layers of inheritance e.g. if `X` inherits variants from `Y`, and `Y` inherits variants from `Z`.

In the case of `Statement`, inheritance is only 1 level deep, so it makes no difference - but it might if we change the AST later on.
graphite-app bot pushed a commit that referenced this pull request Aug 9, 2025
…`TypeId`s (#12930)

Follow-on after #12864. Pure refactor - does not alter generated code.

There's a couple of things going on in this PR.

Firstly, perf:

* Prefer comparing `TypeId`s over string comparison, because it's cheaper.
* Compile a single `Vec` of all types which have no following node at the start (including those listed in `AST_NODE_WITHOUT_FOLLOWING_NODE_LIST`), rather than checking 2 `Vec`s each time in `generate_struct_impls`.

Secondly, the code previously was relying on the fact that almost all of `Statement`s variants have the same name as the types those variants contain e.g.:

```rs
pub enum Statement<'a> {
    BlockStatement(Box<'a, BlockStatement<'a>>),
    // ...
}
```

But that the names match is a bit of a co-incidence. This PR makes it so we don't rely on that co-incidence, and instead makes the "no following node" list from the actual *types* of the variants.

This change reveals a side-effect of the previous behavior which may or may not be intentional. The only variants of `Statement` where the name of the variant and name of the *type* of the variant don't match are `Function` and `Class`.

To maintain the same output as before, I've added an exclude list `AST_NODE_WITH_FOLLOWING_NODE_LIST` containing these 2 types.

Presumably the reason why these 2 need an exclusion is because `Function` and `Class` can be either a `Statement` or an `Expression`. I don't know if this may be problematic and might need logic elsewhere to handle them differently, depending on the context?

Note: `TypeDef::innermost_type` is to get the `TypeId` of the inner type of a variant (e.g. `BlockStatement`), rather than the type which is the actual enum variant (e.g. `Box<BlockStatement>`).

@Dunqing I don't know the formatter at all, so these changes may be unhelpful. Feel free to close or modify this PR if so.
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
Follow-on after oxc-project#12864. Pure refactor, does not alter generated code.

Shorten code by using `Schema::type_by_name` and `EnumDef::all_variants` methods.

`EnumDef::all_variants` iterates over all variants of an enum, including inherited variants. As well as being shorter, it also correctly handles multiple layers of inheritance e.g. if `X` inherits variants from `Y`, and `Y` inherits variants from `Z`.

In the case of `Statement`, inheritance is only 1 level deep, so it makes no difference - but it might if we change the AST later on.
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
…`TypeId`s (oxc-project#12930)

Follow-on after oxc-project#12864. Pure refactor - does not alter generated code.

There's a couple of things going on in this PR.

Firstly, perf:

* Prefer comparing `TypeId`s over string comparison, because it's cheaper.
* Compile a single `Vec` of all types which have no following node at the start (including those listed in `AST_NODE_WITHOUT_FOLLOWING_NODE_LIST`), rather than checking 2 `Vec`s each time in `generate_struct_impls`.

Secondly, the code previously was relying on the fact that almost all of `Statement`s variants have the same name as the types those variants contain e.g.:

```rs
pub enum Statement<'a> {
    BlockStatement(Box<'a, BlockStatement<'a>>),
    // ...
}
```

But that the names match is a bit of a co-incidence. This PR makes it so we don't rely on that co-incidence, and instead makes the "no following node" list from the actual *types* of the variants.

This change reveals a side-effect of the previous behavior which may or may not be intentional. The only variants of `Statement` where the name of the variant and name of the *type* of the variant don't match are `Function` and `Class`.

To maintain the same output as before, I've added an exclude list `AST_NODE_WITH_FOLLOWING_NODE_LIST` containing these 2 types.

Presumably the reason why these 2 need an exclusion is because `Function` and `Class` can be either a `Statement` or an `Expression`. I don't know if this may be problematic and might need logic elsewhere to handle them differently, depending on the context?

Note: `TypeDef::innermost_type` is to get the `TypeId` of the inner type of a variant (e.g. `BlockStatement`), rather than the type which is the actual enum variant (e.g. `Box<BlockStatement>`).

@Dunqing I don't know the formatter at all, so these changes may be unhelpful. Feel free to close or modify this PR if so.
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 A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants