JVM IR: Remove FAKE_OWNER from MethodSignatureMapper
FAKE_OWNER is a hack for when we encounter IrFunctions with non-class parents during codegen. This can only happen for unhandled intrinsic functions and resolving them to FAKE_OWNER can cause codegen to succeed while producing broken bytecode.
This commit is contained in:
committed by
Alexander Udalov
parent
5ffbf9264a
commit
5309e774ac
+3
-2
@@ -367,8 +367,9 @@ class ExpressionCodegen(
|
|||||||
classCodegen.context.irIntrinsics.getIntrinsic(expression.symbol)
|
classCodegen.context.irIntrinsics.getIntrinsic(expression.symbol)
|
||||||
?.invoke(expression, this, data)?.let { return it }
|
?.invoke(expression, this, data)?.let { return it }
|
||||||
|
|
||||||
val callable = methodSignatureMapper.mapToCallableMethod(irFunction, expression)
|
|
||||||
val callee = expression.symbol.owner
|
val callee = expression.symbol.owner
|
||||||
|
require(callee.parent is IrClass) { "Unhandled intrinsic in ExpressionCodegen: ${callee.render()}" }
|
||||||
|
val callable = methodSignatureMapper.mapToCallableMethod(irFunction, expression)
|
||||||
val callGenerator = getOrCreateCallGenerator(expression, data, callable.signature)
|
val callGenerator = getOrCreateCallGenerator(expression, data, callable.signature)
|
||||||
val asmType = if (expression is IrConstructorCall) typeMapper.mapTypeAsDeclaration(expression.type) else expression.asmType
|
val asmType = if (expression is IrConstructorCall) typeMapper.mapTypeAsDeclaration(expression.type) else expression.asmType
|
||||||
|
|
||||||
@@ -1022,7 +1023,7 @@ class ExpressionCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val methodOwner = callee.parent.safeAs<IrClass>()?.let(typeMapper::mapClass) ?: MethodSignatureMapper.FAKE_OWNER_TYPE
|
val methodOwner = typeMapper.mapClass(callee.parentAsClass)
|
||||||
val sourceCompiler = IrSourceCompilerForInline(state, element, callee, this, data)
|
val sourceCompiler = IrSourceCompilerForInline(state, element, callee, this, data)
|
||||||
|
|
||||||
val reifiedTypeInliner = ReifiedTypeInliner(mappings, object : ReifiedTypeInliner.IntrinsicsSupport<IrType> {
|
val reifiedTypeInliner = ReifiedTypeInliner(mappings, object : ReifiedTypeInliner.IntrinsicsSupport<IrType> {
|
||||||
|
|||||||
+1
-13
@@ -285,15 +285,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
|
|||||||
|
|
||||||
fun mapToCallableMethod(caller: IrFunction, expression: IrFunctionAccessExpression): IrCallableMethod {
|
fun mapToCallableMethod(caller: IrFunction, expression: IrFunctionAccessExpression): IrCallableMethod {
|
||||||
val callee = expression.symbol.owner.getOrCreateSuspendFunctionViewIfNeeded(context)
|
val callee = expression.symbol.owner.getOrCreateSuspendFunctionViewIfNeeded(context)
|
||||||
val calleeParent = callee.parent
|
val calleeParent = callee.parentAsClass
|
||||||
if (calleeParent !is IrClass) {
|
|
||||||
// Non-class parent is only possible for intrinsics created in IrBuiltIns, such as dataClassArrayMemberHashCode. In that case,
|
|
||||||
// we still need to return some IrCallableMethod with some owner instance, but that owner will be ignored at the call site.
|
|
||||||
// Here we return a fake type, but this needs to be refactored so that we never call mapToCallableMethod on intrinsics.
|
|
||||||
// TODO: get rid of fake owner here
|
|
||||||
return IrCallableMethod(FAKE_OWNER_TYPE, Opcodes.INVOKESTATIC, mapSignatureSkipGeneric(callee), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
val owner = typeMapper.mapClass(calleeParent)
|
val owner = typeMapper.mapClass(calleeParent)
|
||||||
|
|
||||||
if (callee !is IrSimpleFunction) {
|
if (callee !is IrSimpleFunction) {
|
||||||
@@ -351,8 +343,4 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
|
|||||||
}
|
}
|
||||||
return current
|
return current
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
val FAKE_OWNER_TYPE = Type.getObjectType("kotlin/internal/ir/Intrinsic")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user