diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt index 96d8178f7a2..395137146ed 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt @@ -54,6 +54,9 @@ internal fun generateStateMachineForNamedFunction( element: KtElement ): MethodVisitor { assert(irFunction.isSuspend) + assert(continuationClassBuilder != null) { + "Class builder for continuation is null" + } val state = classCodegen.state val languageVersionSettings = state.languageVersionSettings assert(languageVersionSettings.isReleaseCoroutines()) { "Experimental coroutines are unsupported in JVM_IR backend" } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 8a78135b121..28a0bd6874d 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -56,7 +56,7 @@ open class FunctionCodegen( if (irFunction.origin != IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) { AnnotationCodegen(classCodegen, context, methodVisitor::visitAnnotation).genAnnotations( - irFunction, + functionView, signature.asmMethod.returnType ) } @@ -70,7 +70,7 @@ open class FunctionCodegen( //TODO: investigate this case: annotation here is generated twice in lowered function and in interface method overload irFunction.origin == JvmLoweredDeclarationOrigin.GENERATED_SAM_IMPLEMENTATION ) { - generateParameterAnnotations(irFunction, methodVisitor, signature, classCodegen, context) + generateParameterAnnotations(functionView, methodVisitor, signature, classCodegen, context) } if (!state.classBuilderMode.generateBodies || flags.and(Opcodes.ACC_ABSTRACT) != 0 || irFunction.isExternal) { @@ -82,8 +82,11 @@ open class FunctionCodegen( ?: context.suspendLambdaToOriginalFunctionMap[irFunction.parent]?.symbol?.descriptor?.psiElement) as? KtElement val continuationClassBuilder = context.continuationClassBuilders[irClass] methodVisitor = when { - // We do not generate continuation and state-machine for synthetic accessors, in a sence, they are tail-call - irFunction.isSuspend && irFunction.origin != JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR -> + irFunction.isSuspend && + // We do not generate continuation and state-machine for synthetic accessors, in a sense, they are tail-call + !irFunction.isDefault() && + // TODO: We should generate two versions of inline suspend function: one with state-machine and one without + !irFunction.isInline -> generateStateMachineForNamedFunction( irFunction, classCodegen, methodVisitor, flags, signature, continuationClassBuilder, element!! ) @@ -101,6 +104,9 @@ open class FunctionCodegen( return signature } + private fun IrFunction.isDefault(): Boolean = + origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER || origin == JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR + private fun calculateMethodFlags(isStatic: Boolean): Int { if (irFunction.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) { return Opcodes.ACC_PUBLIC or Opcodes.ACC_SYNTHETIC.let { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt index 004b5f9f8e9..0312b3cd57e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt @@ -94,8 +94,8 @@ class IrSourceCompilerForInline( callDefault: Boolean, asmMethod: Method ): SMAPAndMethodNode { - assert(callableDescriptor == callElement.descriptor.original) - assert(codegen.lastLineNumber >= 0) + assert(callableDescriptor == callElement.descriptor.original) { "Expected $callableDescriptor got ${callElement.descriptor.original}" } + assert(codegen.lastLineNumber >= 0) { "lastLineNumber shall be not negative, but is ${codegen.lastLineNumber}" } val irFunction = getFunctionToInline(callElement as IrCall, jvmSignature, callDefault) return makeInlineNode(irFunction, FakeClassCodegen(irFunction, codegen.classCodegen), CallSiteMarker(codegen.lastLineNumber)) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index 6586ab5f839..8c81af03c27 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -385,6 +385,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : } } + // TODO: Generate two copies of inline suspend functions private fun markSuspendFunctions(irFile: IrFile, suspendLambdas: Set): Set { val result = hashSetOf() @@ -395,7 +396,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : override fun visitFunction(declaration: IrFunction) { super.visitFunction(declaration) - if (declaration.isSuspend && declaration !in suspendLambdas) { + if (declaration.isSuspend && declaration !in suspendLambdas && !declaration.isInline) { result.add(declaration) } } diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferencesWithNullableTypes.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferencesWithNullableTypes.kt index 8ca91f5e47b..3f9a13de024 100644 --- a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferencesWithNullableTypes.kt +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/genericCallableReferencesWithNullableTypes.kt @@ -1,5 +1,4 @@ // IGNORE_BACKEND: NATIVE -// IGNORE_BACKEND: JVM_IR // WITH_REFLECT // WITH_COROUTINES diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt index b3b62254227..e7cb0c2d18e 100644 --- a/compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt @@ -1,5 +1,4 @@ // KJS_WITH_FULL_RUNTIME -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST diff --git a/compiler/testData/codegen/box/coroutines/indirectInlineUsedAsNonInline.kt b/compiler/testData/codegen/box/coroutines/indirectInlineUsedAsNonInline.kt index 7b036b4dcb6..53113bc548a 100644 --- a/compiler/testData/codegen/box/coroutines/indirectInlineUsedAsNonInline.kt +++ b/compiler/testData/codegen/box/coroutines/indirectInlineUsedAsNonInline.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST diff --git a/compiler/testData/codegen/box/coroutines/inlineFunInGenericClass.kt b/compiler/testData/codegen/box/coroutines/inlineFunInGenericClass.kt index 8140b414dc7..ef425c2dcd5 100644 --- a/compiler/testData/codegen/box/coroutines/inlineFunInGenericClass.kt +++ b/compiler/testData/codegen/box/coroutines/inlineFunInGenericClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST diff --git a/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt b/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt index face4b30d5c..6f225d556de 100644 --- a/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt +++ b/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST diff --git a/compiler/testData/codegen/box/coroutines/kt15017.kt b/compiler/testData/codegen/box/coroutines/kt15017.kt index a3d7a84e780..865f44594e9 100644 --- a/compiler/testData/codegen/box/coroutines/kt15017.kt +++ b/compiler/testData/codegen/box/coroutines/kt15017.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST @@ -20,8 +19,8 @@ fun box(): String { var result = "" builder { - result = try { suspendInlineThrow("OK") } catch (e: RuntimeException) { e.message!! } -// result = suspendInline("OK") + result = try { suspendInlineThrow("O") } catch (e: RuntimeException) { e.message!! } + result += suspendInline("K") } return result diff --git a/compiler/testData/codegen/box/coroutines/kt30858.kt b/compiler/testData/codegen/box/coroutines/kt30858.kt index 447a06a605b..09eb7a7d7ea 100644 --- a/compiler/testData/codegen/box/coroutines/kt30858.kt +++ b/compiler/testData/codegen/box/coroutines/kt30858.kt @@ -1,5 +1,5 @@ // !LANGUAGE: +NewInference -// IGNORE_BACKEND: JVM_IR, NATIVE +// IGNORE_BACKEND: NATIVE // WITH_RUNTIME // WITH_COROUTINES diff --git a/compiler/testData/codegen/box/coroutines/multiModule/inlineMultiModule.kt b/compiler/testData/codegen/box/coroutines/multiModule/inlineMultiModule.kt index 46bc07f3640..72cee2ee5e4 100644 --- a/compiler/testData/codegen/box/coroutines/multiModule/inlineMultiModule.kt +++ b/compiler/testData/codegen/box/coroutines/multiModule/inlineMultiModule.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_COROUTINES // WITH_RUNTIME // COMMON_COROUTINES_TEST diff --git a/compiler/testData/codegen/box/coroutines/multiModule/inlineTailCall.kt b/compiler/testData/codegen/box/coroutines/multiModule/inlineTailCall.kt index c24383990be..204539f0b59 100644 --- a/compiler/testData/codegen/box/coroutines/multiModule/inlineTailCall.kt +++ b/compiler/testData/codegen/box/coroutines/multiModule/inlineTailCall.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: NATIVE // WITH_RUNTIME // WITH_COROUTINES diff --git a/compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt b/compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt index ed4c1562151..527fd45bc1b 100644 --- a/compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt +++ b/compiler/testData/codegen/box/coroutines/stackUnwinding/inlineSuspendFunction.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inline.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inline.kt index 4338e64f424..87c31afe684 100644 --- a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inline.kt +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/inline.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST diff --git a/compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIfReturnUnit.kt b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIfReturnUnit.kt index a5defd7bf04..2e20df262cd 100644 --- a/compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIfReturnUnit.kt +++ b/compiler/testData/codegen/box/coroutines/tailCallOptimizations/tailCallIfReturnUnit.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // FULL_JDK // WITH_RUNTIME diff --git a/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/inlineOnly.kt b/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/inlineOnly.kt index 66345fdb106..f9cb727e85d 100644 --- a/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/inlineOnly.kt +++ b/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/inlineOnly.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND_MULTI_MODULE: JVM_IR // WITH_RUNTIME // WITH_COROUTINES diff --git a/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt b/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt index 7fe880838db..59b1f64285d 100644 --- a/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt +++ b/compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND_MULTI_MODULE: JVM_IR // WITH_RUNTIME // WITH_COROUTINES diff --git a/compiler/testData/codegen/boxInline/suspend/stateMachine/unreachableSuspendMarker.kt b/compiler/testData/codegen/boxInline/suspend/stateMachine/unreachableSuspendMarker.kt index baf307510bb..f9872cc285b 100644 --- a/compiler/testData/codegen/boxInline/suspend/stateMachine/unreachableSuspendMarker.kt +++ b/compiler/testData/codegen/boxInline/suspend/stateMachine/unreachableSuspendMarker.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND_MULTI_MODULE: JVM_IR // FILE: inline.kt // COMMON_COROUTINES_TEST