-
-
Notifications
You must be signed in to change notification settings - Fork 631
refactor(ast): Remove AstKind
for MemberExpression
and replace with StaticMemberExpression
and PrivateFieldExpression
#11767
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
refactor(ast): Remove AstKind
for MemberExpression
and replace with StaticMemberExpression
and PrivateFieldExpression
#11767
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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 Instrumentation Performance ReportMerging #11767 will degrade performances by 13.21%Comparing Summary
Benchmarks breakdown
|
f4ef54b
to
c424ef3
Compare
be74684
to
929c466
Compare
AstKind
for StaticMemberExpression
AstKind
for MemberExpression
and replace with StaticMemberExpression
and PrivateFieldExpression
929c466
to
c9918bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we introduce a MemberExpression
enum so that we can go from AstKind
to MemberExpression
? it's such a common pattern in the ;linter
You mean something like? enum MemberExpressionKind<'a> {
ComputedMemberExpression(&'a ComputedMemberExpression<'a>),
StaticMemberExpression(&'a StaticMemberExpression<'a>),
PrivateFieldExpression(&'a PrivateFieldExpression<'a>),
} This kind of "enum narrowing" pattern could also be useful in many places. There's lots of code all over Oxc which checks somewhere that an That's both unperformant (unnecessary checks) and error-prone - we learn about mistakes when there's a panic, rather than getting a compile-time error. It'd be ideal if you could do something like: let expr: &Expression = get_expression_somehow();
if let Some(expr_literal) = expr.as_literal() {
// `expr_literal` is an `&ExpressionLiteral` enum which only has variants
// for `BooleanLiteral`, `StringLiteral` etc.
// Pass `expr_literal` to the next function, instead of passing `expr`.
} Like with the "enum inheritance" schema in AST, we could codegen these conversions and make them very cheap (just a check and transmute). |
I've written up the broader "enum narrowing" feature in oxc-project/backlog#166. But it'd be pretty simple to hand-code |
6e099bb
to
3616da5
Compare
c9918bc
to
eff56f2
Compare
crates/oxc_linter/src/rules/import/no_named_as_default_member.rs
Outdated
Show resolved
Hide resolved
1a880a3
to
3934a58
Compare
@camc314 @overlookmotel Thanks for the suggestion. I agree having the separate enum is a good idea, it makes the code a lot simpler and probably more maintainable in the future if ECMAScript should ever add more member expression types. I've gone ahead and manually implemented an API for this, but an autogenerated one in the future would be nice. |
Yeah enum narrowing would definitly be nice. But for this specific case, I think it's definitly worth having a member expr enum (even if temporary) for this case due to how heavily member expresssion/static member expression is used |
3616da5
to
48d83ab
Compare
3934a58
to
2d81011
Compare
2d81011
to
3075c3b
Compare
3075c3b
to
294664d
Compare
48d83ab
to
190e390
Compare
294664d
to
00195f8
Compare
I rebased this on main, and it's now broken. Looks like clash with #11790 which introduced a usage of |
00195f8
to
189fc00
Compare
I've pushed a commit to hopefully fix |
Conformance fail relates to formatter. Not sure how serious it is. |
189fc00
to
4aa6d5a
Compare
Merge activity
|
…th `StaticMemberExpression` and `PrivateFieldExpression` (#11767) - related to #11490 Replaces the current `AstKind::MemberExpression` with `StaticMemberExpresion` and `PrivateFieldExpression`. To make this change a little bit more ergonomic I've a new `MemberExpressionKind` which represents this subset of kinds.
4aa6d5a
to
87b8496
Compare
Follow-on after #11767. Small optimizations. * `PrivateFieldExpression` cannot have a static property name, so no need to test for it. * Replace branch which can never be taken with `unwrap()`. `unwrap()` should cause compiler to backtrack and prove that this branch cannot be taken, and remove the branch.
AstKind
consistent #11490Replaces the current
AstKind::MemberExpression
withStaticMemberExpresion
andPrivateFieldExpression
.To make this change a little bit more ergonomic I've a new
MemberExpressionKind
which represents this subset of kinds.