From 87dc1f7fde872d7cca52434f098efe20438d073f Mon Sep 17 00:00:00 2001 From: pyos Date: Tue, 24 May 2022 13:50:45 +0200 Subject: [PATCH] JVM_IR: remove ExpressionCodegen.inlinedInto --- .../kotlin/backend/jvm/codegen/ExpressionCodegen.kt | 12 ++++-------- .../kotlin/backend/jvm/codegen/FunctionCodegen.kt | 9 +++------ .../jvm/codegen/IrSourceCompilerForInline.kt | 13 ++++++------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index f7270e87ad1..19f095768bc 100644 --- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -139,7 +139,6 @@ class ExpressionCodegen( override val frameMap: IrFrameMap, val mv: InstructionAdapter, val classCodegen: ClassCodegen, - val inlinedInto: ExpressionCodegen?, val smap: SourceMapper, val reifiedTypeParametersUsages: ReifiedTypeParametersUsages, ) : IrElementVisitor, BaseExpressionCodegen { @@ -148,11 +147,8 @@ class ExpressionCodegen( var finallyDepth = 0 - val inlineRoot: ExpressionCodegen - get() = inlinedInto ?: this - val enclosingFunctionForLocalObjects: IrFunction - get() = generateSequence(inlineRoot.irFunction) { context.enclosingMethodOverride[it] }.last() + get() = generateSequence(irFunction) { context.enclosingMethodOverride[it] }.last() val context = classCodegen.context val typeMapper = context.typeMapper @@ -292,9 +288,9 @@ class ExpressionCodegen( if (state.isParamAssertionsDisabled) return - if (inlinedInto != null || - (DescriptorVisibilities.isPrivate(irFunction.visibility) && !shouldGenerateNonNullAssertionsForPrivateFun(irFunction)) || + if ((DescriptorVisibilities.isPrivate(irFunction.visibility) && !shouldGenerateNonNullAssertionsForPrivateFun(irFunction)) || irFunction.origin.isSynthetic || + irFunction.origin == JvmLoweredDeclarationOrigin.INLINE_LAMBDA || // TODO: refine this condition to not generate nullability assertions on parameters // corresponding to captured variables and anonymous object super constructor arguments (irFunction is IrConstructor && irFunction.parentAsClass.isAnonymousObject) || @@ -1526,7 +1522,7 @@ class ExpressionCodegen( } val isFinallyMarkerRequired: Boolean - get() = irFunction.isInline || inlinedInto != null + get() = irFunction.isInline || irFunction.origin == JvmLoweredDeclarationOrigin.INLINE_LAMBDA val IrType.isReifiedTypeParameter: Boolean get() = this.classifierOrNull?.safeAs()?.owner?.isReified == true diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 6c7c972a646..3d71e542ff6 100644 --- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -39,16 +39,15 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg private val context = classCodegen.context fun generate( - inlinedInto: ExpressionCodegen? = null, reifiedTypeParameters: ReifiedTypeParametersUsages = classCodegen.reifiedTypeParametersUsages ): SMAPAndMethodNode = try { - doGenerate(inlinedInto, reifiedTypeParameters) + doGenerate(reifiedTypeParameters) } catch (e: Throwable) { throw RuntimeException("Exception while generating code for:\n${irFunction.dump()}", e) } - private fun doGenerate(inlinedInto: ExpressionCodegen?, reifiedTypeParameters: ReifiedTypeParametersUsages): SMAPAndMethodNode { + private fun doGenerate(reifiedTypeParameters: ReifiedTypeParametersUsages): SMAPAndMethodNode { val signature = context.methodSignatureMapper.mapSignatureWithGeneric(irFunction) val flags = irFunction.calculateMethodFlags() val isSynthetic = flags.and(Opcodes.ACC_SYNTHETIC) != 0 @@ -116,9 +115,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg context.state.globalInlineContext.enterDeclaration(irFunction.suspendFunctionOriginal().toIrBasedDescriptor()) try { val adapter = InstructionAdapter(methodVisitor) - ExpressionCodegen( - irFunction, signature, frameMap, adapter, classCodegen, inlinedInto, sourceMapper, reifiedTypeParameters - ).generate() + ExpressionCodegen(irFunction, signature, frameMap, adapter, classCodegen, sourceMapper, reifiedTypeParameters).generate() } finally { context.state.globalInlineContext.exitDeclaration() } diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt index 09034c817d3..e61663e7531 100644 --- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt +++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt @@ -42,12 +42,11 @@ class IrSourceCompilerForInline( override val inlineCallSiteInfo: InlineCallSiteInfo get() { - val root = codegen.inlineRoot - val rootFunction = root.enclosingFunctionForLocalObjects + val rootFunction = codegen.enclosingFunctionForLocalObjects return InlineCallSiteInfo( - root.classCodegen.type.internalName, - if (rootFunction === root.irFunction) - root.signature.asmMethod + codegen.classCodegen.type.internalName, + if (rootFunction === codegen.irFunction) + codegen.signature.asmMethod else codegen.methodSignatureMapper.mapAsmMethod(rootFunction), rootFunction.inlineScopeVisibility, @@ -66,7 +65,7 @@ class IrSourceCompilerForInline( reifiedTypeParameters.addUsedReifiedParameter(typeParameter.name.asString()) } } - return FunctionCodegen(lambdaInfo.function, codegen.classCodegen).generate(codegen.inlineRoot, reifiedTypeParameters) + return FunctionCodegen(lambdaInfo.function, codegen.classCodegen).generate(reifiedTypeParameters) } override fun compileInlineFunction(jvmSignature: JvmMethodSignature): SMAPAndMethodNode { @@ -100,7 +99,7 @@ class IrSourceCompilerForInline( override fun generateFinallyBlocks(finallyNode: MethodNode, curFinallyDepth: Int, returnType: Type, afterReturnLabel: Label, target: Label?) { ExpressionCodegen( codegen.irFunction, codegen.signature, codegen.frameMap, InstructionAdapter(finallyNode), codegen.classCodegen, - codegen.inlinedInto, codegen.smap, codegen.reifiedTypeParametersUsages + codegen.smap, codegen.reifiedTypeParametersUsages ).also { it.finallyDepth = curFinallyDepth }.generateFinallyBlocksIfNeeded(returnType, afterReturnLabel, data, target)