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:
@@ -931,9 +931,7 @@ class ControlFlowInformationProvider private constructor(
|
||||
private inline fun traverseCalls(crossinline onCall: (instruction: CallInstruction, resolvedCall: ResolvedCall<*>) -> Unit) {
|
||||
pseudocode.traverse(TraversalOrder.FORWARD) { instruction ->
|
||||
if (instruction !is CallInstruction) return@traverse
|
||||
val resolvedCall = instruction.element.getResolvedCall(trace.bindingContext) ?: return@traverse
|
||||
|
||||
onCall(instruction, resolvedCall)
|
||||
onCall(instruction, instruction.resolvedCall)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
|
||||
import java.util.*
|
||||
|
||||
class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
@@ -750,15 +751,18 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
override fun visitForExpression(expression: KtForExpression) {
|
||||
builder.enterBlockScope(expression)
|
||||
|
||||
generateInstructions(expression.loopRange)
|
||||
val loopRange = expression.loopRange
|
||||
generateInstructions(loopRange)
|
||||
generateLoopConventionCall(loopRange, BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL)
|
||||
declareLoopParameter(expression)
|
||||
|
||||
// TODO : primitive cases
|
||||
val loopInfo = builder.enterLoop(expression)
|
||||
|
||||
builder.bindLabel(loopInfo.conditionEntryPoint)
|
||||
generateLoopConventionCall(loopRange, BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL)
|
||||
builder.nondeterministicJump(loopInfo.exitPoint, expression, null)
|
||||
|
||||
generateLoopConventionCall(loopRange, BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL)
|
||||
|
||||
writeLoopParameterAssignment(expression)
|
||||
|
||||
@@ -773,6 +777,15 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
builder.exitBlockScope(expression)
|
||||
}
|
||||
|
||||
private fun generateLoopConventionCall(
|
||||
loopRange: KtExpression?,
|
||||
callSlice: ReadOnlySlice<KtExpression, ResolvedCall<FunctionDescriptor>>
|
||||
) {
|
||||
if (loopRange == null) return
|
||||
val resolvedCall = trace.bindingContext[callSlice, loopRange] ?: return
|
||||
generateCall(resolvedCall)
|
||||
}
|
||||
|
||||
private fun declareLoopParameter(expression: KtForExpression) {
|
||||
val loopParameter = expression.loopParameter
|
||||
if (loopParameter != null) {
|
||||
|
||||
+21
-15
@@ -20,35 +20,41 @@ L0:
|
||||
w(numbers|<v0>) INIT: in: {numbers=D} out: {numbers=ID}
|
||||
2 mark({ for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } }) INIT: in: {numbers=ID} out: {numbers=ID} USE: in: {numbers=READ} out: {numbers=READ}
|
||||
3 r(numbers) -> <v1> USE: in: {} out: {numbers=READ}
|
||||
mark(numbers)
|
||||
call(numbers, iterator|<v1>) -> <v2>
|
||||
v(i) INIT: in: {numbers=ID} out: {i=D, numbers=ID}
|
||||
L2 [loop entry point]:
|
||||
L6 [condition entry point]:
|
||||
jmp?(L3) INIT: in: {i=I?D, numbers=ID} out: {i=I?D, numbers=ID}
|
||||
magic[LOOP_RANGE_ITERATION](numbers|<v1>) -> <v2>
|
||||
w(i|<v2>) INIT: in: {i=I?D, numbers=ID} out: {i=ID, numbers=ID}
|
||||
mark(numbers) INIT: in: {i=I?D, numbers=ID} out: {i=I?D, numbers=ID}
|
||||
call(numbers, hasNext) -> <v3>
|
||||
jmp?(L3)
|
||||
mark(numbers)
|
||||
call(numbers, next) -> <v4>
|
||||
magic[LOOP_RANGE_ITERATION](numbers|<v4>) -> <v5>
|
||||
w(i|<v5>) INIT: in: {i=I?D, numbers=ID} out: {i=ID, numbers=ID}
|
||||
mark(for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue }) INIT: in: {i=ID, numbers=ID} out: {i=ID, numbers=ID} USE: in: {} out: {}
|
||||
L4 [body entry point]:
|
||||
4 mark({ val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue })
|
||||
v(val b: Boolean) INIT: in: {i=ID, numbers=ID} out: {b=D, i=ID, numbers=ID}
|
||||
mark(if (1 < 2) { b = false } else { b = true }) INIT: in: {b=D, i=ID, numbers=ID} out: {b=D, i=ID, numbers=ID}
|
||||
r(1) -> <v3>
|
||||
r(2) -> <v4>
|
||||
r(1) -> <v6>
|
||||
r(2) -> <v7>
|
||||
mark(1 < 2)
|
||||
call(1 < 2, compareTo|<v3>, <v4>) -> <v5>
|
||||
jf(L7|<v5>)
|
||||
call(1 < 2, compareTo|<v6>, <v7>) -> <v8>
|
||||
jf(L7|<v8>)
|
||||
5 mark({ b = false })
|
||||
r(false) -> <v6> USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ}
|
||||
w(b|<v6>) INIT: in: {b=D, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ}
|
||||
r(false) -> <v9> USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ}
|
||||
w(b|<v9>) INIT: in: {b=D, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ}
|
||||
4 jmp(L8) INIT: in: {b=ID, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=READ}
|
||||
L7 [else branch]:
|
||||
5 mark({ b = true }) INIT: in: {b=D, i=ID, numbers=ID} out: {b=D, i=ID, numbers=ID}
|
||||
r(true) -> <v8> USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ}
|
||||
w(b|<v8>) INIT: in: {b=D, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ}
|
||||
r(true) -> <v11> USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ}
|
||||
w(b|<v11>) INIT: in: {b=D, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ}
|
||||
L8 ['if' expression result]:
|
||||
4 merge(if (1 < 2) { b = false } else { b = true }|!<v7>, !<v9>) -> <v10> INIT: in: {b=ID, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=READ}
|
||||
r(b) -> <v11> USE: in: {} out: {b=READ}
|
||||
4 merge(if (1 < 2) { b = false } else { b = true }|!<v10>, !<v12>) -> <v13> INIT: in: {b=ID, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=READ}
|
||||
r(b) -> <v14> USE: in: {} out: {b=READ}
|
||||
mark(use(b))
|
||||
call(use(b), use|<v11>) -> <v12>
|
||||
call(use(b), use|<v14>) -> <v15>
|
||||
jmp(L6) USE: in: {} out: {}
|
||||
- 3 jmp(L2)
|
||||
L3 [loop exit point]:
|
||||
@@ -77,4 +83,4 @@ error:
|
||||
<ERROR> INIT: in: {} out: {}
|
||||
sink:
|
||||
<SINK> INIT: in: {a=I?} out: {a=I?} USE: in: {} out: {}
|
||||
=====================
|
||||
=====================
|
||||
|
||||
@@ -13,25 +13,25 @@ fun foo(numbers: Collection<Int>) {
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
<v0>: {<: Collection<Int>} NEW: magic[FAKE_INITIALIZER](numbers: Collection<Int>) -> <v0>
|
||||
<v2>: Int NEW: magic[LOOP_RANGE_ITERATION](numbers|<v1>) -> <v2>
|
||||
numbers <v1>: {<: Iterable<Int>} NEW: r(numbers) -> <v1>
|
||||
1 <v3>: {<: Comparable<Int>} NEW: r(1) -> <v3>
|
||||
2 <v4>: Int NEW: r(2) -> <v4>
|
||||
1 < 2 <v5>: Boolean NEW: call(1 < 2, compareTo|<v3>, <v4>) -> <v5>
|
||||
false <v6>: Boolean NEW: r(false) -> <v6>
|
||||
b = false !<v7>: *
|
||||
{ b = false } !<v7>: * COPY
|
||||
true <v8>: Boolean NEW: r(true) -> <v8>
|
||||
b = true !<v9>: *
|
||||
{ b = true } !<v9>: * COPY
|
||||
if (1 < 2) { b = false } else { b = true } <v10>: * NEW: merge(if (1 < 2) { b = false } else { b = true }|!<v7>, !<v9>) -> <v10>
|
||||
b <v11>: * NEW: r(b) -> <v11>
|
||||
use(b) <v12>: * NEW: call(use(b), use|<v11>) -> <v12>
|
||||
continue !<v13>: *
|
||||
{ val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } !<v13>: * COPY
|
||||
for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } !<v14>: *
|
||||
{ for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } } !<v14>: * COPY
|
||||
<v0>: {<: Collection<Int>} NEW: magic[FAKE_INITIALIZER](numbers: Collection<Int>) -> <v0>
|
||||
<v5>: Int NEW: magic[LOOP_RANGE_ITERATION](numbers|<v4>) -> <v5>
|
||||
numbers <v4>: {<: Iterable<Int>} NEW: call(numbers, next) -> <v4>
|
||||
1 <v6>: {<: Comparable<Int>} NEW: r(1) -> <v6>
|
||||
2 <v7>: Int NEW: r(2) -> <v7>
|
||||
1 < 2 <v8>: Boolean NEW: call(1 < 2, compareTo|<v6>, <v7>) -> <v8>
|
||||
false <v9>: Boolean NEW: r(false) -> <v9>
|
||||
b = false !<v10>: *
|
||||
{ b = false } !<v10>: * COPY
|
||||
true <v11>: Boolean NEW: r(true) -> <v11>
|
||||
b = true !<v12>: *
|
||||
{ b = true } !<v12>: * COPY
|
||||
if (1 < 2) { b = false } else { b = true } <v13>: * NEW: merge(if (1 < 2) { b = false } else { b = true }|!<v10>, !<v12>) -> <v13>
|
||||
b <v14>: * NEW: r(b) -> <v14>
|
||||
use(b) <v15>: * NEW: call(use(b), use|<v14>) -> <v15>
|
||||
continue !<v16>: *
|
||||
{ val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } !<v16>: * COPY
|
||||
for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } !<v17>: *
|
||||
{ for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } } !<v17>: * COPY
|
||||
=====================
|
||||
== use ==
|
||||
fun use(vararg a: Any?) = a
|
||||
|
||||
@@ -16,28 +16,34 @@ L0:
|
||||
r(10) -> <v2>
|
||||
mark(1..10)
|
||||
call(1..10, rangeTo|<v1>, <v2>) -> <v3>
|
||||
mark(1..10)
|
||||
call(1..10, iterator|<v3>) -> <v4>
|
||||
v(i) INIT: in: {} out: {i=D}
|
||||
L2 [loop entry point]:
|
||||
L6 [condition entry point]:
|
||||
jmp?(L3) INIT: in: {i=I?D} out: {i=I?D}
|
||||
magic[LOOP_RANGE_ITERATION](1..10|<v3>) -> <v4>
|
||||
w(i|<v4>) INIT: in: {i=I?D} out: {i=ID}
|
||||
mark(1..10) INIT: in: {i=I?D} out: {i=I?D}
|
||||
call(1..10, hasNext) -> <v5>
|
||||
jmp?(L3)
|
||||
mark(1..10)
|
||||
call(1..10, next) -> <v6>
|
||||
magic[LOOP_RANGE_ITERATION](1..10|<v6>) -> <v7>
|
||||
w(i|<v7>) INIT: in: {i=I?D} out: {i=ID}
|
||||
mark(for (i in 1..10) { val a = i }) INIT: in: {i=ID} out: {i=ID}
|
||||
L4 [body entry point]:
|
||||
4 mark({ val a = i })
|
||||
v(val a = i) INIT: in: {i=ID} out: {a=D, i=ID}
|
||||
r(i) -> <v5> INIT: in: {a=D, i=ID} out: {a=D, i=ID}
|
||||
w(a|<v5>) INIT: in: {a=D, i=ID} out: {a=ID, i=ID}
|
||||
r(i) -> <v8> INIT: in: {a=D, i=ID} out: {a=D, i=ID}
|
||||
w(a|<v8>) INIT: in: {a=D, i=ID} out: {a=ID, i=ID}
|
||||
3 jmp(L2) INIT: in: {i=ID} out: {i=ID} USE: in: {i=READ} out: {i=READ}
|
||||
L3 [loop exit point]:
|
||||
L5 [body exit point]:
|
||||
read (Unit) INIT: in: {i=I?D} out: {i=I?D}
|
||||
2 mark("after") INIT: in: {} out: {}
|
||||
r("after") -> <v6>
|
||||
r("after") -> <v9>
|
||||
L1:
|
||||
1 <END>
|
||||
error:
|
||||
<ERROR>
|
||||
sink:
|
||||
<SINK> USE: in: {} out: {}
|
||||
=====================
|
||||
=====================
|
||||
|
||||
@@ -7,12 +7,12 @@ fun foo() {
|
||||
"after"
|
||||
}
|
||||
---------------------
|
||||
<v4>: Int NEW: magic[LOOP_RANGE_ITERATION](1..10|<v3>) -> <v4>
|
||||
"before" <v0>: * NEW: r("before") -> <v0>
|
||||
1 <v1>: Int NEW: r(1) -> <v1>
|
||||
10 <v2>: Int NEW: r(10) -> <v2>
|
||||
1..10 <v3>: {<: Iterable<Int>} NEW: call(1..10, rangeTo|<v1>, <v2>) -> <v3>
|
||||
i <v5>: Int NEW: r(i) -> <v5>
|
||||
"after" <v6>: * NEW: r("after") -> <v6>
|
||||
{ "before" for (i in 1..10) { val a = i } "after" } <v6>: * COPY
|
||||
<v7>: Int NEW: magic[LOOP_RANGE_ITERATION](1..10|<v6>) -> <v7>
|
||||
"before" <v0>: * NEW: r("before") -> <v0>
|
||||
1 <v1>: Int NEW: r(1) -> <v1>
|
||||
10 <v2>: Int NEW: r(10) -> <v2>
|
||||
1..10 <v6>: {<: Iterable<Int>} NEW: call(1..10, next) -> <v6>
|
||||
i <v8>: Int NEW: r(i) -> <v8>
|
||||
"after" <v9>: * NEW: r("after") -> <v9>
|
||||
{ "before" for (i in 1..10) { val a = i } "after" } <v9>: * COPY
|
||||
=====================
|
||||
|
||||
+12
-6
@@ -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
@@ -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
|
||||
=====================
|
||||
|
||||
+68
-50
@@ -476,48 +476,54 @@ L0:
|
||||
r(a) -> <v2>
|
||||
mark(1..a)
|
||||
call(1..a, rangeTo|<v1>, <v2>) -> <v3>
|
||||
mark(1..a)
|
||||
call(1..a, iterator|<v3>) -> <v4>
|
||||
v(i)
|
||||
L2 [loop entry point]:
|
||||
L6 [condition entry point]:
|
||||
jmp?(L3) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>] PREV:[v(i), jmp(L6), jmp(L2)]
|
||||
magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>
|
||||
w(i|<v4>)
|
||||
mark(1..a) PREV:[v(i), jmp(L6), jmp(L2)]
|
||||
call(1..a, hasNext) -> <v5>
|
||||
jmp?(L3) NEXT:[read (Unit), mark(1..a)]
|
||||
mark(1..a)
|
||||
call(1..a, next) -> <v6>
|
||||
magic[LOOP_RANGE_ITERATION](1..a|<v6>) -> <v7>
|
||||
w(i|<v7>)
|
||||
mark(for (i in 1..a) { try { 1 if (2 > 3) { continue@l } } finally { 2 } })
|
||||
L4 [body entry point]:
|
||||
4 mark({ try { 1 if (2 > 3) { continue@l } } finally { 2 } })
|
||||
mark(try { 1 if (2 > 3) { continue@l } } finally { 2 })
|
||||
jmp?(L7) NEXT:[mark({ 2 }), mark({ 1 if (2 > 3) { continue@l } })]
|
||||
5 mark({ 1 if (2 > 3) { continue@l } })
|
||||
r(1) -> <v5>
|
||||
r(1) -> <v8>
|
||||
mark(if (2 > 3) { continue@l })
|
||||
r(2) -> <v6>
|
||||
r(3) -> <v7>
|
||||
r(2) -> <v9>
|
||||
r(3) -> <v10>
|
||||
mark(2 > 3)
|
||||
call(2 > 3, compareTo|<v6>, <v7>) -> <v8>
|
||||
jf(L8|<v8>) NEXT:[read (Unit), mark({ continue@l })]
|
||||
call(2 > 3, compareTo|<v9>, <v10>) -> <v11>
|
||||
jf(L8|<v11>) NEXT:[read (Unit), mark({ continue@l })]
|
||||
6 mark({ continue@l })
|
||||
jmp?(L7) NEXT:[mark({ 2 }), mark({ 2 })]
|
||||
L9 [start finally]:
|
||||
7 mark({ 2 })
|
||||
r(2) -> <v9>
|
||||
r(2) -> <v12>
|
||||
L10 [finish finally]:
|
||||
6 jmp(L6) NEXT:[jmp?(L3)]
|
||||
- 5 jmp(L11) NEXT:[merge(if (2 > 3) { continue@l }|!<v10>) -> <v11>] PREV:[]
|
||||
6 jmp(L6) NEXT:[mark(1..a)]
|
||||
- 5 jmp(L11) NEXT:[merge(if (2 > 3) { continue@l }|!<v13>) -> <v14>] PREV:[]
|
||||
L8 [else branch]:
|
||||
read (Unit) PREV:[jf(L8|<v8>)]
|
||||
read (Unit) PREV:[jf(L8|<v11>)]
|
||||
L11 ['if' expression result]:
|
||||
merge(if (2 > 3) { continue@l }|!<v10>) -> <v11>
|
||||
merge(if (2 > 3) { continue@l }|!<v13>) -> <v14>
|
||||
4 jmp?(L7) NEXT:[mark({ 2 }), jmp(L12)]
|
||||
jmp(L12) NEXT:[mark({ 2 })]
|
||||
L7 [onExceptionToFinallyBlock]:
|
||||
7 mark({ 2 }) PREV:[jmp?(L7), jmp?(L7), jmp?(L7)]
|
||||
r(2) -> <v9>
|
||||
r(2) -> <v12>
|
||||
4 jmp(error) NEXT:[<ERROR>]
|
||||
L12 [skipFinallyToErrorBlock]:
|
||||
7 mark({ 2 }) PREV:[jmp(L12)]
|
||||
r(2) -> <v9>
|
||||
4 merge(try { 1 if (2 > 3) { continue@l } } finally { 2 }|<v11>) -> <v12>
|
||||
3 jmp(L2) NEXT:[jmp?(L3)]
|
||||
r(2) -> <v12>
|
||||
4 merge(try { 1 if (2 > 3) { continue@l } } finally { 2 }|<v14>) -> <v15>
|
||||
3 jmp(L2) NEXT:[mark(1..a)]
|
||||
L3 [loop exit point]:
|
||||
L5 [body exit point]:
|
||||
read (Unit) PREV:[jmp?(L3)]
|
||||
@@ -557,47 +563,53 @@ L0:
|
||||
r(a) -> <v2>
|
||||
mark(1..a)
|
||||
call(1..a, rangeTo|<v1>, <v2>) -> <v3>
|
||||
mark(1..a)
|
||||
call(1..a, iterator|<v3>) -> <v4>
|
||||
v(i)
|
||||
L3 [loop entry point]:
|
||||
L7 [condition entry point]:
|
||||
jmp?(L4) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>] PREV:[v(i), jmp(L7), jmp(L3)]
|
||||
magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>
|
||||
w(i|<v4>)
|
||||
mark(1..a) PREV:[v(i), jmp(L7), jmp(L3)]
|
||||
call(1..a, hasNext) -> <v5>
|
||||
jmp?(L4) NEXT:[read (Unit), mark(1..a)]
|
||||
mark(1..a)
|
||||
call(1..a, next) -> <v6>
|
||||
magic[LOOP_RANGE_ITERATION](1..a|<v6>) -> <v7>
|
||||
w(i|<v7>)
|
||||
mark(for (i in 1..a) { 1 if (2 > 3) { continue@l } })
|
||||
L5 [body entry point]:
|
||||
5 mark({ 1 if (2 > 3) { continue@l } })
|
||||
r(1) -> <v5>
|
||||
r(1) -> <v8>
|
||||
mark(if (2 > 3) { continue@l })
|
||||
r(2) -> <v6>
|
||||
r(3) -> <v7>
|
||||
r(2) -> <v9>
|
||||
r(3) -> <v10>
|
||||
mark(2 > 3)
|
||||
call(2 > 3, compareTo|<v6>, <v7>) -> <v8>
|
||||
jf(L8|<v8>) NEXT:[read (Unit), mark({ continue@l })]
|
||||
call(2 > 3, compareTo|<v9>, <v10>) -> <v11>
|
||||
jf(L8|<v11>) NEXT:[read (Unit), mark({ continue@l })]
|
||||
6 mark({ continue@l })
|
||||
jmp(L7) NEXT:[jmp?(L4)]
|
||||
- 5 jmp(L9) NEXT:[merge(if (2 > 3) { continue@l }|!<v9>) -> <v10>] PREV:[]
|
||||
jmp(L7) NEXT:[mark(1..a)]
|
||||
- 5 jmp(L9) NEXT:[merge(if (2 > 3) { continue@l }|!<v12>) -> <v13>] PREV:[]
|
||||
L8 [else branch]:
|
||||
read (Unit) PREV:[jf(L8|<v8>)]
|
||||
read (Unit) PREV:[jf(L8|<v11>)]
|
||||
L9 ['if' expression result]:
|
||||
merge(if (2 > 3) { continue@l }|!<v9>) -> <v10>
|
||||
4 jmp(L3) NEXT:[jmp?(L4)]
|
||||
merge(if (2 > 3) { continue@l }|!<v12>) -> <v13>
|
||||
4 jmp(L3) NEXT:[mark(1..a)]
|
||||
L4 [loop exit point]:
|
||||
L6 [body exit point]:
|
||||
read (Unit) PREV:[jmp?(L4)]
|
||||
3 r(5) -> <v12>
|
||||
3 r(5) -> <v15>
|
||||
2 jmp?(L2) NEXT:[mark({ 2 }), jmp(L10)]
|
||||
jmp(L10) NEXT:[mark({ 2 })]
|
||||
L2 [onExceptionToFinallyBlock]:
|
||||
L11 [start finally]:
|
||||
3 mark({ 2 }) PREV:[jmp?(L2), jmp?(L2)]
|
||||
r(2) -> <v13>
|
||||
r(2) -> <v16>
|
||||
L12 [finish finally]:
|
||||
2 jmp(error) NEXT:[<ERROR>]
|
||||
L10 [skipFinallyToErrorBlock]:
|
||||
L13 [copy of L2, onExceptionToFinallyBlock]:
|
||||
3 mark({ 2 }) PREV:[jmp(L10)]
|
||||
r(2) -> <v13>
|
||||
2 merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 }|<v12>) -> <v14>
|
||||
r(2) -> <v16>
|
||||
2 merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 }|<v15>) -> <v17>
|
||||
L1:
|
||||
1 <END> NEXT:[<SINK>]
|
||||
error:
|
||||
@@ -633,30 +645,36 @@ L0:
|
||||
r(a) -> <v2>
|
||||
mark(1..a)
|
||||
call(1..a, rangeTo|<v1>, <v2>) -> <v3>
|
||||
mark(1..a)
|
||||
call(1..a, iterator|<v3>) -> <v4>
|
||||
v(i)
|
||||
L3 [loop entry point]:
|
||||
L7 [condition entry point]:
|
||||
jmp?(L4) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>] PREV:[v(i), jmp(L7), jmp(L3)]
|
||||
magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>
|
||||
w(i|<v4>)
|
||||
mark(1..a) PREV:[v(i), jmp(L7), jmp(L3)]
|
||||
call(1..a, hasNext) -> <v5>
|
||||
jmp?(L4) NEXT:[read (Unit), mark(1..a)]
|
||||
mark(1..a)
|
||||
call(1..a, next) -> <v6>
|
||||
magic[LOOP_RANGE_ITERATION](1..a|<v6>) -> <v7>
|
||||
w(i|<v7>)
|
||||
mark(for (i in 1..a) { 1 if (2 > 3) { continue@l } })
|
||||
L5 [body entry point]:
|
||||
5 mark({ 1 if (2 > 3) { continue@l } })
|
||||
r(1) -> <v5>
|
||||
r(1) -> <v8>
|
||||
mark(if (2 > 3) { continue@l })
|
||||
r(2) -> <v6>
|
||||
r(3) -> <v7>
|
||||
r(2) -> <v9>
|
||||
r(3) -> <v10>
|
||||
mark(2 > 3)
|
||||
call(2 > 3, compareTo|<v6>, <v7>) -> <v8>
|
||||
jf(L8|<v8>) NEXT:[read (Unit), mark({ continue@l })]
|
||||
call(2 > 3, compareTo|<v9>, <v10>) -> <v11>
|
||||
jf(L8|<v11>) NEXT:[read (Unit), mark({ continue@l })]
|
||||
6 mark({ continue@l })
|
||||
jmp(L7) NEXT:[jmp?(L4)]
|
||||
- 5 jmp(L9) NEXT:[merge(if (2 > 3) { continue@l }|!<v9>) -> <v10>] PREV:[]
|
||||
jmp(L7) NEXT:[mark(1..a)]
|
||||
- 5 jmp(L9) NEXT:[merge(if (2 > 3) { continue@l }|!<v12>) -> <v13>] PREV:[]
|
||||
L8 [else branch]:
|
||||
read (Unit) PREV:[jf(L8|<v8>)]
|
||||
read (Unit) PREV:[jf(L8|<v11>)]
|
||||
L9 ['if' expression result]:
|
||||
merge(if (2 > 3) { continue@l }|!<v9>) -> <v10>
|
||||
4 jmp(L3) NEXT:[jmp?(L4)]
|
||||
merge(if (2 > 3) { continue@l }|!<v12>) -> <v13>
|
||||
4 jmp(L3) NEXT:[mark(1..a)]
|
||||
L4 [loop exit point]:
|
||||
L6 [body exit point]:
|
||||
read (Unit) PREV:[jmp?(L4)]
|
||||
@@ -665,14 +683,14 @@ L6 [body exit point]:
|
||||
L2 [onExceptionToFinallyBlock]:
|
||||
L11 [start finally]:
|
||||
3 mark({ 2 }) PREV:[jmp?(L2), jmp?(L2)]
|
||||
r(2) -> <v12>
|
||||
r(2) -> <v15>
|
||||
L12 [finish finally]:
|
||||
2 jmp(error) NEXT:[<ERROR>]
|
||||
L10 [skipFinallyToErrorBlock]:
|
||||
L13 [copy of L2, onExceptionToFinallyBlock]:
|
||||
3 mark({ 2 }) PREV:[jmp(L10)]
|
||||
r(2) -> <v12>
|
||||
2 merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 }|!<v11>) -> <v13>
|
||||
r(2) -> <v15>
|
||||
2 merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 }|!<v14>) -> <v16>
|
||||
L1:
|
||||
1 <END> NEXT:[<SINK>]
|
||||
error:
|
||||
|
||||
+82
-82
@@ -7,12 +7,12 @@ fun t1() {
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
1 <v0>: * NEW: r(1) -> <v0>
|
||||
{ 1 } <v0>: * COPY
|
||||
2 <v1>: * NEW: r(2) -> <v1>
|
||||
{ 2 } <v1>: * COPY
|
||||
1 <v0>: * NEW: r(1) -> <v0>
|
||||
{ 1 } <v0>: * COPY
|
||||
2 <v1>: * NEW: r(2) -> <v1>
|
||||
{ 2 } <v1>: * COPY
|
||||
try { 1 } finally { 2 } <v2>: * NEW: merge(try { 1 } finally { 2 }|<v0>) -> <v2>
|
||||
{ try { 1 } finally { 2 } } <v2>: * COPY
|
||||
{ try { 1 } finally { 2 } } <v2>: * COPY
|
||||
=====================
|
||||
== t2 ==
|
||||
fun t2() {
|
||||
@@ -26,18 +26,18 @@ fun t2() {
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
1 <v0>: * NEW: r(1) -> <v0>
|
||||
2 <v1>: {<: Comparable<Int>} NEW: r(2) -> <v1>
|
||||
3 <v2>: Int NEW: r(3) -> <v2>
|
||||
2 > 3 <v3>: Boolean NEW: call(2 > 3, compareTo|<v1>, <v2>) -> <v3>
|
||||
return !<v5>: *
|
||||
{ return } !<v5>: * COPY
|
||||
if (2 > 3) { return } <v6>: * NEW: merge(if (2 > 3) { return }|!<v5>) -> <v6>
|
||||
{ 1 if (2 > 3) { return } } <v6>: * COPY
|
||||
2 <v4>: * NEW: r(2) -> <v4>
|
||||
{ 2 } <v4>: * COPY
|
||||
1 <v0>: * NEW: r(1) -> <v0>
|
||||
2 <v1>: {<: Comparable<Int>} NEW: r(2) -> <v1>
|
||||
3 <v2>: Int NEW: r(3) -> <v2>
|
||||
2 > 3 <v3>: Boolean NEW: call(2 > 3, compareTo|<v1>, <v2>) -> <v3>
|
||||
return !<v5>: *
|
||||
{ return } !<v5>: * COPY
|
||||
if (2 > 3) { return } <v6>: * NEW: merge(if (2 > 3) { return }|!<v5>) -> <v6>
|
||||
{ 1 if (2 > 3) { return } } <v6>: * COPY
|
||||
2 <v4>: * NEW: r(2) -> <v4>
|
||||
{ 2 } <v4>: * COPY
|
||||
try { 1 if (2 > 3) { return } } finally { 2 } <v7>: * NEW: merge(try { 1 if (2 > 3) { return } } finally { 2 }|<v6>) -> <v7>
|
||||
{ try { 1 if (2 > 3) { return } } finally { 2 } } <v7>: * COPY
|
||||
{ try { 1 if (2 > 3) { return } } finally { 2 } } <v7>: * COPY
|
||||
=====================
|
||||
== t3 ==
|
||||
fun t3() {
|
||||
@@ -233,25 +233,25 @@ fun t8(a : Int) {
|
||||
}
|
||||
---------------------
|
||||
<v0>: Int NEW: magic[FAKE_INITIALIZER](a : Int) -> <v0>
|
||||
<v4>: Int NEW: magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>
|
||||
<v7>: Int NEW: magic[LOOP_RANGE_ITERATION](1..a|<v6>) -> <v7>
|
||||
1 <v1>: Int NEW: r(1) -> <v1>
|
||||
a <v2>: Int NEW: r(a) -> <v2>
|
||||
1..a <v3>: {<: Iterable<Int>} NEW: call(1..a, rangeTo|<v1>, <v2>) -> <v3>
|
||||
1 <v5>: * NEW: r(1) -> <v5>
|
||||
2 <v6>: {<: Comparable<Int>} NEW: r(2) -> <v6>
|
||||
3 <v7>: Int NEW: r(3) -> <v7>
|
||||
2 > 3 <v8>: Boolean NEW: call(2 > 3, compareTo|<v6>, <v7>) -> <v8>
|
||||
continue@l !<v10>: *
|
||||
{ continue@l } !<v10>: * COPY
|
||||
if (2 > 3) { continue@l } <v11>: * NEW: merge(if (2 > 3) { continue@l }|!<v10>) -> <v11>
|
||||
{ 1 if (2 > 3) { continue@l } } <v11>: * COPY
|
||||
2 <v9>: * NEW: r(2) -> <v9>
|
||||
{ 2 } <v9>: * COPY
|
||||
try { 1 if (2 > 3) { continue@l } } finally { 2 } <v12>: * NEW: merge(try { 1 if (2 > 3) { continue@l } } finally { 2 }|<v11>) -> <v12>
|
||||
{ try { 1 if (2 > 3) { continue@l } } finally { 2 } } <v12>: * COPY
|
||||
for (i in 1..a) { try { 1 if (2 > 3) { continue@l } } finally { 2 } } !<v13>: *
|
||||
l@ for (i in 1..a) { try { 1 if (2 > 3) { continue@l } } finally { 2 } } !<v13>: * COPY
|
||||
{ l@ for (i in 1..a) { try { 1 if (2 > 3) { continue@l } } finally { 2 } } } !<v13>: * COPY
|
||||
1..a <v6>: {<: Iterable<Int>} NEW: call(1..a, next) -> <v6>
|
||||
1 <v8>: * NEW: r(1) -> <v8>
|
||||
2 <v9>: {<: Comparable<Int>} NEW: r(2) -> <v9>
|
||||
3 <v10>: Int NEW: r(3) -> <v10>
|
||||
2 > 3 <v11>: Boolean NEW: call(2 > 3, compareTo|<v9>, <v10>) -> <v11>
|
||||
continue@l !<v13>: *
|
||||
{ continue@l } !<v13>: * COPY
|
||||
if (2 > 3) { continue@l } <v14>: * NEW: merge(if (2 > 3) { continue@l }|!<v13>) -> <v14>
|
||||
{ 1 if (2 > 3) { continue@l } } <v14>: * COPY
|
||||
2 <v12>: * NEW: r(2) -> <v12>
|
||||
{ 2 } <v12>: * COPY
|
||||
try { 1 if (2 > 3) { continue@l } } finally { 2 } <v15>: * NEW: merge(try { 1 if (2 > 3) { continue@l } } finally { 2 }|<v14>) -> <v15>
|
||||
{ try { 1 if (2 > 3) { continue@l } } finally { 2 } } <v15>: * COPY
|
||||
for (i in 1..a) { try { 1 if (2 > 3) { continue@l } } finally { 2 } } !<v16>: *
|
||||
l@ for (i in 1..a) { try { 1 if (2 > 3) { continue@l } } finally { 2 } } !<v16>: * COPY
|
||||
{ l@ for (i in 1..a) { try { 1 if (2 > 3) { continue@l } } finally { 2 } } } !<v16>: * COPY
|
||||
=====================
|
||||
== t9 ==
|
||||
fun t9(a : Int) {
|
||||
@@ -269,26 +269,26 @@ fun t9(a : Int) {
|
||||
}
|
||||
---------------------
|
||||
<v0>: Int NEW: magic[FAKE_INITIALIZER](a : Int) -> <v0>
|
||||
<v4>: Int NEW: magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>
|
||||
<v7>: Int NEW: magic[LOOP_RANGE_ITERATION](1..a|<v6>) -> <v7>
|
||||
1 <v1>: Int NEW: r(1) -> <v1>
|
||||
a <v2>: Int NEW: r(a) -> <v2>
|
||||
1..a <v3>: {<: Iterable<Int>} NEW: call(1..a, rangeTo|<v1>, <v2>) -> <v3>
|
||||
1 <v5>: * NEW: r(1) -> <v5>
|
||||
2 <v6>: {<: Comparable<Int>} NEW: r(2) -> <v6>
|
||||
3 <v7>: Int NEW: r(3) -> <v7>
|
||||
2 > 3 <v8>: Boolean NEW: call(2 > 3, compareTo|<v6>, <v7>) -> <v8>
|
||||
continue@l !<v9>: *
|
||||
{ continue@l } !<v9>: * COPY
|
||||
if (2 > 3) { continue@l } <v10>: * NEW: merge(if (2 > 3) { continue@l }|!<v9>) -> <v10>
|
||||
{ 1 if (2 > 3) { continue@l } } <v10>: * COPY
|
||||
for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v11>: *
|
||||
l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v11>: * COPY
|
||||
5 <v12>: * NEW: r(5) -> <v12>
|
||||
{ l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } <v12>: * COPY
|
||||
2 <v13>: * NEW: r(2) -> <v13>
|
||||
{ 2 } <v13>: * COPY
|
||||
try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 } <v14>: * NEW: merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 }|<v12>) -> <v14>
|
||||
{ try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 } } <v14>: * COPY
|
||||
1..a <v6>: {<: Iterable<Int>} NEW: call(1..a, next) -> <v6>
|
||||
1 <v8>: * NEW: r(1) -> <v8>
|
||||
2 <v9>: {<: Comparable<Int>} NEW: r(2) -> <v9>
|
||||
3 <v10>: Int NEW: r(3) -> <v10>
|
||||
2 > 3 <v11>: Boolean NEW: call(2 > 3, compareTo|<v9>, <v10>) -> <v11>
|
||||
continue@l !<v12>: *
|
||||
{ continue@l } !<v12>: * COPY
|
||||
if (2 > 3) { continue@l } <v13>: * NEW: merge(if (2 > 3) { continue@l }|!<v12>) -> <v13>
|
||||
{ 1 if (2 > 3) { continue@l } } <v13>: * COPY
|
||||
for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v14>: *
|
||||
l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v14>: * COPY
|
||||
5 <v15>: * NEW: r(5) -> <v15>
|
||||
{ l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } <v15>: * COPY
|
||||
2 <v16>: * NEW: r(2) -> <v16>
|
||||
{ 2 } <v16>: * COPY
|
||||
try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 } <v17>: * NEW: merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 }|<v15>) -> <v17>
|
||||
{ try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } 5 } finally { 2 } } <v17>: * COPY
|
||||
=====================
|
||||
== t10 ==
|
||||
fun t10(a : Int) {
|
||||
@@ -305,25 +305,25 @@ fun t10(a : Int) {
|
||||
}
|
||||
---------------------
|
||||
<v0>: Int NEW: magic[FAKE_INITIALIZER](a : Int) -> <v0>
|
||||
<v4>: Int NEW: magic[LOOP_RANGE_ITERATION](1..a|<v3>) -> <v4>
|
||||
<v7>: Int NEW: magic[LOOP_RANGE_ITERATION](1..a|<v6>) -> <v7>
|
||||
1 <v1>: Int NEW: r(1) -> <v1>
|
||||
a <v2>: Int NEW: r(a) -> <v2>
|
||||
1..a <v3>: {<: Iterable<Int>} NEW: call(1..a, rangeTo|<v1>, <v2>) -> <v3>
|
||||
1 <v5>: * NEW: r(1) -> <v5>
|
||||
2 <v6>: {<: Comparable<Int>} NEW: r(2) -> <v6>
|
||||
3 <v7>: Int NEW: r(3) -> <v7>
|
||||
2 > 3 <v8>: Boolean NEW: call(2 > 3, compareTo|<v6>, <v7>) -> <v8>
|
||||
continue@l !<v9>: *
|
||||
{ continue@l } !<v9>: * COPY
|
||||
if (2 > 3) { continue@l } <v10>: * NEW: merge(if (2 > 3) { continue@l }|!<v9>) -> <v10>
|
||||
{ 1 if (2 > 3) { continue@l } } <v10>: * COPY
|
||||
for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v11>: *
|
||||
l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v11>: * COPY
|
||||
{ l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } !<v11>: * COPY
|
||||
2 <v12>: * NEW: r(2) -> <v12>
|
||||
{ 2 } <v12>: * COPY
|
||||
try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 } <v13>: * NEW: merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 }|!<v11>) -> <v13>
|
||||
{ try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 } } <v13>: * COPY
|
||||
1..a <v6>: {<: Iterable<Int>} NEW: call(1..a, next) -> <v6>
|
||||
1 <v8>: * NEW: r(1) -> <v8>
|
||||
2 <v9>: {<: Comparable<Int>} NEW: r(2) -> <v9>
|
||||
3 <v10>: Int NEW: r(3) -> <v10>
|
||||
2 > 3 <v11>: Boolean NEW: call(2 > 3, compareTo|<v9>, <v10>) -> <v11>
|
||||
continue@l !<v12>: *
|
||||
{ continue@l } !<v12>: * COPY
|
||||
if (2 > 3) { continue@l } <v13>: * NEW: merge(if (2 > 3) { continue@l }|!<v12>) -> <v13>
|
||||
{ 1 if (2 > 3) { continue@l } } <v13>: * COPY
|
||||
for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v14>: *
|
||||
l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } !<v14>: * COPY
|
||||
{ l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } !<v14>: * COPY
|
||||
2 <v15>: * NEW: r(2) -> <v15>
|
||||
{ 2 } <v15>: * COPY
|
||||
try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 } <v16>: * NEW: merge(try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 }|!<v14>) -> <v16>
|
||||
{ try { l@ for (i in 1..a) { 1 if (2 > 3) { continue@l } } } finally { 2 } } <v16>: * COPY
|
||||
=====================
|
||||
== t11 ==
|
||||
fun t11() {
|
||||
@@ -335,14 +335,14 @@ fun t11() {
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
1 <v0>: Unit NEW: r(1) -> <v0>
|
||||
return 1 !<v3>: *
|
||||
{ return 1 } !<v3>: * COPY
|
||||
2 <v1>: Unit NEW: r(2) -> <v1>
|
||||
return 2 !<v2>: *
|
||||
{ return 2 } !<v2>: * COPY
|
||||
1 <v0>: Unit NEW: r(1) -> <v0>
|
||||
return 1 !<v3>: *
|
||||
{ return 1 } !<v3>: * COPY
|
||||
2 <v1>: Unit NEW: r(2) -> <v1>
|
||||
return 2 !<v2>: *
|
||||
{ return 2 } !<v2>: * COPY
|
||||
try { return 1 } finally { return 2 } <v4>: * NEW: merge(try { return 1 } finally { return 2 }|!<v3>) -> <v4>
|
||||
{ try { return 1 } finally { return 2 } } <v4>: * COPY
|
||||
{ try { return 1 } finally { return 2 } } <v4>: * COPY
|
||||
=====================
|
||||
== t12 ==
|
||||
fun t12() : Int {
|
||||
@@ -354,14 +354,14 @@ fun t12() : Int {
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
1 <v0>: Int NEW: r(1) -> <v0>
|
||||
return 1 !<v3>: *
|
||||
{ return 1 } !<v3>: * COPY
|
||||
3 <v1>: Int NEW: r(3) -> <v1>
|
||||
doSmth(3) <v2>: * NEW: call(doSmth(3), doSmth|<v1>) -> <v2>
|
||||
{ doSmth(3) } <v2>: * COPY
|
||||
1 <v0>: Int NEW: r(1) -> <v0>
|
||||
return 1 !<v3>: *
|
||||
{ return 1 } !<v3>: * COPY
|
||||
3 <v1>: Int NEW: r(3) -> <v1>
|
||||
doSmth(3) <v2>: * NEW: call(doSmth(3), doSmth|<v1>) -> <v2>
|
||||
{ doSmth(3) } <v2>: * COPY
|
||||
try { return 1 } finally { doSmth(3) } <v4>: * NEW: merge(try { return 1 } finally { doSmth(3) }|!<v3>) -> <v4>
|
||||
{ try { return 1 } finally { doSmth(3) } } <v4>: * COPY
|
||||
{ try { return 1 } finally { doSmth(3) } } <v4>: * COPY
|
||||
=====================
|
||||
== t13 ==
|
||||
fun t13() : Int {
|
||||
|
||||
+13
-7
@@ -12,19 +12,25 @@ L0:
|
||||
r(2) -> <v1>
|
||||
mark(1..2)
|
||||
call(1..2, rangeTo|<v0>, <v1>) -> <v2>
|
||||
mark(1..2)
|
||||
call(1..2, iterator|<v2>) -> <v3>
|
||||
v(i)
|
||||
L2 [loop entry point]:
|
||||
L6 [condition entry point]:
|
||||
jmp?(L3) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..2|<v2>) -> <v3>] PREV:[v(i), jmp(L2)]
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v2>) -> <v3>
|
||||
w(i|<v3>)
|
||||
mark(1..2) PREV:[v(i), jmp(L2)]
|
||||
call(1..2, hasNext) -> <v4>
|
||||
jmp?(L3) NEXT:[read (Unit), mark(1..2)]
|
||||
mark(1..2)
|
||||
call(1..2, next) -> <v5>
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v5>) -> <v6>
|
||||
w(i|<v6>)
|
||||
mark(for (i in 1..2) { doSmth(i) })
|
||||
L4 [body entry point]:
|
||||
4 mark({ doSmth(i) })
|
||||
r(i) -> <v4>
|
||||
r(i) -> <v7>
|
||||
mark(doSmth(i))
|
||||
call(doSmth(i), doSmth|<v4>) -> <v5>
|
||||
3 jmp(L2) NEXT:[jmp?(L3)]
|
||||
call(doSmth(i), doSmth|<v7>) -> <v8>
|
||||
3 jmp(L2) NEXT:[mark(1..2)]
|
||||
L3 [loop exit point]:
|
||||
L5 [body exit point]:
|
||||
read (Unit) PREV:[jmp?(L3)]
|
||||
@@ -51,4 +57,4 @@ error:
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
=====================
|
||||
|
||||
+9
-9
@@ -5,15 +5,15 @@ fun t1() {
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
<v3>: Int NEW: magic[LOOP_RANGE_ITERATION](1..2|<v2>) -> <v3>
|
||||
1 <v0>: Int NEW: r(1) -> <v0>
|
||||
2 <v1>: Int NEW: r(2) -> <v1>
|
||||
1..2 <v2>: {<: Iterable<Int>} NEW: call(1..2, rangeTo|<v0>, <v1>) -> <v2>
|
||||
i <v4>: Int NEW: r(i) -> <v4>
|
||||
doSmth(i) <v5>: * NEW: call(doSmth(i), doSmth|<v4>) -> <v5>
|
||||
{ doSmth(i) } <v5>: * COPY
|
||||
for (i in 1..2) { doSmth(i) } !<v6>: *
|
||||
{ for (i in 1..2) { doSmth(i) } } !<v6>: * COPY
|
||||
<v6>: Int NEW: magic[LOOP_RANGE_ITERATION](1..2|<v5>) -> <v6>
|
||||
1 <v0>: Int NEW: r(1) -> <v0>
|
||||
2 <v1>: Int NEW: r(2) -> <v1>
|
||||
1..2 <v5>: {<: Iterable<Int>} NEW: call(1..2, next) -> <v5>
|
||||
i <v7>: Int NEW: r(i) -> <v7>
|
||||
doSmth(i) <v8>: * NEW: call(doSmth(i), doSmth|<v7>) -> <v8>
|
||||
{ doSmth(i) } <v8>: * COPY
|
||||
for (i in 1..2) { doSmth(i) } !<v9>: *
|
||||
{ for (i in 1..2) { doSmth(i) } } !<v9>: * COPY
|
||||
=====================
|
||||
== doSmth ==
|
||||
fun doSmth(i: Int) {}
|
||||
|
||||
@@ -16,26 +16,32 @@ L0:
|
||||
r(10) -> <v2>
|
||||
mark(1..10)
|
||||
call(1..10, rangeTo|<v1>, <v2>) -> <v3>
|
||||
mark(1..10)
|
||||
call(1..10, iterator|<v3>) -> <v4>
|
||||
v(i)
|
||||
L2 [loop entry point]:
|
||||
L6 [condition entry point]:
|
||||
jmp?(L3) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..10|<v3>) -> <v4>] PREV:[v(i), jmp(L6)]
|
||||
magic[LOOP_RANGE_ITERATION](1..10|<v3>) -> <v4>
|
||||
w(i|<v4>)
|
||||
mark(1..10) PREV:[v(i), jmp(L6)]
|
||||
call(1..10, hasNext) -> <v5>
|
||||
jmp?(L3) NEXT:[read (Unit), mark(1..10)]
|
||||
mark(1..10)
|
||||
call(1..10, next) -> <v6>
|
||||
magic[LOOP_RANGE_ITERATION](1..10|<v6>) -> <v7>
|
||||
w(i|<v7>)
|
||||
mark(for (i in 1..10) { if (b) break; continue; })
|
||||
L4 [body entry point]:
|
||||
4 mark({ if (b) break; continue; })
|
||||
mark(if (b) break)
|
||||
r(b) -> <v5>
|
||||
jf(L7|<v5>) NEXT:[read (Unit), jmp(L3)]
|
||||
r(b) -> <v8>
|
||||
jf(L7|<v8>) NEXT:[read (Unit), jmp(L3)]
|
||||
jmp(L3) NEXT:[read (Unit)]
|
||||
- jmp(L8) NEXT:[merge(if (b) break|!<v6>) -> <v7>] PREV:[]
|
||||
- jmp(L8) NEXT:[merge(if (b) break|!<v9>) -> <v10>] PREV:[]
|
||||
L7 [else branch]:
|
||||
read (Unit) PREV:[jf(L7|<v5>)]
|
||||
read (Unit) PREV:[jf(L7|<v8>)]
|
||||
L8 ['if' expression result]:
|
||||
merge(if (b) break|!<v6>) -> <v7>
|
||||
jmp(L6) NEXT:[jmp?(L3)]
|
||||
- 3 jmp(L2) NEXT:[jmp?(L3)] PREV:[]
|
||||
merge(if (b) break|!<v9>) -> <v10>
|
||||
jmp(L6) NEXT:[mark(1..10)]
|
||||
- 3 jmp(L2) NEXT:[mark(1..10)] PREV:[]
|
||||
L3 [loop exit point]:
|
||||
L5 [body exit point]:
|
||||
read (Unit) PREV:[jmp?(L3), jmp(L3)]
|
||||
@@ -45,4 +51,4 @@ error:
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
=====================
|
||||
|
||||
+10
-10
@@ -7,15 +7,15 @@ fun test(b: Boolean) {
|
||||
}
|
||||
---------------------
|
||||
<v0>: Boolean NEW: magic[FAKE_INITIALIZER](b: Boolean) -> <v0>
|
||||
<v4>: Int NEW: magic[LOOP_RANGE_ITERATION](1..10|<v3>) -> <v4>
|
||||
<v7>: Int NEW: magic[LOOP_RANGE_ITERATION](1..10|<v6>) -> <v7>
|
||||
1 <v1>: Int NEW: r(1) -> <v1>
|
||||
10 <v2>: Int NEW: r(10) -> <v2>
|
||||
1..10 <v3>: {<: Iterable<Int>} NEW: call(1..10, rangeTo|<v1>, <v2>) -> <v3>
|
||||
b <v5>: Boolean NEW: r(b) -> <v5>
|
||||
break !<v6>: *
|
||||
if (b) break <v7>: * NEW: merge(if (b) break|!<v6>) -> <v7>
|
||||
continue !<v8>: *
|
||||
{ if (b) break; continue; } !<v8>: * COPY
|
||||
for (i in 1..10) { if (b) break; continue; } !<v9>: *
|
||||
{ for (i in 1..10) { if (b) break; continue; } } !<v9>: * COPY
|
||||
=====================
|
||||
1..10 <v6>: {<: Iterable<Int>} NEW: call(1..10, next) -> <v6>
|
||||
b <v8>: Boolean NEW: r(b) -> <v8>
|
||||
break !<v9>: *
|
||||
if (b) break <v10>: * NEW: merge(if (b) break|!<v9>) -> <v10>
|
||||
continue !<v11>: *
|
||||
{ if (b) break; continue; } !<v11>: * COPY
|
||||
for (i in 1..10) { if (b) break; continue; } !<v12>: *
|
||||
{ for (i in 1..10) { if (b) break; continue; } } !<v12>: * COPY
|
||||
=====================
|
||||
|
||||
+62
-38
@@ -67,39 +67,45 @@ L4 [start finally]:
|
||||
r(2) -> <v6>
|
||||
mark(1..2)
|
||||
call(1..2, rangeTo|<v5>, <v6>) -> <v7>
|
||||
mark(1..2)
|
||||
call(1..2, iterator|<v7>) -> <v8>
|
||||
v(i)
|
||||
L5 [loop entry point]:
|
||||
L9 [condition entry point]:
|
||||
jmp?(L6) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>] PREV:[v(i), jmp(L5)]
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>
|
||||
w(i|<v8>)
|
||||
mark(1..2) PREV:[v(i), jmp(L5)]
|
||||
call(1..2, hasNext) -> <v9>
|
||||
jmp?(L6) NEXT:[read (Unit), mark(1..2)]
|
||||
mark(1..2)
|
||||
call(1..2, next) -> <v10>
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v10>) -> <v11>
|
||||
w(i|<v11>)
|
||||
mark(for (i in 1..2) { })
|
||||
L7 [body entry point]:
|
||||
6 mark({ })
|
||||
read (Unit)
|
||||
5 jmp(L5) NEXT:[jmp?(L6)]
|
||||
5 jmp(L5) NEXT:[mark(1..2)]
|
||||
L6 [loop exit point]:
|
||||
L8 [body exit point]:
|
||||
read (Unit) PREV:[jmp?(L6)]
|
||||
4 mark(bar())
|
||||
call(bar(), bar) -> <v9>
|
||||
ret(*|<v9>) L1 NEXT:[<END>]
|
||||
call(bar(), bar) -> <v12>
|
||||
ret(*|<v12>) L1 NEXT:[<END>]
|
||||
L10 [finish finally]:
|
||||
- 3 ret(*|<v4>) L1 NEXT:[<END>] PREV:[]
|
||||
- jmp(L11) NEXT:[merge(if (n < 0) return 0|!<v11>) -> <v12>] PREV:[]
|
||||
- jmp(L11) NEXT:[merge(if (n < 0) return 0|!<v14>) -> <v15>] PREV:[]
|
||||
L3 [else branch]:
|
||||
read (Unit) PREV:[jf(L3|<v3>)]
|
||||
L11 ['if' expression result]:
|
||||
merge(if (n < 0) return 0|!<v11>) -> <v12>
|
||||
merge(if (n < 0) return 0|!<v14>) -> <v15>
|
||||
mark(n.let { return it })
|
||||
r(n) -> <v13>
|
||||
r(n) -> <v16>
|
||||
mark({ return it })
|
||||
jmp?(L12) NEXT:[r({ return it }) -> <v14>, d({ return it })]
|
||||
jmp?(L12) NEXT:[r({ return it }) -> <v17>, d({ return it })]
|
||||
d({ return it }) NEXT:[<SINK>]
|
||||
L12 [after local declaration]:
|
||||
r({ return it }) -> <v14> PREV:[jmp?(L12)]
|
||||
r({ return it }) -> <v17> PREV:[jmp?(L12)]
|
||||
mark(let { return it })
|
||||
call(let { return it }, let|<v13>, <v14>) -> <v15>
|
||||
call(let { return it }, let|<v16>, <v17>) -> <v18>
|
||||
2 jmp?(L2) NEXT:[mark({ for (i in 1..2) { } return bar() }), jmp(L20)]
|
||||
jmp(L20) NEXT:[mark({ for (i in 1..2) { } return bar() })]
|
||||
L2 [onExceptionToFinallyBlock]:
|
||||
@@ -108,23 +114,29 @@ L2 [onExceptionToFinallyBlock]:
|
||||
r(2) -> <v6>
|
||||
mark(1..2)
|
||||
call(1..2, rangeTo|<v5>, <v6>) -> <v7>
|
||||
mark(1..2)
|
||||
call(1..2, iterator|<v7>) -> <v8>
|
||||
v(i)
|
||||
L21 [copy of L5, loop entry point]:
|
||||
L25 [copy of L9, condition entry point]:
|
||||
jmp?(L22) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>] PREV:[v(i), jmp(L21)]
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>
|
||||
w(i|<v8>)
|
||||
mark(1..2) PREV:[v(i), jmp(L21)]
|
||||
call(1..2, hasNext) -> <v9>
|
||||
jmp?(L22) NEXT:[read (Unit), mark(1..2)]
|
||||
mark(1..2)
|
||||
call(1..2, next) -> <v10>
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v10>) -> <v11>
|
||||
w(i|<v11>)
|
||||
mark(for (i in 1..2) { })
|
||||
L23 [copy of L7, body entry point]:
|
||||
6 mark({ })
|
||||
read (Unit)
|
||||
5 jmp(L21) NEXT:[jmp?(L22)]
|
||||
5 jmp(L21) NEXT:[mark(1..2)]
|
||||
L22 [copy of L6, loop exit point]:
|
||||
L24 [copy of L8, body exit point]:
|
||||
read (Unit) PREV:[jmp?(L22)]
|
||||
4 mark(bar())
|
||||
call(bar(), bar) -> <v9>
|
||||
ret(*|<v9>) L1 NEXT:[<END>]
|
||||
call(bar(), bar) -> <v12>
|
||||
ret(*|<v12>) L1 NEXT:[<END>]
|
||||
- 2 jmp(error) NEXT:[<ERROR>] PREV:[]
|
||||
L20 [skipFinallyToErrorBlock]:
|
||||
4 mark({ for (i in 1..2) { } return bar() }) PREV:[jmp(L20)]
|
||||
@@ -132,26 +144,32 @@ L20 [skipFinallyToErrorBlock]:
|
||||
r(2) -> <v6>
|
||||
mark(1..2)
|
||||
call(1..2, rangeTo|<v5>, <v6>) -> <v7>
|
||||
mark(1..2)
|
||||
call(1..2, iterator|<v7>) -> <v8>
|
||||
v(i)
|
||||
L26 [copy of L5, loop entry point]:
|
||||
L30 [copy of L9, condition entry point]:
|
||||
jmp?(L27) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>] PREV:[v(i), jmp(L26)]
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>
|
||||
w(i|<v8>)
|
||||
mark(1..2) PREV:[v(i), jmp(L26)]
|
||||
call(1..2, hasNext) -> <v9>
|
||||
jmp?(L27) NEXT:[read (Unit), mark(1..2)]
|
||||
mark(1..2)
|
||||
call(1..2, next) -> <v10>
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v10>) -> <v11>
|
||||
w(i|<v11>)
|
||||
mark(for (i in 1..2) { })
|
||||
L28 [copy of L7, body entry point]:
|
||||
6 mark({ })
|
||||
read (Unit)
|
||||
5 jmp(L26) NEXT:[jmp?(L27)]
|
||||
5 jmp(L26) NEXT:[mark(1..2)]
|
||||
L27 [copy of L6, loop exit point]:
|
||||
L29 [copy of L8, body exit point]:
|
||||
read (Unit) PREV:[jmp?(L27)]
|
||||
4 mark(bar())
|
||||
call(bar(), bar) -> <v9>
|
||||
ret(*|<v9>) L1 NEXT:[<END>]
|
||||
- 2 merge(try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() }|<v15>) -> <v16> PREV:[]
|
||||
call(bar(), bar) -> <v12>
|
||||
ret(*|<v12>) L1 NEXT:[<END>]
|
||||
- 2 merge(try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() }|<v18>) -> <v19> PREV:[]
|
||||
L1:
|
||||
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v9>) L1, ret(*|<v9>) L1, ret(*|<v9>) L1, ret(*|<v9>) L1]
|
||||
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v12>) L1, ret(*|<v12>) L1, ret(*|<v12>) L1, ret(*|<v12>) L1]
|
||||
error:
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
@@ -169,29 +187,35 @@ L13:
|
||||
r(2) -> <v6>
|
||||
mark(1..2)
|
||||
call(1..2, rangeTo|<v5>, <v6>) -> <v7>
|
||||
mark(1..2)
|
||||
call(1..2, iterator|<v7>) -> <v8>
|
||||
v(i)
|
||||
L15 [copy of L5, loop entry point]:
|
||||
L19 [copy of L9, condition entry point]:
|
||||
jmp?(L16) NEXT:[read (Unit), magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>] PREV:[v(i), jmp(L15)]
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>
|
||||
w(i|<v8>)
|
||||
mark(1..2) PREV:[v(i), jmp(L15)]
|
||||
call(1..2, hasNext) -> <v9>
|
||||
jmp?(L16) NEXT:[read (Unit), mark(1..2)]
|
||||
mark(1..2)
|
||||
call(1..2, next) -> <v10>
|
||||
magic[LOOP_RANGE_ITERATION](1..2|<v10>) -> <v11>
|
||||
w(i|<v11>)
|
||||
mark(for (i in 1..2) { })
|
||||
L17 [copy of L7, body entry point]:
|
||||
6 mark({ })
|
||||
read (Unit)
|
||||
5 jmp(L15) NEXT:[jmp?(L16)]
|
||||
5 jmp(L15) NEXT:[mark(1..2)]
|
||||
L16 [copy of L6, loop exit point]:
|
||||
L18 [copy of L8, body exit point]:
|
||||
read (Unit) PREV:[jmp?(L16)]
|
||||
read (Unit) PREV:[jmp?(L16)]
|
||||
4 mark(bar())
|
||||
call(bar(), bar) -> <v9>
|
||||
ret(*|<v9>) L1 NEXT:[<END>]
|
||||
- 5 ret(*|<v0>) L1 NEXT:[<END>] PREV:[]
|
||||
- 4 ret(*|!<v1>) L14 PREV:[]
|
||||
call(bar(), bar) -> <v12>
|
||||
ret(*|<v12>) L1 NEXT:[<END>]
|
||||
- 5 ret(*|<v0>) L1 NEXT:[<END>] PREV:[]
|
||||
- 4 ret(*|!<v1>) L14 PREV:[]
|
||||
L14:
|
||||
<END> NEXT:[<SINK>] PREV:[]
|
||||
<END> NEXT:[<SINK>] PREV:[]
|
||||
error:
|
||||
<ERROR> PREV:[]
|
||||
<ERROR> PREV:[]
|
||||
sink:
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
<SINK> PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
|
||||
+17
-17
@@ -25,32 +25,32 @@ fun foo(n: Int): Int {
|
||||
}
|
||||
---------------------
|
||||
<v0>: Int NEW: magic[FAKE_INITIALIZER](n: Int) -> <v0>
|
||||
<v8>: Int NEW: magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>
|
||||
<v11>: Int NEW: magic[LOOP_RANGE_ITERATION](1..2|<v10>) -> <v11>
|
||||
n <v1>: {<: Comparable<Int>} NEW: r(n) -> <v1>
|
||||
0 <v2>: Int NEW: r(0) -> <v2>
|
||||
n < 0 <v3>: Boolean NEW: call(n < 0, compareTo|<v1>, <v2>) -> <v3>
|
||||
0 <v4>: Int NEW: r(0) -> <v4>
|
||||
return 0 !<v11>: *
|
||||
if (n < 0) return 0 <v12>: * NEW: merge(if (n < 0) return 0|!<v11>) -> <v12>
|
||||
n <v13>: Int NEW: r(n) -> <v13>
|
||||
{ return it } <v14>: {<: (Int) -> ???} NEW: r({ return it }) -> <v14>
|
||||
let { return it } <v15>: * NEW: call(let { return it }, let|<v13>, <v14>) -> <v15>
|
||||
n.let { return it } <v15>: * COPY
|
||||
{ if (n < 0) return 0 n.let { return it } } <v15>: * COPY
|
||||
return 0 !<v14>: *
|
||||
if (n < 0) return 0 <v15>: * NEW: merge(if (n < 0) return 0|!<v14>) -> <v15>
|
||||
n <v16>: Int NEW: r(n) -> <v16>
|
||||
{ return it } <v17>: {<: (Int) -> ???} NEW: r({ return it }) -> <v17>
|
||||
let { return it } <v18>: * NEW: call(let { return it }, let|<v16>, <v17>) -> <v18>
|
||||
n.let { return it } <v18>: * COPY
|
||||
{ if (n < 0) return 0 n.let { return it } } <v18>: * COPY
|
||||
1 <v5>: Int NEW: r(1) -> <v5>
|
||||
2 <v6>: Int NEW: r(2) -> <v6>
|
||||
1..2 <v7>: {<: Iterable<Int>} NEW: call(1..2, rangeTo|<v5>, <v6>) -> <v7>
|
||||
bar() <v9>: Int NEW: call(bar(), bar) -> <v9>
|
||||
return bar() !<v10>: *
|
||||
{ for (i in 1..2) { } return bar() } !<v10>: * COPY
|
||||
try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() } <v16>: * NEW: merge(try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() }|<v15>) -> <v16>
|
||||
{ try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() } } <v16>: * COPY
|
||||
1..2 <v10>: {<: Iterable<Int>} NEW: call(1..2, next) -> <v10>
|
||||
bar() <v12>: Int NEW: call(bar(), bar) -> <v12>
|
||||
return bar() !<v13>: *
|
||||
{ for (i in 1..2) { } return bar() } !<v13>: * COPY
|
||||
try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() } <v19>: * NEW: merge(try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() }|<v18>) -> <v19>
|
||||
{ try { if (n < 0) return 0 n.let { return it } } finally { for (i in 1..2) { } return bar() } } <v19>: * COPY
|
||||
=====================
|
||||
== anonymous_0 ==
|
||||
{ return it }
|
||||
---------------------
|
||||
<v8>: Int NEW: magic[LOOP_RANGE_ITERATION](1..2|<v7>) -> <v8>
|
||||
it <v0>: Int NEW: r(it) -> <v0>
|
||||
<v11>: Int NEW: magic[LOOP_RANGE_ITERATION](1..2|<v10>) -> <v11>
|
||||
it <v0>: Int NEW: r(it) -> <v0>
|
||||
return it !<v1>: *
|
||||
return it !<v1>: * COPY
|
||||
return it !<v1>: * COPY
|
||||
=====================
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
interface AsyncGenerator<in T> {
|
||||
suspend fun yield(value: T)
|
||||
}
|
||||
|
||||
interface AsyncSequence<out T> {
|
||||
operator fun iterator(): AsyncIterator<T>
|
||||
}
|
||||
|
||||
interface AsyncIterator<out T> {
|
||||
operator suspend fun hasNext(): Boolean
|
||||
operator suspend fun next(): T
|
||||
}
|
||||
|
||||
fun <T> asyncGenerate(block: suspend AsyncGenerator<T>.() -> Unit): AsyncSequence<T> = object : AsyncSequence<T> {
|
||||
override fun iterator(): AsyncIterator<T> {
|
||||
val iterator = AsyncGeneratorIterator<T>()
|
||||
iterator.nextStep = block.createCoroutine(receiver = iterator, completion = iterator)
|
||||
return iterator
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuation<Unit> {
|
||||
var computedNext = false
|
||||
var nextValue: T? = null
|
||||
var nextStep: Continuation<Unit>? = null
|
||||
|
||||
// if (computesNext) computeContinuation is Continuation<T>
|
||||
// if (!computesNext) computeContinuation is Continuation<Boolean>
|
||||
var computesNext = false
|
||||
var computeContinuation: Continuation<*>? = null
|
||||
|
||||
override val context = EmptyCoroutineContext
|
||||
|
||||
suspend fun computeHasNext(): Boolean = suspendCoroutineOrReturn { c ->
|
||||
computesNext = false
|
||||
computeContinuation = c
|
||||
nextStep!!.resume(Unit)
|
||||
SUSPENDED_MARKER
|
||||
}
|
||||
|
||||
suspend fun computeNext(): T = suspendCoroutineOrReturn { c ->
|
||||
computesNext = true
|
||||
computeContinuation = c
|
||||
nextStep!!.resume(Unit)
|
||||
SUSPENDED_MARKER
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun resumeIterator(exception: Throwable?) {
|
||||
if (exception != null) {
|
||||
done()
|
||||
computeContinuation!!.resumeWithException(exception)
|
||||
return
|
||||
}
|
||||
if (computesNext) {
|
||||
computedNext = false
|
||||
(computeContinuation as Continuation<T>).resume(nextValue as T)
|
||||
} else {
|
||||
(computeContinuation as Continuation<Boolean>).resume(nextStep != null)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun hasNext(): Boolean {
|
||||
if (!computedNext) return computeHasNext()
|
||||
return nextStep != null
|
||||
}
|
||||
|
||||
override suspend fun next(): T {
|
||||
if (!computedNext) return computeNext()
|
||||
computedNext = false
|
||||
return nextValue as T
|
||||
}
|
||||
|
||||
private fun done() {
|
||||
computedNext = true
|
||||
nextStep = null
|
||||
}
|
||||
|
||||
// Completion continuation implementation
|
||||
override fun resume(value: Unit) {
|
||||
done()
|
||||
resumeIterator(null)
|
||||
}
|
||||
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
done()
|
||||
resumeIterator(exception)
|
||||
}
|
||||
|
||||
// Generator implementation
|
||||
override suspend fun yield(value: T): Unit = suspendCoroutineOrReturn { c ->
|
||||
computedNext = true
|
||||
nextValue = value
|
||||
nextStep = c
|
||||
resumeIterator(null)
|
||||
SUSPENDED_MARKER
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun <T> AsyncSequence<T>.toList(): List<T> {
|
||||
val out = arrayListOf<T>()
|
||||
for (e in this@toList) out += e // fails at this line
|
||||
return out
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val seq = asyncGenerate {
|
||||
yield("O")
|
||||
yield("K")
|
||||
}
|
||||
|
||||
var res = listOf<String>()
|
||||
|
||||
builder {
|
||||
res = seq.toList()
|
||||
}
|
||||
|
||||
if (res.size > 2) return "fail 1: ${res.size}"
|
||||
|
||||
return res[0] + res[1]
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
@kotlin.Metadata
|
||||
public interface AsyncGenerator {
|
||||
public abstract @org.jetbrains.annotations.Nullable method yield(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class AsyncGeneratorIterator {
|
||||
private @org.jetbrains.annotations.Nullable field computeContinuation: kotlin.coroutines.Continuation
|
||||
private field computedNext: boolean
|
||||
private field computesNext: boolean
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.EmptyCoroutineContext
|
||||
private @org.jetbrains.annotations.Nullable field nextStep: kotlin.coroutines.Continuation
|
||||
private @org.jetbrains.annotations.Nullable field nextValue: java.lang.Object
|
||||
public method <init>(): void
|
||||
public final @org.jetbrains.annotations.Nullable method computeHasNext(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
public final @org.jetbrains.annotations.Nullable method computeNext(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
private final method done(): void
|
||||
public final @org.jetbrains.annotations.Nullable method getComputeContinuation(): kotlin.coroutines.Continuation
|
||||
public final method getComputedNext(): boolean
|
||||
public final method getComputesNext(): boolean
|
||||
public synthetic method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.EmptyCoroutineContext
|
||||
public final @org.jetbrains.annotations.Nullable method getNextStep(): kotlin.coroutines.Continuation
|
||||
public final @org.jetbrains.annotations.Nullable method getNextValue(): java.lang.Object
|
||||
public @org.jetbrains.annotations.Nullable method hasNext(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
public @org.jetbrains.annotations.Nullable method next(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
public method resume(@org.jetbrains.annotations.NotNull p0: kotlin.Unit): void
|
||||
public synthetic method resume(p0: java.lang.Object): void
|
||||
public final @kotlin.Suppress method resumeIterator(@org.jetbrains.annotations.Nullable p0: java.lang.Throwable): void
|
||||
public method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
|
||||
public final method setComputeContinuation(@org.jetbrains.annotations.Nullable p0: kotlin.coroutines.Continuation): void
|
||||
public final method setComputedNext(p0: boolean): void
|
||||
public final method setComputesNext(p0: boolean): void
|
||||
public final method setNextStep(@org.jetbrains.annotations.Nullable p0: kotlin.coroutines.Continuation): void
|
||||
public final method setNextValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void
|
||||
public @org.jetbrains.annotations.Nullable method yield(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface AsyncIterator {
|
||||
public abstract @org.jetbrains.annotations.Nullable method hasNext(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
public abstract @org.jetbrains.annotations.Nullable method next(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class AsyncIteratorToListKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method asyncGenerate(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2): AsyncSequence
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
|
||||
public final static @org.jetbrains.annotations.Nullable method toList(@org.jetbrains.annotations.NotNull p0: AsyncSequence, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface AsyncSequence {
|
||||
public abstract @org.jetbrains.annotations.NotNull method iterator(): AsyncIterator
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class CoroutineUtilKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
|
||||
public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public class EmptyContinuation {
|
||||
public final static field Companion: EmptyContinuation.Companion
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.CoroutineContext
|
||||
inner class EmptyContinuation/Companion
|
||||
public @synthetic.kotlin.jvm.GeneratedByJvmOverloads method <init>(): void
|
||||
public method <init>(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): void
|
||||
public synthetic method <init>(p0: kotlin.coroutines.CoroutineContext, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public method resume(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void
|
||||
public method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final static class EmptyContinuation/Companion {
|
||||
inner class EmptyContinuation/Companion
|
||||
private method <init>(): void
|
||||
}
|
||||
+6
@@ -4613,6 +4613,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("asyncIteratorToList.kt")
|
||||
public void testAsyncIteratorToList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/asyncIteratorToList.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("await.kt")
|
||||
public void testAwait() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/await.kt");
|
||||
|
||||
@@ -4613,6 +4613,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("asyncIteratorToList.kt")
|
||||
public void testAsyncIteratorToList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/asyncIteratorToList.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("await.kt")
|
||||
public void testAwait() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/await.kt");
|
||||
|
||||
@@ -4613,6 +4613,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("asyncIteratorToList.kt")
|
||||
public void testAsyncIteratorToList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/asyncIteratorToList.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("await.kt")
|
||||
public void testAwait() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/await.kt");
|
||||
|
||||
@@ -5304,6 +5304,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("asyncIteratorToList.kt")
|
||||
public void testAsyncIteratorToList() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/asyncIteratorToList.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("await.kt")
|
||||
public void testAwait() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/await.kt");
|
||||
|
||||
Reference in New Issue
Block a user