JVM_IR: skip SAM lambdas when computing enclosing method of objects
This is what Java 15+ does, and it permits accessing captured type parameters via reflection. The alternative is to emit generic signatures on the lambda methods, but that was disabled and I have no clue why. ^KT-52417 Fixed
This commit is contained in:
+7
-1
@@ -148,6 +148,12 @@ class ExpressionCodegen(
|
||||
|
||||
var finallyDepth = 0
|
||||
|
||||
val inlineRoot: ExpressionCodegen
|
||||
get() = inlinedInto ?: this
|
||||
|
||||
val enclosingFunctionForLocalObjects: IrFunction
|
||||
get() = generateSequence(inlineRoot.irFunction) { context.enclosingMethodOverride[it] }.last()
|
||||
|
||||
val context = classCodegen.context
|
||||
val typeMapper = context.typeMapper
|
||||
val methodSignatureMapper = context.methodSignatureMapper
|
||||
@@ -862,7 +868,7 @@ class ExpressionCodegen(
|
||||
|
||||
override fun visitClass(declaration: IrClass, data: BlockInfo): PromisedValue {
|
||||
if (declaration.origin != JvmLoweredDeclarationOrigin.CONTINUATION_CLASS) {
|
||||
val childCodegen = ClassCodegen.getOrCreate(declaration, context, generateSequence(this) { it.inlinedInto }.last().irFunction)
|
||||
val childCodegen = ClassCodegen.getOrCreate(declaration, context, enclosingFunctionForLocalObjects)
|
||||
childCodegen.generate()
|
||||
closureReifiedMarkers[declaration] = childCodegen.reifiedTypeParametersUsages
|
||||
}
|
||||
|
||||
+9
-5
@@ -42,12 +42,16 @@ class IrSourceCompilerForInline(
|
||||
|
||||
override val inlineCallSiteInfo: InlineCallSiteInfo
|
||||
get() {
|
||||
val root = generateSequence(codegen) { it.inlinedInto }.last()
|
||||
val root = codegen.inlineRoot
|
||||
val rootFunction = root.enclosingFunctionForLocalObjects
|
||||
return InlineCallSiteInfo(
|
||||
root.classCodegen.type.internalName,
|
||||
root.signature.asmMethod,
|
||||
root.irFunction.inlineScopeVisibility,
|
||||
root.irFunction.fileParent.getIoFile(),
|
||||
if (rootFunction === root.irFunction)
|
||||
root.signature.asmMethod
|
||||
else
|
||||
codegen.methodSignatureMapper.mapAsmMethod(rootFunction),
|
||||
rootFunction.inlineScopeVisibility,
|
||||
rootFunction.fileParent.getIoFile(),
|
||||
callElement.psiElement?.let { CodegenUtil.getLineNumberForElement(it, false) } ?: 0
|
||||
)
|
||||
}
|
||||
@@ -62,7 +66,7 @@ class IrSourceCompilerForInline(
|
||||
reifiedTypeParameters.addUsedReifiedParameter(typeParameter.name.asString())
|
||||
}
|
||||
}
|
||||
return FunctionCodegen(lambdaInfo.function, codegen.classCodegen).generate(codegen, reifiedTypeParameters)
|
||||
return FunctionCodegen(lambdaInfo.function, codegen.classCodegen).generate(codegen.inlineRoot, reifiedTypeParameters)
|
||||
}
|
||||
|
||||
override fun compileInlineFunction(jvmSignature: JvmMethodSignature): SMAPAndMethodNode {
|
||||
|
||||
Reference in New Issue
Block a user