Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ast_codegen, ast): visit ExpressionArrayElement as Expression. #4061

Conversation

rzvxa
Copy link
Contributor

@rzvxa rzvxa commented Jul 5, 2024

hotfix for #4060

I just added an edge case, We can come back to it later on and make it a standard in our codegen.

The diff is big because it causes the code to reorder, The edge case generated code doesn't follow the order in which they are defined in the source of truth(eg js.rs)

Copy link

graphite-app bot commented Jul 5, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-ast Area - AST label Jul 5, 2024
Copy link
Contributor Author

rzvxa commented Jul 5, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @rzvxa and the rest of your teammates on Graphite Graphite

@rzvxa rzvxa force-pushed the 07-05-fix_ast_codegen_ast_visit_expressionarrayelement_as_expression_ branch from 2ee7657 to ec5bfd0 Compare July 5, 2024 15:49
@rzvxa rzvxa requested a review from Boshen July 5, 2024 15:49
@rzvxa rzvxa marked this pull request as ready for review July 5, 2024 15:49
@Dunqing
Copy link
Member

Dunqing commented Jul 5, 2024

Not just Expression, we need to visit the corresponding AST for all @inherit XXX

Copy link

codspeed-hq bot commented Jul 5, 2024

CodSpeed Performance Report

Merging #4061 will improve performances by 6.49%

Comparing 07-05-fix_ast_codegen_ast_visit_expressionarrayelement_as_expression_ (cb78ece) with 07-05-fix_ast_codegen_ast_visit_expressionarrayelement_as_expression_ (ec5bfd0)

Summary

⚡ 2 improvements
✅ 26 untouched benchmarks

Benchmarks breakdown

Benchmark 07-05-fix_ast_codegen_ast_visit_expressionarrayelement_as_expression_ 07-05-fix_ast_codegen_ast_visit_expressionarrayelement_as_expression_ Change
prepass[react.development.js] 218.3 µs 207.1 µs +5.45%
prepass[typescript.js] 29.1 ms 27.3 ms +6.49%

@rzvxa
Copy link
Contributor Author

rzvxa commented Jul 5, 2024

Not just Expression, we need to visit the corresponding AST for all @inherit XXX

We already do this for the inherited enums, ExpressionArrayElement is special because it doesn't exist, I use the visit_as attribute to visit an arbitrary Expression as a non-existing type ExpressionArrayElement, That's actually what causes this bug, Since I was generating a new walk for this based on the Expression supertype.

It also happens in FinallyClause and ClassHeritage but those 2 are structures so It doesn't need to consider inheritance.
For now, I used an edge case, But we should standardize the behavior or visit_as on enums to act this way out of the gate.


Edit:

Here is an example:

pub fn walk_argument<'a, V: Visit<'a>>(visitor: &mut V, it: &Argument<'a>) {
let kind = AstKind::Argument(visitor.alloc(it));
visitor.enter_node(kind);
match it {
Argument::SpreadElement(it) => visitor.visit_spread_element(it),
match_expression!(Argument) => visitor.visit_expression(it.to_expression()),
}
visitor.leave_node(kind);
}

@Dunqing
Copy link
Member

Dunqing commented Jul 5, 2024

Thanks for the explanation, I see the root cause

@rzvxa
Copy link
Contributor Author

rzvxa commented Jul 5, 2024

Thanks for the explanation, I see the root cause

Your question actually showed me another edge case, ClassHeritage is also an alias for Expression I have to add that one to our edge case too.

@Boshen Boshen merged commit aa585d3 into main Jul 5, 2024
24 checks passed
@Boshen Boshen deleted the 07-05-fix_ast_codegen_ast_visit_expressionarrayelement_as_expression_ branch July 5, 2024 16:29
@Boshen
Copy link
Member

Boshen commented Jul 5, 2024

Confirmed in Rolldown by testing locally.

@github-actions github-actions bot mentioned this pull request Jul 6, 2024
Boshen added a commit that referenced this pull request Jul 6, 2024
## [0.17.1] - 2024-07-06

### Bug Fixes

- aa585d3 ast_codegen, ast: Visit `ExpressionArrayElement` as
`Expression`. (#4061) (rzvxa)
- 564a75a codegen: Missing TypeParameters in TSConstructSignature
(#4063) (michaelm)
- adee728 isolated_declarations: Don't report an error for parameters if
they are ObjectPattern or ArrayPattern with an explicit type (#4065)
(michaelm)
- 1b8f208 isolated_declarations: Correct emit for private static methods
(#4064) (michaelm)
- 719fb96 minifier: Omit dce `undefined` which can be a shadowed
variable (#4073) (Boshen)
- 150f4d9 napi/transform: Display error with spanned messages (Boshen)

### Performance

- 7fe2a2f parser: Do not copy comments (#4067) (overlookmotel)

### Refactor

- 8fa98e0 ast: Inline trivial functions and shorten code (#4066)
(overlookmotel)
- 65aee19 isolated-declarations: Reorganize scope tree (#4070) (Luca
Bruno)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area - AST
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants