JVM_IR: remove ExpressionCodegen.inlinedInto

This commit is contained in:
pyos
2022-05-24 13:50:45 +02:00
committed by Alexander Udalov
parent 27c51f5f88
commit 87dc1f7fde
3 changed files with 13 additions and 21 deletions
@@ -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<PromisedValue, BlockInfo>, 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<IrTypeParameterSymbol>()?.owner?.isReified == true
@@ -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()
}
@@ -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)