You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(ast_tools/formatter): compile list of no following nodes as TypeIds (#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.
0 commit comments