Skip to content

Commit 94bc012

Browse files
a-sivaCommit Bot
authored and
Commit Bot
committed
Revert "[vm] Fix some async* semantics issues: Only run generator if there's active subscription (not paused/cancelled)"
This reverts commit 837ee17. Reason for revert: Please see flutter/flutter#101514 Original change's description: > [vm] Fix some async* semantics issues: Only run generator if there's active subscription (not paused/cancelled) > > This fixes an issue where VM would run the async* generator after a > `yield` / `yield*` even though the subscription may be paused or > cancelled. > > Furthermore this fixes an issue where `StackTrace.current` used > in async* generator crashes VM and/or produces truncated stack > trace. > > This fixes the following existing tests that were failing before: > > * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t08 > * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t09 > * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t10 > * language/async_star/async_star_cancel_test > * language/async_star/pause_test > > Issue flutter/flutter#100441 > Issue #48695 > Issue #34775 > > TEST=vm/dart{,_2}/causal_stacks/flutter_regress_100441_test > > Change-Id: I73f7d0b70937a3e3766b992740fa6fe6e6d57cec > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239421 > Reviewed-by: Lasse Nielsen <[email protected]> > Commit-Queue: Martin Kustermann <[email protected]> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Ic3d9c0508310a33a2aaee67860c0bb2ec83bab4a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240506 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent bca5b89 commit 94bc012

20 files changed

+93
-292
lines changed

pkg/front_end/testcases/general/async_function.dart.weak.transformed.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ static method asyncStarString() → asy::Stream<core::String> /* originally asyn
121121
return null;
122122
else
123123
[yield] null;
124-
:controller.{asy::_AsyncStarStreamController::addStream}(self::asyncStarString2()){(asy::Stream<core::String>) → void};
125-
[yield] null;
126-
if(_in::unsafeCast<core::bool>(:result_or_exception))
124+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::asyncStarString2()){(asy::Stream<core::String>) → core::bool})
127125
return null;
126+
else
127+
[yield] null;
128128
[yield] let dynamic #t1 = asy::_awaitHelper(self::asyncString(), :async_op_then, :async_op_error) in null;
129129
if(:controller.{asy::_AsyncStarStreamController::add}(_in::unsafeCast<core::String>(:result_or_exception)){(core::String) → core::bool})
130130
return null;

pkg/front_end/testcases/general/await_complex.dart.weak.transformed.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,10 @@ static method controlFlow() → dynamic /* futureValueType= dynamic */ /* origin
652652
#L16:
653653
{
654654
[yield] let dynamic #t55 = asy::_awaitHelper(func<asy::Stream<core::int>>(self::intStream()){(asy::Stream<core::int>) → FutureOr<asy::Stream<core::int>>}, :async_op_then, :async_op_error) in null;
655-
:controller.{asy::_AsyncStarStreamController::addStream}(_in::unsafeCast<asy::Stream<core::int>>(:result_or_exception)){(asy::Stream<core::int>) → void};
656-
[yield] null;
657-
if(_in::unsafeCast<core::bool>(:result_or_exception))
655+
if(:controller.{asy::_AsyncStarStreamController::addStream}(_in::unsafeCast<asy::Stream<core::int>>(:result_or_exception)){(asy::Stream<core::int>) → core::bool})
658656
return null;
657+
else
658+
[yield] null;
659659
}
660660
return;
661661
}

pkg/front_end/testcases/general/statements.dart.weak.transformed.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ static method bar(dynamic d) → dynamic /* originally async* */ {
4444
return null;
4545
else
4646
[yield] null;
47-
:controller.{asy::_AsyncStarStreamController::addStream}(x as{TypeError,ForDynamic,ForNonNullableByDefault} asy::Stream<dynamic>){(asy::Stream<dynamic>) → void};
48-
[yield] null;
49-
if(_in::unsafeCast<core::bool>(:result_or_exception))
47+
if(:controller.{asy::_AsyncStarStreamController::addStream}(x as{TypeError,ForDynamic,ForNonNullableByDefault} asy::Stream<dynamic>){(asy::Stream<dynamic>) → core::bool})
5048
return null;
49+
else
50+
[yield] null;
5151
}
5252
}
5353
else

pkg/front_end/testcases/inference/block_bodied_lambdas_async_star.dart.weak.transformed.expect

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ library test;
22
import self as self;
33
import "dart:async" as asy;
44
import "dart:core" as core;
5-
import "dart:_internal" as _in;
65

76
import "dart:async";
87

@@ -26,10 +25,10 @@ static method test() → dynamic {
2625
else
2726
[yield] null;
2827
asy::Stream<core::double*>* s;
29-
:controller.{asy::_AsyncStarStreamController::addStream}(s){(asy::Stream<core::num*>) → void};
30-
[yield] null;
31-
if(_in::unsafeCast<core::bool>(:result_or_exception))
28+
if(:controller.{asy::_AsyncStarStreamController::addStream}(s){(asy::Stream<core::num*>) → core::bool})
3229
return null;
30+
else
31+
[yield] null;
3332
}
3433
return;
3534
}

pkg/front_end/testcases/inference/downwards_inference_yield_yield_star.dart.weak.transformed.expect

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ library test;
2929
import self as self;
3030
import "dart:core" as core;
3131
import "dart:async" as asy;
32-
import "dart:_internal" as _in;
3332

3433
import "dart:async";
3534

@@ -110,18 +109,18 @@ static method foo() → asy::Stream<core::List<core::int*>*>* /* originally asyn
110109
return null;
111110
else
112111
[yield] null;
113-
:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/inference/downwards_inference_yield_yield_star.dart:17:64: Error: A value of type 'List<dynamic>' can't be assigned to a variable of type 'Stream<List<int>>'.
112+
if(:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/inference/downwards_inference_yield_yield_star.dart:17:64: Error: A value of type 'List<dynamic>' can't be assigned to a variable of type 'Stream<List<int>>'.
114113
- 'List' is from 'dart:core'.
115114
- 'Stream' is from 'dart:async'.
116115
yield* /*error:YIELD_OF_INVALID_TYPE*/ /*@typeArgs=dynamic*/ [];
117-
^" in core::_GrowableList::•<dynamic>(0) as{TypeError} asy::Stream<core::List<core::int*>*>*){(asy::Stream<core::List<core::int*>*>) → void};
118-
[yield] null;
119-
if(_in::unsafeCast<core::bool>(:result_or_exception))
116+
^" in core::_GrowableList::•<dynamic>(0) as{TypeError} asy::Stream<core::List<core::int*>*>*){(asy::Stream<core::List<core::int*>*>) → core::bool})
120117
return null;
121-
:controller.{asy::_AsyncStarStreamController::addStream}(self::MyStream::•<core::List<core::int*>*>()){(asy::Stream<core::List<core::int*>*>) → void};
122-
[yield] null;
123-
if(_in::unsafeCast<core::bool>(:result_or_exception))
118+
else
119+
[yield] null;
120+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::MyStream::•<core::List<core::int*>*>()){(asy::Stream<core::List<core::int*>*>) → core::bool})
124121
return null;
122+
else
123+
[yield] null;
125124
}
126125
return;
127126
}

pkg/front_end/testcases/inference/local_return_and_yield.dart.weak.transformed.expect

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ library test;
1010
import self as self;
1111
import "dart:core" as core;
1212
import "dart:async" as asy;
13-
import "dart:_internal" as _in;
1413

1514
import "dart:async";
1615

@@ -130,10 +129,10 @@ static method main() → dynamic {
130129
try {
131130
#L3:
132131
{
133-
:controller.{asy::_AsyncStarStreamController::addStream}(asy::Stream::fromIterable<(core::int*) →* core::int*>(core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x))){(asy::Stream<(core::int*) →* core::int*>) → void};
134-
[yield] null;
135-
if(_in::unsafeCast<core::bool>(:result_or_exception))
132+
if(:controller.{asy::_AsyncStarStreamController::addStream}(asy::Stream::fromIterable<(core::int*) →* core::int*>(core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x))){(asy::Stream<(core::int*) →* core::int*>) → core::bool})
136133
return null;
134+
else
135+
[yield] null;
137136
}
138137
return;
139138
}

pkg/front_end/testcases/inference/top_level_return_and_yield.dart.weak.transformed.expect

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ library test;
1010
import self as self;
1111
import "dart:core" as core;
1212
import "dart:async" as asy;
13-
import "dart:_internal" as _in;
1413

1514
import "dart:async";
1615

@@ -129,10 +128,10 @@ static method f() → asy::Stream<(core::int*) →* core::int*>* /* originally a
129128
try {
130129
#L3:
131130
{
132-
:controller.{asy::_AsyncStarStreamController::addStream}(asy::Stream::fromIterable<(core::int*) →* core::int*>(core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x))){(asy::Stream<(core::int*) →* core::int*>) → void};
133-
[yield] null;
134-
if(_in::unsafeCast<core::bool>(:result_or_exception))
131+
if(:controller.{asy::_AsyncStarStreamController::addStream}(asy::Stream::fromIterable<(core::int*) →* core::int*>(core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x))){(asy::Stream<(core::int*) →* core::int*>) → core::bool})
135132
return null;
133+
else
134+
[yield] null;
136135
}
137136
return;
138137
}

pkg/front_end/testcases/nnbd/issue41437c.dart.strong.transformed.expect

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ library /*isNonNullableByDefault*/;
4040
import self as self;
4141
import "dart:async" as asy;
4242
import "dart:core" as core;
43-
import "dart:_internal" as _in;
4443

4544
static method getNull() → dynamic
4645
return null;
@@ -161,13 +160,13 @@ static method test4() → asy::Stream<core::bool> /* originally async* */ {
161160
try {
162161
#L4:
163162
{
164-
:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:21:10: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
163+
if(:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:21:10: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
165164
- 'Stream' is from 'dart:async'.
166165
yield* getStreamNull(); // error
167-
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → void};
168-
[yield] null;
169-
if(_in::unsafeCast<core::bool>(:result_or_exception))
166+
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → core::bool})
170167
return null;
168+
else
169+
[yield] null;
171170
}
172171
return;
173172
}
@@ -204,10 +203,10 @@ static method test7() → asy::Stream<core::bool> /* originally async* */ {
204203
try {
205204
#L5:
206205
{
207-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → void};
208-
[yield] null;
209-
if(_in::unsafeCast<core::bool>(:result_or_exception))
206+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → core::bool})
210207
return null;
208+
else
209+
[yield] null;
211210
}
212211
return;
213212
}
@@ -286,13 +285,13 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
286285
try {
287286
#L8:
288287
{
289-
:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:38:12: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
288+
if(:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:38:12: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
290289
- 'Stream' is from 'dart:async'.
291290
yield* getStreamNull(); // error
292-
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → void};
293-
[yield] null;
294-
if(_in::unsafeCast<core::bool>(:result_or_exception))
291+
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → core::bool})
295292
return null;
293+
else
294+
[yield] null;
296295
}
297296
return;
298297
}
@@ -329,10 +328,10 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
329328
try {
330329
#L9:
331330
{
332-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → void};
333-
[yield] null;
334-
if(_in::unsafeCast<core::bool>(:result_or_exception))
331+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → core::bool})
335332
return null;
333+
else
334+
[yield] null;
336335
}
337336
return;
338337
}
@@ -403,10 +402,10 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
403402
try {
404403
#L11:
405404
{
406-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamNull()){(asy::Stream<dynamic>) → void};
407-
[yield] null;
408-
if(_in::unsafeCast<core::bool>(:result_or_exception))
405+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamNull()){(asy::Stream<dynamic>) → core::bool})
409406
return null;
407+
else
408+
[yield] null;
410409
}
411410
return;
412411
}
@@ -441,10 +440,10 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
441440
try {
442441
#L12:
443442
{
444-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → void};
445-
[yield] null;
446-
if(_in::unsafeCast<core::bool>(:result_or_exception))
443+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → core::bool})
447444
return null;
445+
else
446+
[yield] null;
448447
}
449448
return;
450449
}

pkg/front_end/testcases/nnbd/issue41437c.dart.weak.transformed.expect

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ library /*isNonNullableByDefault*/;
4040
import self as self;
4141
import "dart:async" as asy;
4242
import "dart:core" as core;
43-
import "dart:_internal" as _in;
4443

4544
static method getNull() → dynamic
4645
return null;
@@ -161,13 +160,13 @@ static method test4() → asy::Stream<core::bool> /* originally async* */ {
161160
try {
162161
#L4:
163162
{
164-
:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:21:10: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
163+
if(:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:21:10: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
165164
- 'Stream' is from 'dart:async'.
166165
yield* getStreamNull(); // error
167-
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → void};
168-
[yield] null;
169-
if(_in::unsafeCast<core::bool>(:result_or_exception))
166+
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → core::bool})
170167
return null;
168+
else
169+
[yield] null;
171170
}
172171
return;
173172
}
@@ -204,10 +203,10 @@ static method test7() → asy::Stream<core::bool> /* originally async* */ {
204203
try {
205204
#L5:
206205
{
207-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → void};
208-
[yield] null;
209-
if(_in::unsafeCast<core::bool>(:result_or_exception))
206+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → core::bool})
210207
return null;
208+
else
209+
[yield] null;
211210
}
212211
return;
213212
}
@@ -286,13 +285,13 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
286285
try {
287286
#L8:
288287
{
289-
:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:38:12: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
288+
if(:controller.{asy::_AsyncStarStreamController::addStream}(invalid-expression "pkg/front_end/testcases/nnbd/issue41437c.dart:38:12: Error: A value of type 'Stream<dynamic>' can't be assigned to a variable of type 'Stream<bool>'.
290289
- 'Stream' is from 'dart:async'.
291290
yield* getStreamNull(); // error
292-
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → void};
293-
[yield] null;
294-
if(_in::unsafeCast<core::bool>(:result_or_exception))
291+
^" in self::getStreamNull() as{TypeError,ForNonNullableByDefault} asy::Stream<core::bool>){(asy::Stream<core::bool>) → core::bool})
295292
return null;
293+
else
294+
[yield] null;
296295
}
297296
return;
298297
}
@@ -329,10 +328,10 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
329328
try {
330329
#L9:
331330
{
332-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → void};
333-
[yield] null;
334-
if(_in::unsafeCast<core::bool>(:result_or_exception))
331+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → core::bool})
335332
return null;
333+
else
334+
[yield] null;
336335
}
337336
return;
338337
}
@@ -403,10 +402,10 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
403402
try {
404403
#L11:
405404
{
406-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamNull()){(asy::Stream<dynamic>) → void};
407-
[yield] null;
408-
if(_in::unsafeCast<core::bool>(:result_or_exception))
405+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamNull()){(asy::Stream<dynamic>) → core::bool})
409406
return null;
407+
else
408+
[yield] null;
410409
}
411410
return;
412411
}
@@ -441,10 +440,10 @@ static method test() → dynamic /* futureValueType= dynamic */ /* originally as
441440
try {
442441
#L12:
443442
{
444-
:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → void};
445-
[yield] null;
446-
if(_in::unsafeCast<core::bool>(:result_or_exception))
443+
if(:controller.{asy::_AsyncStarStreamController::addStream}(self::getStreamBool()){(asy::Stream<core::bool>) → core::bool})
447444
return null;
445+
else
446+
[yield] null;
448447
}
449448
return;
450449
}

pkg/vm/lib/transformations/continuation.dart

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,21 +1319,10 @@ class AsyncStarFunctionRewriter extends AsyncRewriterBase {
13191319
functionType: addMethodFunctionType)
13201320
..fileOffset = stmt.fileOffset;
13211321

1322-
if (stmt.isYieldStar) {
1323-
statements.add(ExpressionStatement(addExpression));
1324-
statements.add(createContinuationPoint()..fileOffset = stmt.fileOffset);
1325-
final wasCancelled = StaticInvocation(
1326-
helper.unsafeCast,
1327-
Arguments(<Expression>[VariableGet(expressionRewriter!.asyncResult)],
1328-
types: <DartType>[helper.coreTypes.boolNonNullableRawType]));
1329-
statements
1330-
.add(IfStatement(wasCancelled, ReturnStatement(NullLiteral()), null));
1331-
} else {
1332-
statements.add(new IfStatement(
1333-
addExpression,
1334-
new ReturnStatement(new NullLiteral()),
1335-
createContinuationPoint()..fileOffset = stmt.fileOffset));
1336-
}
1322+
statements.add(new IfStatement(
1323+
addExpression,
1324+
new ReturnStatement(new NullLiteral()),
1325+
createContinuationPoint()..fileOffset = stmt.fileOffset));
13371326
return removalSentinel ?? EmptyStatement();
13381327
}
13391328

0 commit comments

Comments
 (0)