Skip to content

Commit 77ea982

Browse files
alexmarkovCommit Bot
authored and
Commit Bot
committed
[vm] New implementation of sync* based on suspend/resume stubs
Issue: #48378 Change-Id: I7f4b6b56d914a617dfd7ac724cd4414532073b4c TEST=ci Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249141 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Slava Egorov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent ee86c92 commit 77ea982

File tree

53 files changed

+3601
-3160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3601
-3160
lines changed

pkg/front_end/testcases/extensions/async_extensions.dart.weak.transformed.expect

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@ extension Extension on core::int {
1010
method asyncStarMethod = self::Extension|asyncStarMethod;
1111
tearoff asyncStarMethod = self::Extension|get#asyncStarMethod;
1212
}
13-
static method Extension|syncStarMethod(lowered final core::int #this) → dynamic /* originally sync* */ {
14-
function :sync_op_gen() → (core::_SyncIterator<dynamic>?, dynamic, dynamic) → core::bool* {
15-
core::int :await_jump_var = 0;
16-
dynamic :await_ctx_var;
17-
function :sync_op(core::_SyncIterator<dynamic>? :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
18-
{}
19-
return false;
20-
}
21-
return :sync_op;
22-
}
23-
return new core::_SyncIterable::•<dynamic>(:sync_op_gen);
24-
}
13+
static method Extension|syncStarMethod(lowered final core::int #this) → dynamic sync* {}
2514
static method Extension|get#syncStarMethod(lowered final core::int #this) → () → dynamic
2615
return () → dynamic => self::Extension|syncStarMethod(#this);
2716
static method Extension|asyncMethod(lowered final core::int #this) → dynamic async /* futureValueType= dynamic */ {}

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

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,13 @@ static method asyncString() → asy::Future<core::String> async /* futureValueTy
1212
static method asyncString2() → asy::Future<core::String> async /* futureValueType= core::String */ {
1313
return self::asyncString();
1414
}
15-
static method syncStarString() → core::Iterable<core::String> /* originally sync* */ {
16-
function :sync_op_gen() → (core::_SyncIterator<dynamic>?, dynamic, dynamic) → core::bool* {
17-
core::int :await_jump_var = 0;
18-
dynamic :await_ctx_var;
19-
function :sync_op(core::_SyncIterator<dynamic>? :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
20-
{
21-
{
22-
:iterator.{core::_SyncIterator::_current} = "foo";
23-
[yield] true;
24-
}
25-
{
26-
:iterator.{core::_SyncIterator::_yieldEachIterable} = self::syncStarString2();
27-
[yield] true;
28-
}
29-
{
30-
:iterator.{core::_SyncIterator::_yieldEachIterable} = self::stringList;
31-
[yield] true;
32-
}
33-
}
34-
return false;
35-
}
36-
return :sync_op;
37-
}
38-
return new core::_SyncIterable::•<core::String>(:sync_op_gen);
15+
static method syncStarString() → core::Iterable<core::String> sync* {
16+
yield "foo";
17+
yield* self::syncStarString2();
18+
yield* self::stringList;
3919
}
40-
static method syncStarString2() → core::Iterable<core::String> /* originally sync* */ {
41-
function :sync_op_gen() → (core::_SyncIterator<dynamic>?, dynamic, dynamic) → core::bool* {
42-
core::int :await_jump_var = 0;
43-
dynamic :await_ctx_var;
44-
function :sync_op(core::_SyncIterator<dynamic>? :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
45-
{
46-
{
47-
:iterator.{core::_SyncIterator::_current} = "foo";
48-
[yield] true;
49-
}
50-
}
51-
return false;
52-
}
53-
return :sync_op;
54-
}
55-
return new core::_SyncIterable::•<core::String>(:sync_op_gen);
20+
static method syncStarString2() → core::Iterable<core::String> sync* {
21+
yield "foo";
5622
}
5723
static method asyncStarString() → asy::Stream<core::String> async* {
5824
yield "foo";

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

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,12 @@ library /*isNonNullableByDefault*/;
22
import self as self;
33
import "dart:core" as core;
44

5-
static method getElements() → core::Iterable<core::int> /* originally sync* */ {
6-
function :sync_op_gen() → (core::_SyncIterator<dynamic>?, dynamic, dynamic) → core::bool* {
7-
core::int :await_jump_var = 0;
8-
dynamic :await_ctx_var;
9-
function :sync_op(core::_SyncIterator<dynamic>? :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
10-
{
11-
core::Iterable<core::int> elements;
12-
elements = (() → core::Iterable<core::int> /* originally sync* */ {
13-
function :sync_op_gen() → (core::_SyncIterator<dynamic>?, dynamic, dynamic) → core::bool* {
14-
core::int :await_jump_var = 0;
15-
dynamic :await_ctx_var;
16-
function :sync_op(core::_SyncIterator<dynamic>? :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
17-
{
18-
{
19-
:iterator.{core::_SyncIterator::_current} = 7;
20-
[yield] true;
21-
}
22-
}
23-
return false;
24-
}
25-
return :sync_op;
26-
}
27-
return new core::_SyncIterable::•<core::int>(:sync_op_gen);
28-
})(){() → core::Iterable<core::int>};
29-
{
30-
:iterator.{core::_SyncIterator::_yieldEachIterable} = elements;
31-
[yield] true;
32-
}
33-
}
34-
return false;
35-
}
36-
return :sync_op;
37-
}
38-
return new core::_SyncIterable::•<core::int>(:sync_op_gen);
5+
static method getElements() → core::Iterable<core::int> sync* {
6+
core::Iterable<core::int> elements;
7+
elements = (() → core::Iterable<core::int> sync* {
8+
yield 7;
9+
})(){() → core::Iterable<core::int>};
10+
yield* elements;
3911
}
4012
static method main() → dynamic
4113
return core::print(self::getElements());

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,8 @@ import self as self;
33
import "dart:core" as core;
44

55
static method main() → dynamic {
6-
() →* core::Iterable<Null>* f = () → core::Iterable<Null>* /* originally sync* */ {
7-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
8-
core::int* :await_jump_var = 0;
9-
dynamic :await_ctx_var;
10-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
11-
{
12-
{
13-
:iterator.{core::_SyncIterator::_current} = null;
14-
[yield] true;
15-
}
16-
}
17-
return false;
18-
}
19-
return :sync_op;
20-
}
21-
return new core::_SyncIterable::•<Null>(:sync_op_gen);
6+
() →* core::Iterable<Null>* f = () → core::Iterable<Null>* sync* {
7+
yield null;
228
};
239
core::Iterable<dynamic>* y = f(){() →* core::Iterable<Null>*};
2410
core::Iterable<core::String*>* z = f(){() →* core::Iterable<Null>*};

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,9 @@ import self as self;
33
import "dart:core" as core;
44

55
static method test() → dynamic {
6-
() →* core::Iterable<core::num*>* f = () → core::Iterable<core::num*>* /* originally sync* */ {
7-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
8-
core::int* :await_jump_var = 0;
9-
dynamic :await_ctx_var;
10-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
11-
{
12-
{
13-
:iterator.{core::_SyncIterator::_current} = 1;
14-
[yield] true;
15-
}
16-
{
17-
:iterator.{core::_SyncIterator::_yieldEachIterable} = core::_GrowableList::_literal2<core::num*>(3, 4.0);
18-
[yield] true;
19-
}
20-
}
21-
return false;
22-
}
23-
return :sync_op;
24-
}
25-
return new core::_SyncIterable::•<core::num*>(:sync_op_gen);
6+
() →* core::Iterable<core::num*>* f = () → core::Iterable<core::num*>* sync* {
7+
yield 1;
8+
yield* core::_GrowableList::_literal2<core::num*>(3, 4.0);
269
};
2710
core::Iterable<core::num*>* g = f(){() →* core::Iterable<core::num*>*};
2811
core::Iterable<core::int*>* h = f(){() →* core::Iterable<core::num*>*} as{TypeError} core::Iterable<core::int*>*;

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

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,42 +97,19 @@ static method foo() → asy::Stream<core::List<core::int*>*>* async* {
9797
^" in core::_GrowableList::•<dynamic>(0) as{TypeError} asy::Stream<core::List<core::int*>*>*;
9898
yield* self::MyStream::•<core::List<core::int*>*>();
9999
}
100-
static method bar() → core::Iterable<core::Map<core::int*, core::int*>*>* /* originally sync* */ {
101-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
102-
core::int* :await_jump_var = 0;
103-
dynamic :await_ctx_var;
104-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
105-
{
106-
{
107-
:iterator.{core::_SyncIterator::_current} = core::Map::•<core::int*, core::int*>();
108-
[yield] true;
109-
}
110-
{
111-
:iterator.{core::_SyncIterator::_current} = invalid-expression "pkg/front_end/testcases/inference/downwards_inference_yield_yield_star.dart:23:63: Error: A value of type 'List<dynamic>' can't be assigned to a variable of type 'Map<int, int>'.
100+
static method bar() → core::Iterable<core::Map<core::int*, core::int*>*>* sync* {
101+
yield core::Map::•<core::int*, core::int*>();
102+
yield invalid-expression "pkg/front_end/testcases/inference/downwards_inference_yield_yield_star.dart:23:63: Error: A value of type 'List<dynamic>' can't be assigned to a variable of type 'Map<int, int>'.
112103
- 'List' is from 'dart:core'.
113104
- 'Map' is from 'dart:core'.
114105
yield /*error:YIELD_OF_INVALID_TYPE*/ /*@typeArgs=dynamic*/ [];
115106
^" in core::_GrowableList::•<dynamic>(0) as{TypeError} core::Map<core::int*, core::int*>*;
116-
[yield] true;
117-
}
118-
{
119-
:iterator.{core::_SyncIterator::_yieldEachIterable} = invalid-expression "pkg/front_end/testcases/inference/downwards_inference_yield_yield_star.dart:24:79: Error: A value of type 'Map<dynamic, dynamic>' can't be assigned to a variable of type 'Iterable<Map<int, int>>'.
107+
yield* invalid-expression "pkg/front_end/testcases/inference/downwards_inference_yield_yield_star.dart:24:79: Error: A value of type 'Map<dynamic, dynamic>' can't be assigned to a variable of type 'Iterable<Map<int, int>>'.
120108
- 'Map' is from 'dart:core'.
121109
- 'Iterable' is from 'dart:core'.
122110
yield* /*error:YIELD_OF_INVALID_TYPE*/ new /*@ typeArgs=dynamic, dynamic */ Map();
123111
^" in core::Map::•<dynamic, dynamic>() as{TypeError} core::Iterable<core::Map<core::int*, core::int*>*>*;
124-
[yield] true;
125-
}
126-
{
127-
:iterator.{core::_SyncIterator::_yieldEachIterable} = core::_GrowableList::•<core::Map<core::int*, core::int*>*>(0);
128-
[yield] true;
129-
}
130-
}
131-
return false;
132-
}
133-
return :sync_op;
134-
}
135-
return new core::_SyncIterable::•<core::Map<core::int*, core::int*>*>(:sync_op_gen);
112+
yield* core::_GrowableList::•<core::Map<core::int*, core::int*>*>(0);
136113
}
137114
static method main() → dynamic {}
138115

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,8 @@ static method test() → dynamic {
1414
function f3() → asy::Future<core::int*>* async /* futureValueType= core::int* */ {
1515
return 42;
1616
}
17-
function f4() → core::Iterable<core::int*>* /* originally sync* */ {
18-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
19-
core::int* :await_jump_var = 0;
20-
dynamic :await_ctx_var;
21-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
22-
{
23-
{
24-
:iterator.{core::_SyncIterator::_current} = 42;
25-
[yield] true;
26-
}
27-
}
28-
return false;
29-
}
30-
return :sync_op;
31-
}
32-
return new core::_SyncIterable::•<core::int*>(:sync_op_gen);
17+
function f4() → core::Iterable<core::int*>* sync* {
18+
yield 42;
3319
}
3420
function f5() → asy::Stream<core::int*>* async* {
3521
yield 42;

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

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,11 @@ static method main() → dynamic {
2424
return /*@ returnType=dynamic */ (/*@ type=dynamic */ x) => x;
2525
^" in ((dynamic x) → dynamic => x) as{TypeError} FutureOr<(core::int*) →* core::int*>*;
2626
}
27-
function c() → core::Iterable<(core::int*) →* core::int*>* /* originally sync* */ {
28-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
29-
core::int* :await_jump_var = 0;
30-
dynamic :await_ctx_var;
31-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
32-
{
33-
{
34-
:iterator.{core::_SyncIterator::_current} = (core::int* x) → core::int* => x;
35-
[yield] true;
36-
}
37-
}
38-
return false;
39-
}
40-
return :sync_op;
41-
}
42-
return new core::_SyncIterable::•<(core::int*) →* core::int*>(:sync_op_gen);
27+
function c() → core::Iterable<(core::int*) →* core::int*>* sync* {
28+
yield(core::int* x) → core::int* => x;
4329
}
44-
function d() → core::Iterable<(core::int*) →* core::int*>* /* originally sync* */ {
45-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
46-
core::int* :await_jump_var = 0;
47-
dynamic :await_ctx_var;
48-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
49-
{
50-
{
51-
:iterator.{core::_SyncIterator::_yieldEachIterable} = core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x);
52-
[yield] true;
53-
}
54-
}
55-
return false;
56-
}
57-
return :sync_op;
58-
}
59-
return new core::_SyncIterable::•<(core::int*) →* core::int*>(:sync_op_gen);
30+
function d() → core::Iterable<(core::int*) →* core::int*>* sync* {
31+
yield* core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x);
6032
}
6133
function e() → asy::Stream<(core::int*) →* core::int*>* async* {
6234
yield(core::int* x) → core::int* => x;

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

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,11 @@ static method b() → asy::Future<(core::int*) →* core::int*>* async /* future
2323
return /*@ returnType=dynamic */ (/*@ type=dynamic */ x) => x;
2424
^" in ((dynamic x) → dynamic => x) as{TypeError} FutureOr<(core::int*) →* core::int*>*;
2525
}
26-
static method c() → core::Iterable<(core::int*) →* core::int*>* /* originally sync* */ {
27-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
28-
core::int* :await_jump_var = 0;
29-
dynamic :await_ctx_var;
30-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
31-
{
32-
{
33-
:iterator.{core::_SyncIterator::_current} = (core::int* x) → core::int* => x;
34-
[yield] true;
35-
}
36-
}
37-
return false;
38-
}
39-
return :sync_op;
40-
}
41-
return new core::_SyncIterable::•<(core::int*) →* core::int*>(:sync_op_gen);
26+
static method c() → core::Iterable<(core::int*) →* core::int*>* sync* {
27+
yield(core::int* x) → core::int* => x;
4228
}
43-
static method d() → core::Iterable<(core::int*) →* core::int*>* /* originally sync* */ {
44-
function :sync_op_gen() → (core::_SyncIterator<dynamic>*, dynamic, dynamic) →* core::bool* {
45-
core::int* :await_jump_var = 0;
46-
dynamic :await_ctx_var;
47-
function :sync_op(core::_SyncIterator<dynamic>* :iterator, dynamic :exception, dynamic :stack_trace) → core::bool* yielding {
48-
{
49-
{
50-
:iterator.{core::_SyncIterator::_yieldEachIterable} = core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x);
51-
[yield] true;
52-
}
53-
}
54-
return false;
55-
}
56-
return :sync_op;
57-
}
58-
return new core::_SyncIterable::•<(core::int*) →* core::int*>(:sync_op_gen);
29+
static method d() → core::Iterable<(core::int*) →* core::int*>* sync* {
30+
yield* core::_GrowableList::_literal1<(core::int*) →* core::int*>((core::int* x) → core::int* => x);
5931
}
6032
static method e() → asy::Stream<(core::int*) →* core::int*>* async* {
6133
yield(core::int* x) → core::int* => x;

0 commit comments

Comments
 (0)