-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add runtime type check for 'await' in dart2js #50601
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
Comments
@alexmarkov, @sigmundch, @rakudrama, @fishythefish, the definition of flatten turned out to be too aggressive (causing gratuitous loss of type information), so it was adjusted, cf. #49396 (comment). Sorry about the inconvenience this may cause! |
Friendly ping: All other configurations are passing in https://dart-current-results.web.app/#/filter=language/async/await_flatten_test. Is there something that prevents this soundness issue from being handled in dart2js? |
Thanks for the ping Erik, I'll make sure we discuss it at our team sync later today. |
Thanks, that's great! |
Iterating on a fix: https://dart-review.googlesource.com/c/sdk/+/316320 |
Looks correct (to the untainted eye). That is, in the code paths for
the first two should behave the same. I'm guessing the compilation of |
It looks good! I think there is one issue ,though, and I added a drive-by comment in the CL. |
@eernstg If it matters whether we create a |
We certainly cannot expect that We do have But do we know for sure that we have one of these situations here, without exception? In any case, it would be safe to use a |
(Ack, we don't actually know The optional implementation would avoid allocating a Future at all, and it would avoid checking for |
Thanks for the comments (both here and on the CL)! I'm updating the CL to use AFAIK, we have no mechanism to insert an async delay and evaluate to the original value. Even in The redundant test in |
Ack. If the front end already does these checks, and only sets the check-type of a check is necessary, then you don't need to do anything, but that seems unlikely since it doesn't provide a way to know if it's an always-true or always-false check. |
My understanding is that the CFE omits @johnniwinther / @chloestefantsova: #49396 has a lot of discussion about when the runtime check can be safely elided. Which cases are implemented by the CFE? |
sdk/pkg/front_end/lib/src/fasta/type_inference/inference_visitor.dart Lines 830 to 838 in bf9ea56
|
Sounds like that should be "flatten of the static type of the operand"? The point would be that, by soundness, there is no need to check |
It is. Don't know why I wrote "runtime type". |
🎉 |
(make that |
This reverts commit c81711b. Reason for revert: `Internal Error: Runtime type information not available for type_variable_local` - b/295131730 Original change's description: > [dart2js] Add runtime type check for `await`. > > See #49396 for details. > > Fixes: #50601 > Change-Id: Ie89130cffe642b3e4935d7d02fe2e34f7fc8b12e > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316320 > Commit-Queue: Mayank Patke <[email protected]> > Reviewed-by: Stephen Adams <[email protected]> Change-Id: I481b119b6569d1bc9cf2ab80d997a3eb6d06f674 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319421 Reviewed-by: Alexander Thomas <[email protected]> Auto-Submit: Oleh Prypin <[email protected]> Commit-Queue: Oleh Prypin <[email protected]>
This is a reland of commit c81711b Original change's description: > [dart2js] Add runtime type check for `await`. > > See #49396 for details. > > Fixes: #50601 > Change-Id: Ie89130cffe642b3e4935d7d02fe2e34f7fc8b12e > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316320 > Commit-Queue: Mayank Patke <[email protected]> > Reviewed-by: Stephen Adams <[email protected]> Change-Id: Ida3258ee3768e8bff0161019511647db8b161473 Bug: #50601 Bug: b/295131730 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319462 Commit-Queue: Mayank Patke <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
@lrhn: |
It should be sufficient to use The That strategy, of scheduling a microtask immediately, ensures that if someone listens to the future before that microtask triggers (which is incredibly likely, the way we encourage futures to be used), then we've already scheduled a task to report the result to them. It minimizes latency by scheduling early, and if more than one listener is added to the same future, we only schedule one microtask, and accumulate listeners on the future until that microtask triggers. Using But, if you add zero listeners, a completed future does nothing, whereas the In this case, you will have precisely one listener, added immediately, so I doubt there is any visible difference in timing between the two approaches. Using |
Great, thanks, Lasse! This was very informative. |
In phase 1, we apply a kernel transformation to the AST we get from the CFE. Although there is only one actual Transformer, it applies multiple logically separate lowerings. In most cases, these lowerings are independent and operate on distinct parts of the AST, so they "commute" and no special care must be taken to ensure they're applied in the right order. In this case, we have two lowerings which slightly overlap. The async_lowering implements the `simpleAsyncToFuture` canary feature, and await_lowering implements some additional semantics which were recently added to the specification of `await` expressions - see #50601. These lowerings overlap on AwaitExpression nodes. The await_lowering can change the `await`ed expression, while async_lowering simply registers the `await`ed expression for later use. Therefore, the correct sequence seems to be await_lowering, then async_lowering. Change-Id: I5e26ab56271053d69727263d0927266515c12dd6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322585 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Mayank Patke <[email protected]>
This is a dart2js part of #49396.
According to the spec,
await e
should check runtime type ofe
to be aFuture<flatten(S)>
whereS
is a static type ofe
before waiting fore
(otherwise it should wait forFuture.value(e)
). See #49396 for details.Kernel AST contains the type to check in
AwaitExpression.runtimeCheckType
.@sigmundch @rakudrama @fishythefish
The text was updated successfully, but these errors were encountered: