JVM_IR: resolve inline fake overrides before codegen

See KT-33054 and KT-29242.
This commit is contained in:
pyos
2019-11-11 16:24:25 +01:00
committed by max-kammerer
parent 1b2091d536
commit 29a14e2330
8 changed files with 119 additions and 5 deletions
@@ -298,6 +298,7 @@ private val jvmFilePhases =
additionalClassAnnotationPhase then
typeOperatorLowering then
replaceKFunctionInvokeWithFunctionInvokePhase then
resolveInlineCallsPhase then
checkLocalNamesWithOldBackendPhase then
@@ -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) {
@@ -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)
}
})
}
}