JVM_IR: resolve inline fake overrides before codegen
See KT-33054 and KT-29242.
This commit is contained in:
@@ -298,6 +298,7 @@ private val jvmFilePhases =
|
||||
additionalClassAnnotationPhase then
|
||||
typeOperatorLowering then
|
||||
replaceKFunctionInvokeWithFunctionInvokePhase then
|
||||
resolveInlineCallsPhase then
|
||||
|
||||
checkLocalNamesWithOldBackendPhase then
|
||||
|
||||
|
||||
+2
-5
@@ -965,9 +965,8 @@ class ExpressionCodegen(
|
||||
}
|
||||
}
|
||||
|
||||
val original = (callee as? IrSimpleFunction)?.resolveFakeOverride() ?: irFunction
|
||||
val methodOwner = callee.parent.safeAs<IrClass>()?.let(typeMapper::mapClass) ?: MethodSignatureMapper.FAKE_OWNER_TYPE
|
||||
val sourceCompiler = IrSourceCompilerForInline(state, element, original, this, data)
|
||||
val sourceCompiler = IrSourceCompilerForInline(state, element, callee, this, data)
|
||||
|
||||
val reifiedTypeInliner = ReifiedTypeInliner(mappings, object : ReifiedTypeInliner.IntrinsicsSupport<IrType> {
|
||||
override fun putClassInstance(v: InstructionAdapter, type: IrType) {
|
||||
@@ -977,9 +976,7 @@ class ExpressionCodegen(
|
||||
override fun toKotlinType(type: IrType): KotlinType = type.toKotlinType()
|
||||
}, IrTypeCheckerContext(context.irBuiltIns), state.languageVersionSettings)
|
||||
|
||||
return IrInlineCodegen(
|
||||
this, state, original.descriptor, methodOwner, signature, mappings, sourceCompiler, reifiedTypeInliner
|
||||
)
|
||||
return IrInlineCodegen(this, state, callee.descriptor, methodOwner, signature, mappings, sourceCompiler, reifiedTypeInliner)
|
||||
}
|
||||
|
||||
override fun consumeReifiedOperationMarker(typeParameter: TypeParameterMarker) {
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isInlineFunctionCall
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.util.copyTypeAndValueArgumentsFrom
|
||||
import org.jetbrains.kotlin.ir.util.resolveFakeOverride
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
|
||||
internal val resolveInlineCallsPhase = makeIrFilePhase(
|
||||
::ResolveInlineCalls,
|
||||
name = "ResolveInlineCalls",
|
||||
description = "Statically resolve calls to inline methods to particular implementations"
|
||||
)
|
||||
|
||||
class ResolveInlineCalls(val context: JvmBackendContext) : IrElementTransformerVoid(), FileLoweringPass {
|
||||
override fun lower(irFile: IrFile) = irFile.transformChildrenVoid()
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
if (!expression.symbol.owner.isInlineFunctionCall(context))
|
||||
return super.visitCall(expression)
|
||||
val maybeFakeOverride = expression.symbol.owner as? IrSimpleFunction
|
||||
?: return super.visitCall(expression)
|
||||
val resolved = maybeFakeOverride.resolveFakeOverride()
|
||||
?: return super.visitCall(expression)
|
||||
return super.visitCall(with(expression) {
|
||||
IrCallImpl(startOffset, endOffset, type, resolved.symbol, superQualifierSymbol).apply {
|
||||
copyTypeAndValueArgumentsFrom(expression)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user