JVM_IR: Support inner lambdas which capture crossinline

This commit is contained in:
Ilmir Usmanov
2019-12-09 19:50:50 +03:00
parent daa76cbf1e
commit 9292022f88
7 changed files with 16 additions and 10 deletions
@@ -131,6 +131,12 @@ class MethodInliner(
processReturns(resultNode, returnLabelOwner, remapReturn, end)
//flush transformed node to output
// TODO: HACK resultNode's invisibleParameterAnnotations' size is greater than adapter's
if (resultNode.name == "<init>" && resultNode.desc.contains("Lkotlin/coroutines/Continuation;") &&
inliningContext.root.state.isIrBackend
) {
resultNode.invisibleParameterAnnotations = null
}
resultNode.accept(SkipMaxAndEndVisitor(adapter))
sourceMapper.endMapping()
@@ -652,11 +652,20 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
expression.acceptChildrenVoid(this)
if (expression.isSuspend && expression !in inlineLambdas && expression.origin == IrStatementOrigin.LAMBDA) {
var expressionCapturesCrossinline = false
for (i in 0 until expression.valueArgumentsCount) {
val getValue = expression.getValueArgument(i) as? IrGetValue ?: continue
val owner = getValue.symbol.owner as? IrValueParameter ?: continue
if (owner.isCrossinline) {
expressionCapturesCrossinline = true
break
}
}
suspendLambdas += SuspendLambdaInfo(
expression.symbol.owner,
(expression.type as IrSimpleType).arguments.size - 1,
expression,
expression in capturesCrossinline
expressionCapturesCrossinline || expression in capturesCrossinline
)
}
}
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// FILE: test.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// FILE: inlined.kt
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// FILE: inlined.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// FILE: inlined.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// COMMON_COROUTINES_TEST
// WITH_RUNTIME