Fix incorrect coroutines codegen behavior

If all the suspension calls in a suspend function were "hidden"
under the for-convention (iterator/next/hasNext) calls,
control-flow didn't find them, thus supposing that there is no
suspension points and there is no need to generate a coroutine state machine

The solution is to add relevant calls to CFG

 #KT-15824 Fixed
This commit is contained in:
Denis Zharkov
2017-01-20 15:25:21 +03:00
parent 8cbea903f4
commit 02b40326cc
22 changed files with 609 additions and 291 deletions
+12 -6
View File
@@ -14,21 +14,27 @@ L0:
w(c|<v0>)
2 mark({ for (e in c) { { break } } })
3 r(c) -> <v1>
mark(c)
call(c, iterator|<v1>) -> <v2>
v(e)
L2 [loop entry point]:
L6 [condition entry point]:
jmp?(L3) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](c|<v1>) -> <v2>] PREV:[v(e), jmp(L2)]
magic[LOOP_RANGE_ITERATION](c|<v1>) -> <v2>
w(e|<v2>)
mark(c) PREV:[v(e), jmp(L2)]
call(c, hasNext) -> <v3>
jmp?(L3) NEXT:[read (Unit), mark(c)]
mark(c)
call(c, next) -> <v4>
magic[LOOP_RANGE_ITERATION](c|<v4>) -> <v5>
w(e|<v5>)
mark(for (e in c) { { break } })
L4 [body entry point]:
4 mark({ { break } })
mark({ break })
jmp?(L7) NEXT:[r({ break }) -> <v3>, d({ break })]
jmp?(L7) NEXT:[r({ break }) -> <v6>, d({ break })]
d({ break }) NEXT:[<SINK>]
L7 [after local declaration]:
r({ break }) -> <v3> PREV:[jmp?(L7)]
3 jmp(L2) NEXT:[jmp?(L3)]
r({ break }) -> <v6> PREV:[jmp?(L7)]
3 jmp(L2) NEXT:[mark(c)]
L3 [loop exit point]:
L5 [body exit point]:
read (Unit) PREV:[jmp?(L3)]
+7 -7
View File
@@ -8,18 +8,18 @@ fun foo(c: Collection<Int>) {
}
---------------------
<v0>: {<: Collection<Int>} NEW: magic[FAKE_INITIALIZER](c: Collection<Int>) -> <v0>
<v2>: Int NEW: magic[LOOP_RANGE_ITERATION](c|<v1>) -> <v2>
c <v1>: {<: Iterable<Int>} NEW: r(c) -> <v1>
{ break } <v3>: * NEW: r({ break }) -> <v3>
{ { break } } <v3>: * COPY
for (e in c) { { break } } !<v4>: *
{ for (e in c) { { break } } } !<v4>: * COPY
<v5>: Int NEW: magic[LOOP_RANGE_ITERATION](c|<v4>) -> <v5>
c <v4>: {<: Iterable<Int>} NEW: call(c, next) -> <v4>
{ break } <v6>: * NEW: r({ break }) -> <v6>
{ { break } } <v6>: * COPY
for (e in c) { { break } } !<v7>: *
{ for (e in c) { { break } } } !<v7>: * COPY
=====================
== anonymous_0 ==
{
break
}
---------------------
break !<v0>: *
break !<v0>: *
break !<v0>: * COPY
=====================