From f9f715c31eccdce868808a94d30afa0696a9f53a Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Tue, 18 Feb 2020 13:10:24 +0100 Subject: [PATCH] Support suspend lambda with arity 22 in old BE Somehow, I missed, that its 'create' function has bit arity, while 'invoke' does not. Thus, instead of directly passing arguments of 'invoke' to 'create', pack them into an array first. --- .../codegen/coroutines/CoroutineCodegen.kt | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt index 684805b3b69..f3135f724e6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt @@ -307,10 +307,29 @@ class CoroutineCodegenForLambda private constructor( val createArgumentTypes = if (generateErasedCreate || doNotGenerateInvokeBridge) typeMapper.mapAsmMethod(createCoroutineDescriptor).argumentTypes.asList() else parameterTypes - var index = 0 - parameterTypes.withVariableIndices().forEach { (varIndex, type) -> - load(varIndex + 1, type) - StackValue.coerce(type, createArgumentTypes[index++], this) + // invoke is not big arity, but create is. Pass an array to create. + if (parameterTypes.size == 22 && createArgumentTypes.size == 1) { + iconst(22) + newarray(AsmTypes.OBJECT_TYPE) + // 0 - this + // 1..22 - parameters + // 23 - first empy slot + val arraySlot = 23 + store(arraySlot, AsmTypes.OBJECT_TYPE) + for ((varIndex, type) in parameterTypes.withVariableIndices()) { + load(arraySlot, AsmTypes.OBJECT_TYPE) + iconst(varIndex) + load(varIndex + 1, type) + StackValue.coerce(type, AsmTypes.OBJECT_TYPE, this) + astore(AsmTypes.OBJECT_TYPE) + } + load(arraySlot, AsmTypes.OBJECT_TYPE) + } else { + var index = 0 + parameterTypes.withVariableIndices().forEach { (varIndex, type) -> + load(varIndex + 1, type) + StackValue.coerce(type, createArgumentTypes[index++], this) + } } // this.create(..)