Skip to content

Wrong implementation of yield/yield* in dartdevk #49621

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

Open
sgrekhov opened this issue Aug 9, 2022 · 2 comments
Open

Wrong implementation of yield/yield* in dartdevk #49621

sgrekhov opened this issue Aug 9, 2022 · 2 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. dev-compiler-async P2 A bug or feature request we're likely to work on web-dev-compiler

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Aug 9, 2022

dartdevk doesn't implement yield/yield* behavior described in https://github.com/dart-lang/language/blob/master/accepted/future-releases/async-star-behavior/feature-specification.md

There are several issues.

  1. If execution is paused on yield/yield* and stream is cancelled, then yield* should act like a return; statement. But it isn't so and it causes failure of the following co19 tests

co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A03_t01
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A03_t01
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t07
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t08
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t09

  1. In an asynchronous function, an await for (var event in stream) ... loop first listens on the iterated stream, then for each data event, it executes the body. If the body performs any asynchronous operation (that is, it does not complete synchronously because it executes any await, wait for or yield* operation, or it blocks at a yield), then the stream subscription must be paused. It is resumed again when the body completes normally. But it isn't so and it causes failure of

co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A05_t02

  1. If execution is paused then execution should be blocked at yield. See failures of

co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t01
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t02
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t03
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t04
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t05
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t06
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t07
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t08

See full log at https://dart-ci.firebaseapp.com/cl/253664/1

@mit-mit mit-mit added the legacy-area-front-end Legacy: Use area-dart-model instead. label Aug 9, 2022
@nshahan nshahan added web-dev-compiler area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. P2 A bug or feature request we're likely to work on and removed legacy-area-front-end Legacy: Use area-dart-model instead. labels Jun 16, 2023
@Markzipan
Copy link
Contributor

We're receiving bugs about this inconsistency internally as well. Another repro by a Googler:

Stream<int> f() async* {
  var count = 0;
  yield* Stream.fromIterable([1, 2, 3]).map((x) {
    count++;
    return x;
  });
  expect(count, 3);
}

final s = f().listen(null);
s.onData((x) => s.cancel());

which fails on DDC with:

Expected: <3>
  Actual: <1>

since DDC resumes execution of the body despite canceling the stream.

@natebosch
Copy link
Member

Potential duplicates or related issues:

#53062
#47764
#47342
#42764
#35624
#54411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. dev-compiler-async P2 A bug or feature request we're likely to work on web-dev-compiler
Projects
None yet
Development

No branches or pull requests

5 participants