Skip to content

[Dot Shorthands] CFE Implementation #59758

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

Closed
5 tasks done
Tracked by #57036 ...
kallentu opened this issue Dec 18, 2024 · 1 comment
Closed
5 tasks done
Tracked by #57036 ...

[Dot Shorthands] CFE Implementation #59758

kallentu opened this issue Dec 18, 2024 · 1 comment
Assignees
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. feature-dot-shorthands Implementation of the dot shorthands feature. model-features General feature work in the analyzer and CFE.

Comments

@kallentu
Copy link
Member

kallentu commented Dec 18, 2024

Updates to the CFE (may be updated over time):

  • Parse and add listeners in body_builder
  • Add internal AST representing dot shorthands
  • ExpressionGenerator for dot shorthands to create those ASTs.
  • Type inference changes for finding the type
  • Errors and warnings

cc. @chloestefantsova @johnniwinther @stereotype441

@kallentu kallentu added area-fe-analyzer-shared legacy-area-front-end Legacy: Use area-dart-model instead. model-features General feature work in the analyzer and CFE. feature-dot-shorthands Implementation of the dot shorthands feature. labels Dec 18, 2024
@kallentu kallentu self-assigned this Dec 18, 2024
@kallentu kallentu changed the title [Enum Shorthands] CFE Implementation [Dot Shorthands] CFE Implementation Jan 31, 2025
copybara-service bot pushed a commit that referenced this issue Feb 18, 2025
Doing some initial work for parsing dot shorthands.

The listeners in the CFE and analyzer will report an extra error if the experiment is not turned on. The compilation should still fail and produce errors, but it won't crash.

If you turn on the experiment, the parsing will crash, but I'd like to get this in so I can modularly work on the CFE and analyzer separately.

Bug: #59758, #59835
Change-Id: I262b0bd5cffc8e5e04ac79c76454b6e355779ade
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409540
Reviewed-by: Jens Johansen <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
copybara-service bot pushed a commit that referenced this issue Feb 20, 2025
Two new internal ASTs for the CFE representing the entire dot shorthand expression (DotShorthand) and the dot shorthand head (DotShorthandPropertyGet) without arguments.
Static method invocations/constructor calls will be handled later.

Setting up the ASTS first, there's no tests yet. I'll use these in the upcoming CLs.

Bug: #59758
Change-Id: I91a052a3c954a00a424426d3be5c3007aaebc775
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410902
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
copybara-service bot pushed a commit that referenced this issue Feb 24, 2025
Using the type analyzer to cache a shorthand context type. This mechanism will be shared between the analyzer and the CFE.

There will be tests for this one the implementation strings through to this part. But otherwise, it's fairly straightforward logic.

Bug: #59758
Change-Id: I88ac8283d2901d7d141992ab5ab3a83e40be5912
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410943
Reviewed-by: Paul Berry <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Feb 26, 2025
Resolve static getters and tear-offs in dot shorthands.

Method and constructor invocations will come in a later CL. Also, looking to update the parser handling in a future CL, but we'll work incrementally.

Bug: #59758
Change-Id: I15c9eb7e531975ea19d496a03ac4b666fa15a04e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411940
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Feb 27, 2025
The parser was still WIP and was emitting an extra error, so this CL removes that error so tests can start passing and so I can properly test the new implementation e2e.

It still needs some fixes after the analyzer implementation is complete. The current extra synthetic tokens added in the parser are temporary to prevent crashes on the analyzer side when the experiment flag is turned off. But it works fine for now, and I'll clean it up in a CL when the feature is complete.

Bug: #59758
Change-Id: I83d8c840f66bedff4aa27a737a3f57e77d3973b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412344
Reviewed-by: Paul Berry <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Feb 28, 2025
This CL adds the work needed to be able to use dot shorthands with extension types.

Also, there's some additional work to set `isSetter` to false for dot shorthands. Static setters don't work together with shorthands.

Bug: #59758
Change-Id: I2c14606cf2970ee249f48189c686ea5cb963df0b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412784
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 4, 2025
This CL adds the resolution of dot shorthand invocations.

At the point of parsing, we can't be sure whether the invocation is a method invocation or a constructor invocation. We'll resolve the name with the given context type to find out.

Bug: #59758
Change-Id: I136ab6c7522fe24d98a4613d102089d50c4cd8cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412800
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 6, 2025
This CL adds the ability to handle == with dot shorthands in regular equality expressions and then in relational patterns.

Bug: #59758
Change-Id: I958bbaf9e8a63ca576024ef2ee287779064e5967
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413321
Reviewed-by: Chloe Stefantsova <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 6, 2025
This CL is a bug fix where we weren't parsing the rest of the expression after the dot shorthand.
This caused errors in parsing dot shorthands expressions such as `.red..toString();` or `fn(.parse('true') || false)`.

Bug: #59758
Change-Id: I745f45e04af53eac0cfcebe7ab977b918da10fbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413920
Reviewed-by: Paul Berry <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 7, 2025
Fixing a couple typos keeping this test from passing.

Bug: #59758
Change-Id: I5fd8345538ee4516db4565c910dcb75b93c4cda1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414185
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Bob Nystrom <[email protected]>
@johnniwinther johnniwinther added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. and removed legacy-area-front-end Legacy: Use area-dart-model instead. legacy-area-fe-analyzer-shared labels Mar 7, 2025
copybara-service bot pushed a commit that referenced this issue Mar 7, 2025
Pretty sure this isn't valid code. Moving to an error test.

Bug: #59758
Change-Id: I58fc9cc00286bfae2b6093cfb5ac2c215baf344d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414187
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Lasse Nielsen <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 10, 2025
This CL allows FutureOrs to work with dot shorthands.
The static namespace denoted by `S` is also the namespace denoted by `FutureOr<S>`.

Bug: #59758
Change-Id: Idac4c4e05dc8b9c13c2932bf6c98bc9918e5dad5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414184
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 13, 2025
…n-expressions.

Update the parser handler for the dot shorthand wrapper to handle more than just expressions. Needed for selector chains.

Additionally, fixing a type alias test that would now work, but has a typo.

Bug: #59758
Change-Id: Ifaf61b3ee32e315ecb284a8f81ef875e8af6023a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414662
Reviewed-by: Johnni Winther <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 18, 2025
This CL implements `FutureOr` for static method invocations and constructors.

Note: `static_method_future_or_test` doesn't work due to unrelated reasons (initializers), but I corrected a typo anyways.

Bug: #59758
Change-Id: I77b97b0a9104fb0354ce1de39b619394f4477f32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414664
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 19, 2025
Parse and build dot shorthand invocations that are constant.
Added a new listener to handle and store the const-ness. It didn't feel right re-using any of the other `beginConstPattern` methods.

Added an error message if invoking a non-const constructor where we expected a const constructor.

Bug: #59758
Change-Id: I8551e3b8f71e89a69d090510bb64694d5e09247d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414660
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 20, 2025
…thands.

This CL avoids reusing `findInstanceMember` to find a static member for a given context. Implemented a new `findStaticMember` that handles resolving with the dot shorthand context.

All existing tests pass.

Bug: #59758
Change-Id: I71dfef451100ce77d5bd0d203129adbb281b6859
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416840
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 25, 2025
This CL adds two errors - 1 for having an invalid context type for resolving a dot shorthand and 1 for not finding a static getter/field in the declaration provided.

Bug: #59758
Change-Id: I9cc473adf82ca1f74f2370136ac8eec5e97fb23e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416881
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 25, 2025
Adds `DotShorthandsUndefinedInvocation` error to handle unresolved method or constructor invocations.

Updates test expectations.

Bug: #59758
Change-Id: I004f989e2d6f460892964106ad72861fd3e49a5c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417084
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 27, 2025
Any dot shorthand code in the form of `.id()` where `id` is a field or getter should resolve to the `call` method in the declaration of the type of `id`.

Normal static invocations already do this, and this CL adds the extra bit of `call()` resolution to the dot shorthands feature.

Bug: #59758
Change-Id: Ie8a22f251c3c80443e27d9fb307e7ef6b495315e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418141
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
copybara-service bot pushed a commit that referenced this issue Mar 27, 2025
…t shorthands.

Adds errors for this part of the spec behaviour: `.new<typeArgs> and .new<typeArgs>(args) will always be compile-time errors because .new denotes a constructor which is not generic`

Bug: #59758
Change-Id: I76074d2314f40f60015324d4b01ece7477a8ffb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417880
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Apr 2, 2025
… empty context.

Fixes https://github.com/dart-lang/co19/blob/master/LanguageFeatures/Static-access-shorthand/type_inference_A07_t01.dart and https://github.com/dart-lang/co19/blob/master/LanguageFeatures/Static-access-shorthand/type_inference_A07_t02.dart.

This CL changes the following behaviour according to the spec -- In case of a constructor invocation, the shorthand expression is inferred in the empty context.

Bug: #59758
Change-Id: Ia849888f1a810df7390a35e454a09f3fed458849
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417960
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
copybara-service bot pushed a commit that referenced this issue Apr 4, 2025
Similar to constructor invocations, we infer the type parameters for the dot shorthand static member that we find.

Added language + cfe tests for this case.

This CL is a follow up to: https://dart-review.googlesource.com/c/sdk/+/417960/comment/90f32aed_8d1f6c01/

Bug: #59758
Change-Id: I96666ba9faa6ffaf42bd46e4d39175b88f7a353d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420283
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Apr 4, 2025
This CL adds support for constructor tearoffs in dot shorthands. If there's any type parameters on the tearoff and it's a constructor, we produce an error.

I also updated the expectations of existing tests due to an early return of `InvalidExpression`s and added language + cfe tests for the new behavior.

This CL fixes the following co19 tests and is a follow up to dart-lang/co19#3122
co19/LanguageFeatures/Static-access-shorthand/constant_expression_A03_t01
co19/LanguageFeatures/Static-access-shorthand/constant_expression_A04_t01
co19/LanguageFeatures/Static-access-shorthand/semantics_A05_t01
co19/LanguageFeatures/Static-access-shorthand/constant_expression_A03_t02

Bug: #59758, dart-lang/co19#3122
Change-Id: I1ea837342ad818cd3b1de9e422065f42e8a61d6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419782
Commit-Queue: Kallen Tu <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
copybara-service bot pushed a commit that referenced this issue Apr 8, 2025
Surfaced from this co19 test crashing because of an assert when making a null-aware element. The `fileOffset` for static tearoffs and static gets were not being properly set and caused the crash. This CL simply sets the `fileOffset` on those expressions and existing tests should pass.

https://github.com/dart-lang/co19/blob/2c7f9a6a379cfc49b3e9019d1f616d7ec9edd766/LanguageFeatures/Static-access-shorthand/non_ambiguity_A02_t01.dart

Bug: #59758
Change-Id: I7b81f0ee11d8a9458154f1148e92523d1ad8be99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420840
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue Apr 24, 2025
Context:
A while back, I inserted a synthetic token in the parser to allow us to parse without crashing the analyzer while I worked on the CFE. Now that both implementations are up and working, we can remove this synthetic token and allow the parser to parse as if we had enabled dot shorthands by default, and produce an error if the experiment isn't enabled.

This change allows a bunch of different language tests to start passing since they were blocked on the weird synthetic token messing up the parsing stream.

Bug: #59758
Change-Id: I792e3b917a76241b04ee708de06f670bbde64036
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423563
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
copybara-service bot pushed a commit that referenced this issue May 13, 2025
…iated or torn off.

Adding a few errors on when we instantiate or tear off abstract constructors. Should be parallel to how we currently check for these errors in the CFE and analyzer.

Follow up to https://dart-review.googlesource.com/c/sdk/+/426682

Language test added, co19 test passing, and unit tests added.

Bug: #59758, #59835
Change-Id: I9b34e5f960856ce50aa969ca27e56907ae3a2a8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428201
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
@kallentu
Copy link
Member Author

Will add any future bug fixes into this issue to track, but otherwise, main implementation has converged and is complete. 🚢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. feature-dot-shorthands Implementation of the dot shorthands feature. model-features General feature work in the analyzer and CFE.
Projects
None yet
Development

No branches or pull requests

2 participants