JVM_IR: fold inline lambdas when computing OUTERCLASS
so that the enclosing method of objects defined inside lambdas is the one they are declared in. Note that this does not fix *all* enclosingInfo tests because JVM_IR currently follows the KT-28064 proposal, i.e. does not regenerate objects defined inside lambdas under any circumstances. For example, this causes test boxInline/enclosingInfo/inlineChain2.kt to fail because the enclosing method of objects is _2Kt.box instead of (non-existent in source code) `_2Kt$box$inlined$call$1.invoke` or whatever. What's more important is that OUTERCLASS no longer points to a non-existent `box$lambda-N` and therefore `.enclosingMethod` no longer throws.
This commit is contained in:
+6
-8
@@ -52,6 +52,7 @@ open class ClassCodegen protected constructor(
|
||||
internal val irClass: IrClass,
|
||||
val context: JvmBackendContext,
|
||||
private val parentClassCodegen: ClassCodegen? = null,
|
||||
private val parentFunction: IrFunction? = null,
|
||||
private val withinInline: Boolean = false
|
||||
) : InnerClassConsumer {
|
||||
private val innerClasses = mutableListOf<IrClass>()
|
||||
@@ -303,8 +304,8 @@ open class ClassCodegen protected constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun generateLocalClass(klass: IrClass, withinInline: Boolean): ReifiedTypeParametersUsages {
|
||||
return ClassCodegen(klass, context, this, withinInline = withinInline || this.withinInline).generate()
|
||||
fun generateLocalClass(klass: IrClass, parentFunction: IrFunction): ReifiedTypeParametersUsages {
|
||||
return ClassCodegen(klass, context, this, parentFunction, withinInline = withinInline || parentFunction.isInline).generate()
|
||||
}
|
||||
|
||||
private fun generateField(field: IrField) {
|
||||
@@ -404,12 +405,9 @@ open class ClassCodegen protected constructor(
|
||||
// or constructor, the name and type of the function is recorded as well.
|
||||
if (parentClassCodegen != null) {
|
||||
val outerClassName = parentClassCodegen.type.internalName
|
||||
// TODO: Since the class could have been reparented in lowerings, this could
|
||||
// be a class instead of the actual function that the class is nested inside
|
||||
// in the source.
|
||||
val containingDeclaration = irClass.symbol.owner.parent
|
||||
if (containingDeclaration is IrFunction) {
|
||||
val method = methodSignatureMapper.mapAsmMethod(containingDeclaration)
|
||||
// TODO: LocalDeclarationsLowering could have moved this class out of its enclosing method.
|
||||
if (parentFunction != null) {
|
||||
val method = methodSignatureMapper.mapAsmMethod(parentFunction)
|
||||
visitor.visitOuterClass(outerClassName, method.name, method.descriptor)
|
||||
} else if (irClass.isAnonymousObject) {
|
||||
visitor.visitOuterClass(outerClassName, null, null)
|
||||
|
||||
+1
-1
@@ -556,7 +556,7 @@ class ExpressionCodegen(
|
||||
)
|
||||
|
||||
override fun visitClass(declaration: IrClass, data: BlockInfo): PromisedValue {
|
||||
classCodegen.generateLocalClass(declaration, generateSequence(this) { it.inlinedInto }.any { it.irFunction.isInline }).also {
|
||||
classCodegen.generateLocalClass(declaration, generateSequence(this) { it.inlinedInto }.last().irFunction).also {
|
||||
closureReifiedMarkers[declaration] = it
|
||||
}
|
||||
return immaterialUnitValue
|
||||
|
||||
+4
-4
@@ -58,11 +58,11 @@ class IrSourceCompilerForInline(
|
||||
|
||||
override val inlineCallSiteInfo: InlineCallSiteInfo
|
||||
get() {
|
||||
//TODO: support nested inline calls
|
||||
val root = generateSequence(codegen) { it.inlinedInto }.last()
|
||||
return InlineCallSiteInfo(
|
||||
codegen.classCodegen.type.internalName,
|
||||
codegen.signature.asmMethod.name,
|
||||
codegen.signature.asmMethod.descriptor,
|
||||
root.classCodegen.type.internalName,
|
||||
root.signature.asmMethod.name,
|
||||
root.signature.asmMethod.descriptor,
|
||||
//compilationContextFunctionDescriptor.isInlineOrInsideInline()
|
||||
false,
|
||||
compilationContextFunctionDescriptor.isSuspend
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
// WITH_REFLECT
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
// WITH_REFLECT
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
// WITH_REFLECT
|
||||
|
||||
Reference in New Issue
Block a user