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 e56c5582191..f6d9a566215 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt @@ -43,7 +43,6 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.kotlin.serialization.DescriptorSerializer import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.makeNullable -import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.kotlin.utils.sure import org.jetbrains.org.objectweb.asm.Label import org.jetbrains.org.objectweb.asm.MethodVisitor @@ -104,9 +103,9 @@ abstract class AbstractCoroutineCodegen( ValueParameterDescriptorImpl( this, null, index, Annotations.EMPTY, name, type, - false, false, - false, - null, SourceElement.NO_SOURCE + declaresDefaultValue = false, isCrossinline = false, + isNoinline = false, + varargElementType = null, source = SourceElement.NO_SOURCE ) override fun generateConstructor(): Method { @@ -157,7 +156,7 @@ abstract class AbstractCoroutineCodegen( return constructor } - abstract protected val passArityToSuperClass: Boolean + protected abstract val passArityToSuperClass: Boolean } class CoroutineCodegenForLambda private constructor( @@ -187,6 +186,23 @@ class CoroutineCodegenForLambda private constructor( private val endLabel = Label() + private val varsCountByType = hashMapOf() + + private val fieldsForParameters: Map = createFieldsForParameters() + + private fun createFieldsForParameters(): Map { + val result = hashMapOf() + for (parameter in allFunctionParameters()) { + if (parameter.isUnused()) continue + val type = state.typeMapper.mapType(parameter.type) + val normalizedType = type.normalize() + val index = varsCountByType[normalizedType]?.plus(1) ?: 0 + varsCountByType[normalizedType] = index + result[parameter] = createHiddenFieldInfo(parameter.type, "${normalizedType.descriptor[0]}$$index") + } + return result + } + private fun getCreateFunction(): SimpleFunctionDescriptor = SimpleFunctionDescriptorImpl.create( funDescriptor.containingDeclaration, Annotations.EMPTY, @@ -232,8 +248,7 @@ class CoroutineCodegenForLambda private constructor( override fun generateClosureBody() { for (parameter in allFunctionParameters()) { - if (parameter.isUnused()) continue - val fieldInfo = parameter.getFieldInfoForCoroutineLambdaParameter() + val fieldInfo = fieldsForParameters[parameter] ?: continue v.newField( OtherOrigin(parameter), Opcodes.ACC_PRIVATE + Opcodes.ACC_SYNTHETIC, @@ -257,7 +272,7 @@ class CoroutineCodegenForLambda private constructor( super.generateBody() if (doNotGenerateInvokeBridge) { - v.serializationBindings.put( + v.serializationBindings.put( METHOD_FOR_FUNCTION, originalSuspendFunctionDescriptor, typeMapper.mapAsmMethod(erasedInvokeFunction) @@ -320,7 +335,7 @@ class CoroutineCodegenForLambda private constructor( newarray(AsmTypes.OBJECT_TYPE) // 0 - this // 1..22 - parameters - // 23 - first empy slot + // 23 - first empty slot val arraySlot = 23 store(arraySlot, AsmTypes.OBJECT_TYPE) for ((varIndex, type) in parameterTypes.withVariableIndices()) { @@ -405,8 +420,8 @@ class CoroutineCodegenForLambda private constructor( // Pass lambda parameters to 'invoke' call on newly constructed object var index = 1 for (parameter in allFunctionParameters()) { - val fieldInfoForCoroutineLambdaParameter = parameter.getFieldInfoForCoroutineLambdaParameter() - if (!parameter.isUnused()) { + val fieldInfoForCoroutineLambdaParameter = fieldsForParameters[parameter] + if (fieldInfoForCoroutineLambdaParameter != null) { if (isBigArity) { load(cloneIndex, fieldInfoForCoroutineLambdaParameter.ownerType) load(1, AsmTypes.OBJECT_TYPE) @@ -442,7 +457,7 @@ class CoroutineCodegenForLambda private constructor( ) } } - index += if (isBigArity || generateErasedCreate) 1 else fieldInfoForCoroutineLambdaParameter.fieldType.size + index += if (isBigArity || generateErasedCreate) 1 else state.typeMapper.mapType(parameter.type).size } load(cloneIndex, AsmTypes.OBJECT_TYPE) @@ -452,17 +467,17 @@ class CoroutineCodegenForLambda private constructor( private fun ExpressionCodegen.initializeCoroutineParameters() { for (parameter in allFunctionParameters()) { - if (parameter.isUnused()) continue - val fieldStackValue = - StackValue.field( - parameter.getFieldInfoForCoroutineLambdaParameter(), generateThisOrOuter(context.thisDescriptor, false) - ) + val fieldForParameter = fieldsForParameters[parameter] ?: continue + val fieldStackValue = StackValue.field(fieldForParameter, generateThisOrOuter(context.thisDescriptor, false)) - val mappedType = typeMapper.mapType(parameter.type) - fieldStackValue.put(mappedType, v) + val originalType = typeMapper.mapType(parameter.type) + val normalizedType = originalType.normalize() + fieldStackValue.put(normalizedType, v) - val newIndex = myFrameMap.enter(parameter, mappedType) - v.store(newIndex, mappedType) + val newIndex = myFrameMap.enter(parameter, originalType) + // FIXME: Coerce int + StackValue.coerce(normalizedType, originalType, v) + v.store(newIndex, originalType) val name = if (parameter is ReceiverParameterDescriptor) @@ -471,7 +486,7 @@ class CoroutineCodegenForLambda private constructor( (getNameForDestructuredParameterOrNull(parameter as ValueParameterDescriptor) ?: parameter.name.asString()) val label = Label() v.mark(label) - v.visitLocalVariable(name, mappedType.descriptor, null, label, endLabel, newIndex) + v.visitLocalVariable(name, originalType.descriptor, null, label, endLabel, newIndex) } initializeVariablesForDestructuredLambdaParameters( @@ -485,13 +500,10 @@ class CoroutineCodegenForLambda private constructor( originalSuspendFunctionDescriptor.extensionReceiverParameter.let(::listOfNotNull) + originalSuspendFunctionDescriptor.valueParameters - private fun ParameterDescriptor.getFieldInfoForCoroutineLambdaParameter() = - createHiddenFieldInfo(type, COROUTINE_LAMBDA_PARAMETER_PREFIX + (this.safeAs()?.index ?: "")) - private fun createHiddenFieldInfo(type: KotlinType, name: String) = FieldInfo.createForHiddenField( typeMapper.mapClass(closureContext.thisDescriptor), - typeMapper.mapType(type), + typeMapper.mapType(type).normalize(), type, name ) @@ -514,7 +526,8 @@ class CoroutineCodegenForLambda private constructor( isForNamedFunction = false, languageVersionSettings = languageVersionSettings, disableTailCallOptimizationForFunctionReturningUnit = false, - useOldSpilledVarTypeAnalysis = state.configuration.getBoolean(JVMConfigurationKeys.USE_OLD_SPILLED_VAR_TYPE_ANALYSIS) + useOldSpilledVarTypeAnalysis = state.configuration.getBoolean(JVMConfigurationKeys.USE_OLD_SPILLED_VAR_TYPE_ANALYSIS), + initialVarsCountByType = varsCountByType ) val maybeWithForInline = if (forInline) SuspendForInlineCopyingMethodVisitor(stateMachineBuilder, access, name, desc, functionCodegen::newMethod) @@ -758,16 +771,11 @@ class CoroutineCodegenForNamedFunction private constructor( declaration: KtFunction ): CoroutineCodegenForNamedFunction { val bindingContext = expressionCodegen.state.bindingContext - val closure = - bindingContext[ - CodegenBinding.CLOSURE, - bindingContext[CodegenBinding.CLASS_FOR_CALLABLE, originalSuspendDescriptor] - ].sure { "There must be a closure defined for $originalSuspendDescriptor" } + val closure = bindingContext[CLOSURE, bindingContext[CodegenBinding.CLASS_FOR_CALLABLE, originalSuspendDescriptor]] + .sure { "There must be a closure defined for $originalSuspendDescriptor" } - val suspendFunctionView = - bindingContext[ - CodegenBinding.SUSPEND_FUNCTION_TO_JVM_VIEW, originalSuspendDescriptor - ].sure { "There must be a jvm view defined for $originalSuspendDescriptor" } + val suspendFunctionView = bindingContext[CodegenBinding.SUSPEND_FUNCTION_TO_JVM_VIEW, originalSuspendDescriptor] + .sure { "There must be a jvm view defined for $originalSuspendDescriptor" } if (suspendFunctionView.dispatchReceiverParameter != null) { closure.setNeedsCaptureOuterClass() @@ -785,10 +793,8 @@ class CoroutineCodegenForNamedFunction private constructor( } } -private const val COROUTINE_LAMBDA_PARAMETER_PREFIX = "p$" - private object FailingFunctionGenerationStrategy : FunctionGenerationStrategy() { - override fun skipNotNullAssertionsForParameters(): kotlin.Boolean { + override fun skipNotNullAssertionsForParameters(): Boolean { error("This functions must not be called") } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt index 2f40b6ebd05..68fac79ff1a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineTransformerMethodVisitor.kt @@ -64,7 +64,9 @@ class CoroutineTransformerMethodVisitor( // JVM_IR backend generates $completion, while old backend does not private val putContinuationParameterToLvt: Boolean = true, // New SourceInterpreter-less analyser can be somewhat unstable, disable it - private val useOldSpilledVarTypeAnalysis: Boolean = false + private val useOldSpilledVarTypeAnalysis: Boolean = false, + // Parameters of suspend lambda are put to the same fields as spilled variables + private val initialVarsCountByType: Map = emptyMap() ) : TransformationMethodVisitor(delegate, access, name, desc, signature, exceptions) { private val classBuilderForCoroutineState: ClassBuilder by lazy(obtainClassBuilderForCoroutineState) @@ -200,7 +202,6 @@ class CoroutineTransformerMethodVisitor( // In this case the variables are uninitialized, initialize them private fun initializeFakeInlinerVariables(methodNode: MethodNode, stateLabels: List) { for (stateLabel in stateLabels) { - val unitializedFakeInlinerVariables = arrayListOf() for (record in methodNode.localVariables) { if (isFakeLocalVariableForInline(record.name) && methodNode.instructions.indexOf(record.start) < methodNode.instructions.indexOf(stateLabel) && @@ -597,6 +598,14 @@ class CoroutineTransformerMethodVisitor( fun AbstractInsnNode.index() = instructions.indexOf(this) val maxVarsCountByType = mutableMapOf() + var initialSpilledVariablesCount = 0 + for ((type, count) in initialVarsCountByType) { + if (type == AsmTypes.OBJECT_TYPE) { + initialSpilledVariablesCount = count + } + maxVarsCountByType[type] = count + } + val livenessFrames = analyzeLiveness(methodNode) // References shall be cleaned up after uspill (during spill in next suspension point) to prevent memory leaks, @@ -703,7 +712,8 @@ class CoroutineTransformerMethodVisitor( val currentSpilledReferencesCount = countVariablesToSpill(suspensionPointIndex) val preds = predSuspensionPoints[suspensionPoint] val predSpilledReferencesCount = - if (preds.isNullOrEmpty()) 0 else preds.maxOf { countVariablesToSpill(suspensionPoints.indexOf(it)) } + if (preds.isNullOrEmpty()) initialSpilledVariablesCount + else preds.maxOf { countVariablesToSpill(suspensionPoints.indexOf(it)) } referencesToCleanBySuspensionPointIndex += currentSpilledReferencesCount to predSpilledReferencesCount } @@ -779,7 +789,7 @@ class CoroutineTransformerMethodVisitor( for (entry in maxVarsCountByType) { val (type, maxIndex) = entry - for (index in 0..maxIndex) { + for (index in (initialVarsCountByType[type]?.plus(1) ?: 0)..maxIndex) { classBuilderForCoroutineState.newField( JvmDeclarationOrigin.NO_ORIGIN, AsmUtil.NO_FLAG_PACKAGE_PRIVATE, type.fieldNameForVar(index), type.descriptor, null, null @@ -835,7 +845,7 @@ class CoroutineTransformerMethodVisitor( private val SuspensionPoint.tryCatchBlockEndLabelAfterSuspensionCall: LabelNode get() { assert(suspensionCallEnd.next is LabelNode) { - "Next instruction after ${this} should be a label, but " + + "Next instruction after $this should be a label, but " + "${suspensionCallEnd.next::class.java}/${suspensionCallEnd.next.opcode} was found" } @@ -936,9 +946,11 @@ class CoroutineTransformerMethodVisitor( private fun nextDefinitelyHitLineNumber(suspension: SuspensionPoint): LineNumberNode? { var next = suspension.suspensionCallEnd.next while (next != null) { - if (next.isBranchOrCall) return null - else if (next is LineNumberNode) return next - else next = next.next + when { + next.isBranchOrCall -> return null + next is LineNumberNode -> return next + else -> next = next.next + } } return next } @@ -1072,7 +1084,7 @@ inline fun withInstructionAdapter(block: InstructionAdapter.() -> Unit): InsnLis return tmpMethodNode.instructions } -private fun Type.normalize() = +internal fun Type.normalize() = when (sort) { Type.ARRAY, Type.OBJECT -> AsmTypes.OBJECT_TYPE else -> this diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.txt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.txt index 6343dab3ede..047f67f9942 100644 --- a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.txt +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.txt @@ -2,8 +2,8 @@ @kotlin.Metadata final class LambdaWithLongReceiverKt$box$1$1 { // source: 'lambdaWithLongReceiver.kt' + private synthetic field J$0: long field label: int - private synthetic field p$: long inner (anonymous) class LambdaWithLongReceiverKt$box$1 inner (anonymous) class LambdaWithLongReceiverKt$box$1$1 method (p0: kotlin.coroutines.Continuation): void diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_1_2.txt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_1_2.txt index 665c2f23c82..49e40983cfb 100644 --- a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_1_2.txt +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_1_2.txt @@ -1,7 +1,7 @@ @kotlin.Metadata final class LambdaWithLongReceiverKt$box$1$1 { // source: 'lambdaWithLongReceiver.kt' - private synthetic field p$: long + private synthetic field J$0: long inner (anonymous) class LambdaWithLongReceiverKt$box$1 inner (anonymous) class LambdaWithLongReceiverKt$box$1$1 method (p0: kotlin.coroutines.experimental.Continuation): void diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.txt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.txt index 0b4e1f0cef0..d124170341d 100644 --- a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.txt +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.txt @@ -2,13 +2,13 @@ @kotlin.Metadata final class LambdaWithMultipleParametersKt$box$1$1 { // source: 'lambdaWithMultipleParameters.kt' + private synthetic field J$0: long + private synthetic field J$1: long + private synthetic field J$2: long + private synthetic field J$3: long + private synthetic field J$4: long + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: java.lang.String - private synthetic field p$1: long - private synthetic field p$2: long - private synthetic field p$3: long - private synthetic field p$4: long - private synthetic field p$5: long inner (anonymous) class LambdaWithMultipleParametersKt$box$1 inner (anonymous) class LambdaWithMultipleParametersKt$box$1$1 method (p0: kotlin.coroutines.Continuation): void diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters_1_2.txt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters_1_2.txt index 752d8d79d2f..d4d3ac1ea04 100644 --- a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters_1_2.txt +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters_1_2.txt @@ -1,12 +1,12 @@ @kotlin.Metadata final class LambdaWithMultipleParametersKt$box$1$1 { // source: 'lambdaWithMultipleParameters.kt' - private synthetic field p$0: java.lang.String - private synthetic field p$1: long - private synthetic field p$2: long - private synthetic field p$3: long - private synthetic field p$4: long - private synthetic field p$5: long + private synthetic field J$0: long + private synthetic field J$1: long + private synthetic field J$2: long + private synthetic field J$3: long + private synthetic field J$4: long + private synthetic field L$0: java.lang.Object inner (anonymous) class LambdaWithMultipleParametersKt$box$1 inner (anonymous) class LambdaWithMultipleParametersKt$box$1$1 method (p0: kotlin.coroutines.experimental.Continuation): void diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields.txt b/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields.txt index 80ad24d8ab6..dd061f55725 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields.txt @@ -42,9 +42,8 @@ final class CoroutineFieldsKt$box$1 { // source: 'coroutineFields.kt' synthetic final field $result: kotlin.jvm.internal.Ref$ObjectRef field J$0: long - field L$0: java.lang.Object + private synthetic field L$0: java.lang.Object field L$1: java.lang.Object - private synthetic field p$: Controller inner (anonymous) class CoroutineFieldsKt$box$1 method (p0: kotlin.jvm.internal.Ref$ObjectRef, p1: COROUTINES_PACKAGE.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: COROUTINES_PACKAGE.Continuation): COROUTINES_PACKAGE.Continuation diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields_1_3.txt b/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields_1_3.txt index 268f2893334..8bf3bce0f4e 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields_1_3.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/coroutineFields_1_3.txt @@ -41,10 +41,9 @@ final class CoroutineFieldsKt$box$1 { // source: 'coroutineFields.kt' synthetic final field $result: kotlin.jvm.internal.Ref$ObjectRef field J$0: long - field L$0: java.lang.Object + private synthetic field L$0: java.lang.Object field L$1: java.lang.Object field label: int - private synthetic field p$: Controller inner (anonymous) class CoroutineFieldsKt$box$1 method (p0: kotlin.jvm.internal.Ref$ObjectRef, p1: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/component1.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/component1.txt index ef6e107d741..2715137ca3d 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/component1.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/component1.txt @@ -2,8 +2,8 @@ @kotlin.Metadata final class Component1Kt$test$1 { // source: 'component1.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$: Foo inner (anonymous) class Component1Kt$test$1 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/component1_ir.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/component1_ir.txt new file mode 100644 index 00000000000..ef6e107d741 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/component1_ir.txt @@ -0,0 +1,40 @@ +@kotlin.coroutines.jvm.internal.DebugMetadata +@kotlin.Metadata +final class Component1Kt$test$1 { + // source: 'component1.kt' + field label: int + private synthetic field p$: Foo + inner (anonymous) class Component1Kt$test$1 + method (p0: kotlin.coroutines.Continuation): void + public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation + public final method invoke(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public final @org.jetbrains.annotations.Nullable method invokeSuspend(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object +} + +@kotlin.Metadata +public final class Component1Kt { + // source: 'component1.kt' + inner (anonymous) class Component1Kt$test$1 + public final static @org.jetbrains.annotations.NotNull method generate(): Result + public final static method test(): void + public final static method use(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2): void +} + +@kotlin.Metadata +public final class Foo$DefaultImpls { + // source: 'component1.kt' + public static @org.jetbrains.annotations.Nullable method component1(@org.jetbrains.annotations.NotNull p0: Foo, @org.jetbrains.annotations.NotNull p1: Result, @org.jetbrains.annotations.NotNull p2: kotlin.coroutines.Continuation): java.lang.Object + public final inner class Foo$DefaultImpls +} + +@kotlin.Metadata +public interface Foo { + // source: 'component1.kt' + public abstract @org.jetbrains.annotations.Nullable method component1(@org.jetbrains.annotations.NotNull p0: Result, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object + public final inner class Foo$DefaultImpls +} + +@kotlin.Metadata +public interface Result { + // source: 'component1.kt' +} diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/destructured.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/destructured.txt index e52982ed518..8103a33cb60 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/destructured.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/destructured.txt @@ -14,8 +14,8 @@ final class DestructuredKt$test$1 { @kotlin.Metadata final class DestructuredKt$test$2 { // source: 'destructured.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: kotlin.Pair inner (anonymous) class DestructuredKt$test$2 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -27,8 +27,8 @@ final class DestructuredKt$test$2 { @kotlin.Metadata final class DestructuredKt$test$3 { // source: 'destructured.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: kotlin.Pair inner (anonymous) class DestructuredKt$test$3 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -40,8 +40,8 @@ final class DestructuredKt$test$3 { @kotlin.Metadata final class DestructuredKt$test$4 { // source: 'destructured.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: kotlin.Pair inner (anonymous) class DestructuredKt$test$4 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/field.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/field.txt index a7d130e60af..2008fc2b17a 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/field.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/field.txt @@ -2,8 +2,8 @@ @kotlin.Metadata final class FieldKt$test$1 { // source: 'field.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$: Foo inner (anonymous) class FieldKt$test$1 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/field_ir.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/field_ir.txt new file mode 100644 index 00000000000..a7d130e60af --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/field_ir.txt @@ -0,0 +1,40 @@ +@kotlin.coroutines.jvm.internal.DebugMetadata +@kotlin.Metadata +final class FieldKt$test$1 { + // source: 'field.kt' + field label: int + private synthetic field p$: Foo + inner (anonymous) class FieldKt$test$1 + method (p0: kotlin.coroutines.Continuation): void + public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation + public final method invoke(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public final @org.jetbrains.annotations.Nullable method invokeSuspend(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object +} + +@kotlin.Metadata +public final class FieldKt { + // source: 'field.kt' + inner (anonymous) class FieldKt$test$1 + public final static @org.jetbrains.annotations.NotNull method generate(): Result + public final static method test(): void + public final static method use(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2): void +} + +@kotlin.Metadata +public final class Foo$DefaultImpls { + // source: 'field.kt' + public static @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: Foo, @org.jetbrains.annotations.NotNull p1: Result): java.lang.Object + public final inner class Foo$DefaultImpls +} + +@kotlin.Metadata +public interface Foo { + // source: 'field.kt' + public abstract @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.NotNull p0: Result): java.lang.Object + public final inner class Foo$DefaultImpls +} + +@kotlin.Metadata +public interface Result { + // source: 'field.kt' +} diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/lambda.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/lambda.txt index e11fcd6ff2d..2365e36c627 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/lambda.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/lambda.txt @@ -2,9 +2,9 @@ @kotlin.Metadata final class LambdaKt$test$1 { // source: 'lambda.kt' + private synthetic field D$0: double + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: double - private synthetic field p$1: java.lang.String inner (anonymous) class LambdaKt$test$1 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -16,9 +16,9 @@ final class LambdaKt$test$1 { @kotlin.Metadata final class LambdaKt$test$10 { // source: 'lambda.kt' + private synthetic field J$0: long + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$1: java.lang.String - private synthetic field p$: long inner (anonymous) class LambdaKt$test$10 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -30,8 +30,8 @@ final class LambdaKt$test$10 { @kotlin.Metadata final class LambdaKt$test$11 { // source: 'lambda.kt' + private synthetic field J$0: long field label: int - private synthetic field p$: long inner (anonymous) class LambdaKt$test$11 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -55,9 +55,9 @@ final class LambdaKt$test$12 { @kotlin.Metadata final class LambdaKt$test$13 { // source: 'lambda.kt' + private synthetic field J$0: long + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: java.lang.String - private synthetic field p$: long inner (anonymous) class LambdaKt$test$13 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, @org.jetbrains.annotations.NotNull p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -69,8 +69,8 @@ final class LambdaKt$test$13 { @kotlin.Metadata final class LambdaKt$test$14 { // source: 'lambda.kt' + private synthetic field J$0: long field label: int - private synthetic field p$: long inner (anonymous) class LambdaKt$test$14 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, @org.jetbrains.annotations.NotNull p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -82,8 +82,8 @@ final class LambdaKt$test$14 { @kotlin.Metadata final class LambdaKt$test$15 { // source: 'lambda.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: java.lang.String inner (anonymous) class LambdaKt$test$15 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, @org.jetbrains.annotations.NotNull p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -107,8 +107,8 @@ final class LambdaKt$test$16 { @kotlin.Metadata final class LambdaKt$test$17 { // source: 'lambda.kt' + private synthetic field J$0: long field label: int - private synthetic field p$: long inner (anonymous) class LambdaKt$test$17 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, @org.jetbrains.annotations.NotNull p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -120,8 +120,8 @@ final class LambdaKt$test$17 { @kotlin.Metadata final class LambdaKt$test$2 { // source: 'lambda.kt' + private synthetic field D$0: double field label: int - private synthetic field p$0: double inner (anonymous) class LambdaKt$test$2 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -133,8 +133,8 @@ final class LambdaKt$test$2 { @kotlin.Metadata final class LambdaKt$test$3 { // source: 'lambda.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$1: java.lang.String inner (anonymous) class LambdaKt$test$3 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -146,8 +146,8 @@ final class LambdaKt$test$3 { @kotlin.Metadata final class LambdaKt$test$4 { // source: 'lambda.kt' + private synthetic field D$0: double field label: int - private synthetic field p$0: double inner (anonymous) class LambdaKt$test$4 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -159,8 +159,8 @@ final class LambdaKt$test$4 { @kotlin.Metadata final class LambdaKt$test$5 { // source: 'lambda.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$1: java.lang.String inner (anonymous) class LambdaKt$test$5 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -172,10 +172,10 @@ final class LambdaKt$test$5 { @kotlin.Metadata final class LambdaKt$test$6 { // source: 'lambda.kt' + private synthetic field D$0: double + private synthetic field J$0: long + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: double - private synthetic field p$1: java.lang.String - private synthetic field p$: long inner (anonymous) class LambdaKt$test$6 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -187,9 +187,9 @@ final class LambdaKt$test$6 { @kotlin.Metadata final class LambdaKt$test$7 { // source: 'lambda.kt' + private synthetic field D$0: double + private synthetic field J$0: long field label: int - private synthetic field p$0: double - private synthetic field p$: long inner (anonymous) class LambdaKt$test$7 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -201,9 +201,9 @@ final class LambdaKt$test$7 { @kotlin.Metadata final class LambdaKt$test$8 { // source: 'lambda.kt' + private synthetic field J$0: long + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$1: java.lang.String - private synthetic field p$: long inner (anonymous) class LambdaKt$test$8 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation @@ -215,9 +215,9 @@ final class LambdaKt$test$8 { @kotlin.Metadata final class LambdaKt$test$9 { // source: 'lambda.kt' + private synthetic field D$0: double + private synthetic field J$0: long field label: int - private synthetic field p$0: double - private synthetic field p$: long inner (anonymous) class LambdaKt$test$9 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(p0: long, p1: double, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/select.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/select.txt index b2deb6d95da..9ba1a10eac9 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/select.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/select.txt @@ -41,8 +41,8 @@ final class SelectKt$produceNumbers$1$1$1 { @kotlin.Metadata final class SelectKt$produceNumbers$1 { // source: 'select.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$: ProducerScope inner (anonymous) class SelectKt$produceNumbers$1 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation diff --git a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/unreachable.txt b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/unreachable.txt index 9e58ad085dd..4a30f486dce 100644 --- a/compiler/testData/codegen/bytecodeListing/coroutines/spilling/unreachable.txt +++ b/compiler/testData/codegen/bytecodeListing/coroutines/spilling/unreachable.txt @@ -2,8 +2,8 @@ @kotlin.Metadata final class UnreachableKt$test$1 { // source: 'unreachable.kt' + private synthetic field L$0: java.lang.Object field label: int - private synthetic field p$0: java.lang.String inner (anonymous) class UnreachableKt$test$1 method (p0: kotlin.coroutines.Continuation): void public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation