JVM_IR. Combine all inline function resolve logic in ResolveInlineCalls lower
This commit is contained in:
@@ -286,7 +286,6 @@ private val jvmFilePhases =
|
|||||||
additionalClassAnnotationPhase then
|
additionalClassAnnotationPhase then
|
||||||
typeOperatorLowering then
|
typeOperatorLowering then
|
||||||
replaceKFunctionInvokeWithFunctionInvokePhase then
|
replaceKFunctionInvokeWithFunctionInvokePhase then
|
||||||
resolveInlineCallsPhase then
|
|
||||||
|
|
||||||
checkLocalNamesWithOldBackendPhase then
|
checkLocalNamesWithOldBackendPhase then
|
||||||
|
|
||||||
@@ -302,6 +301,7 @@ val jvmPhases = namedIrModulePhase(
|
|||||||
fileClassPhase then
|
fileClassPhase then
|
||||||
performByIrFile(lower = jvmFilePhases) then
|
performByIrFile(lower = jvmFilePhases) then
|
||||||
generateMultifileFacadesPhase then
|
generateMultifileFacadesPhase then
|
||||||
|
resolveInlineCallsPhase then
|
||||||
// should be last transformation
|
// should be last transformation
|
||||||
removeDeclarationsThatWouldBeInlined then
|
removeDeclarationsThatWouldBeInlined then
|
||||||
validateIrAfterLowering
|
validateIrAfterLowering
|
||||||
|
|||||||
+1
-9
@@ -948,14 +948,6 @@ class ExpressionCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrFunction.resolveMultiFileFacades(): IrFunction {
|
|
||||||
//TODO: move to ResolveInlineCalls lower (now it's goes before generateMultifileFacadesPhase)
|
|
||||||
return if (origin == JvmLoweredDeclarationOrigin.MULTIFILE_BRIDGE) {
|
|
||||||
context.multifileFacadeMemberToPartMember[this]?.let { return it }
|
|
||||||
error("Function from a multi-file facade without the link to the function in the part: ${this.render()}")
|
|
||||||
} else this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getOrCreateCallGenerator(
|
private fun getOrCreateCallGenerator(
|
||||||
element: IrFunctionAccessExpression, data: BlockInfo, signature: JvmMethodSignature
|
element: IrFunctionAccessExpression, data: BlockInfo, signature: JvmMethodSignature
|
||||||
): IrCallGenerator {
|
): IrCallGenerator {
|
||||||
@@ -965,7 +957,7 @@ class ExpressionCodegen(
|
|||||||
return IrCallGenerator.DefaultCallGenerator
|
return IrCallGenerator.DefaultCallGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
val callee = element.symbol.owner.resolveMultiFileFacades()
|
val callee = element.symbol.owner
|
||||||
val typeArgumentContainer = if (callee is IrConstructor) callee.parentAsClass else callee
|
val typeArgumentContainer = if (callee is IrConstructor) callee.parentAsClass else callee
|
||||||
val typeArguments =
|
val typeArguments =
|
||||||
if (element.typeArgumentsCount == 0) {
|
if (element.typeArgumentsCount == 0) {
|
||||||
|
|||||||
+1
-26
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.jvm.codegen
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.MultifileFacadeFileEntry
|
|
||||||
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
|
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
|
||||||
import org.jetbrains.kotlin.codegen.ClassBuilder
|
import org.jetbrains.kotlin.codegen.ClassBuilder
|
||||||
import org.jetbrains.kotlin.codegen.OwnerKind
|
import org.jetbrains.kotlin.codegen.OwnerKind
|
||||||
@@ -23,9 +22,6 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
import org.jetbrains.kotlin.ir.util.isSuspend
|
|
||||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
|
||||||
import org.jetbrains.kotlin.ir.util.render
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
|
||||||
@@ -95,28 +91,7 @@ class IrSourceCompilerForInline(
|
|||||||
asmMethod: Method
|
asmMethod: Method
|
||||||
): SMAPAndMethodNode {
|
): SMAPAndMethodNode {
|
||||||
assert(callableDescriptor == callee.symbol.descriptor.original) { "Expected $callableDescriptor got ${callee.descriptor.original}" }
|
assert(callableDescriptor == callee.symbol.descriptor.original) { "Expected $callableDescriptor got ${callee.descriptor.original}" }
|
||||||
val irFunction = getFunctionToInline()
|
return makeInlineNode(callee, FakeClassCodegen(callee, codegen.classCodegen), false)
|
||||||
return makeInlineNode(irFunction, FakeClassCodegen(irFunction, codegen.classCodegen), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getFunctionToInline(): IrFunction {
|
|
||||||
val parent = callee.parentAsClass
|
|
||||||
|
|
||||||
if (parent.fileParent.fileEntry is MultifileFacadeFileEntry) {
|
|
||||||
codegen.context.multifileFacadeMemberToPartMember[callee]?.let { return it }
|
|
||||||
|
|
||||||
if (callee.isSuspend) {
|
|
||||||
codegen.context.suspendFunctionViewToOriginal[callee]?.let { facadeMemberOriginal ->
|
|
||||||
codegen.context.multifileFacadeMemberToPartMember[facadeMemberOriginal]?.let { partMemberOriginal ->
|
|
||||||
return partMemberOriginal.getOrCreateSuspendFunctionViewIfNeeded(codegen.context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
error("Function from a multi-file facade without the link to the function in the part: ${callee.render()}")
|
|
||||||
}
|
|
||||||
|
|
||||||
return callee
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasFinallyBlocks() = data.hasFinallyBlocks()
|
override fun hasFinallyBlocks() = data.hasFinallyBlocks()
|
||||||
|
|||||||
+13
-4
@@ -6,10 +6,12 @@
|
|||||||
package org.jetbrains.kotlin.backend.jvm.lower
|
package org.jetbrains.kotlin.backend.jvm.lower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
import org.jetbrains.kotlin.backend.common.phaser.makeIrModulePhase
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.backend.jvm.codegen.isInlineFunctionCall
|
import org.jetbrains.kotlin.backend.jvm.codegen.isInlineFunctionCall
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
@@ -19,7 +21,7 @@ import org.jetbrains.kotlin.ir.util.resolveFakeOverride
|
|||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
|
|
||||||
@Suppress("RemoveExplicitTypeArguments")
|
@Suppress("RemoveExplicitTypeArguments")
|
||||||
internal val resolveInlineCallsPhase = makeIrFilePhase<JvmBackendContext>(
|
internal val resolveInlineCallsPhase = makeIrModulePhase(
|
||||||
::ResolveInlineCalls,
|
::ResolveInlineCalls,
|
||||||
name = "ResolveInlineCalls",
|
name = "ResolveInlineCalls",
|
||||||
description = "Statically resolve calls to inline methods to particular implementations"
|
description = "Statically resolve calls to inline methods to particular implementations"
|
||||||
@@ -31,9 +33,10 @@ class ResolveInlineCalls(val context: JvmBackendContext) : IrElementTransformerV
|
|||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
if (!expression.symbol.owner.isInlineFunctionCall(context))
|
if (!expression.symbol.owner.isInlineFunctionCall(context))
|
||||||
return super.visitCall(expression)
|
return super.visitCall(expression)
|
||||||
val maybeFakeOverride = expression.symbol.owner as? IrSimpleFunction
|
val maybeFakeOverrideOfMultiFileBridge = expression.symbol.owner as? IrSimpleFunction
|
||||||
?: return super.visitCall(expression)
|
?: return super.visitCall(expression)
|
||||||
val resolved = maybeFakeOverride.resolveFakeOverride()
|
val resolved =
|
||||||
|
maybeFakeOverrideOfMultiFileBridge?.resolveMultiFileFacades() ?: maybeFakeOverrideOfMultiFileBridge.resolveFakeOverride()
|
||||||
?: return super.visitCall(expression)
|
?: return super.visitCall(expression)
|
||||||
return super.visitCall(with(expression) {
|
return super.visitCall(with(expression) {
|
||||||
IrCallImpl(startOffset, endOffset, type, resolved.symbol, expression.typeArgumentsCount, null, superQualifierSymbol).apply {
|
IrCallImpl(startOffset, endOffset, type, resolved.symbol, expression.typeArgumentsCount, null, superQualifierSymbol).apply {
|
||||||
@@ -41,4 +44,10 @@ class ResolveInlineCalls(val context: JvmBackendContext) : IrElementTransformerV
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun IrFunction.resolveMultiFileFacades(): IrFunction? {
|
||||||
|
return if (origin == JvmLoweredDeclarationOrigin.MULTIFILE_BRIDGE) {
|
||||||
|
context.multifileFacadeMemberToPartMember[this]
|
||||||
|
} else null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user