From 78467792d55deee55725cb53fa4a7b8f3d5dd77e Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 31 Mar 2020 20:43:49 +0200 Subject: [PATCH] JVM IR: rename CallableReferenceLowering -> FunctionReferenceLowering Property references are handled by PropertyReferenceLowering. --- .../jetbrains/kotlin/backend/jvm/JvmLower.kt | 6 +++--- .../backend/jvm/lower/AssertionLowering.kt | 4 ++-- .../backend/jvm/lower/EnumClassLowering.kt | 2 +- ...wering.kt => FunctionReferenceLowering.kt} | 19 ++++++++----------- .../jvm/lower/PropertyReferenceLowering.kt | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) rename compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/{CallableReferenceLowering.kt => FunctionReferenceLowering.kt} (97%) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt index 3c7bc0649cd..1b7cea2f382 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt @@ -143,7 +143,7 @@ internal val localDeclarationsPhase = makeIrFilePhase( }, name = "JvmLocalDeclarations", description = "Move local declarations to classes", - prerequisite = setOf(callableReferencePhase, sharedVariablesPhase) + prerequisite = setOf(functionReferencePhase, sharedVariablesPhase) ) private val jvmLocalClassExtractionPhase = makeIrFilePhase( @@ -181,7 +181,7 @@ private val defaultArgumentInjectorPhase = makeIrFilePhase( ::JvmDefaultParameterInjector, name = "DefaultParameterInjector", description = "Transform calls with default arguments into calls to stubs", - prerequisite = setOf(callableReferencePhase, inlineCallableReferenceToLambdaPhase) + prerequisite = setOf(functionReferencePhase, inlineCallableReferenceToLambdaPhase) ) private val interfacePhase = makeIrFilePhase( @@ -303,7 +303,7 @@ private val jvmFilePhases = enumWhenPhase then singletonReferencesPhase then - callableReferencePhase then + functionReferencePhase then singleAbstractMethodPhase then assertionPhase then returnableBlocksPhase then diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AssertionLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AssertionLowering.kt index 83182a10c97..0fc12226a30 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AssertionLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AssertionLowering.kt @@ -39,7 +39,7 @@ internal val assertionPhase = makeIrFilePhase( description = "Lower assert calls depending on the assertions mode", // Necessary to place the `$assertionsDisabled` field into the reference's class, not the // class that contains it. - prerequisite = setOf(callableReferencePhase) + prerequisite = setOf(functionReferencePhase) ) private class AssertionLowering(private val context: JvmBackendContext) : @@ -133,7 +133,7 @@ private class AssertionLowering(private val context: JvmBackendContext) : } private fun IrBuilderWithScope.getJavaClass(backendContext: JvmBackendContext, irClass: IrClass) = - with(CallableReferenceLowering) { + with(FunctionReferenceLowering) { javaClassReference(irClass.defaultType, backendContext) } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt index e7131056c46..1cb90bfb8a3 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt @@ -142,7 +142,7 @@ private class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringP IrSyntheticBodyKind.ENUM_VALUEOF -> irCall(backendContext.ir.symbols.enumValueOfFunction).apply { - putValueArgument(0, with(CallableReferenceLowering) { + putValueArgument(0, with(FunctionReferenceLowering) { javaClassReference(irClass.defaultType, backendContext) }) putValueArgument(1, irGet(declaration.valueParameters[0])) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt similarity index 97% rename from compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt rename to compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt index 36e14f029c7..15c90c045c0 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt @@ -36,24 +36,21 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames -internal val callableReferencePhase = makeIrFilePhase( - ::CallableReferenceLowering, - name = "CallableReference", - description = "Handle callable references" +internal val functionReferencePhase = makeIrFilePhase( + ::FunctionReferenceLowering, + name = "FunctionReference", + description = "Construct instances of anonymous KFunction subclasses for function references" ) - - -// Originally copied from K/Native -internal class CallableReferenceLowering(private val context: JvmBackendContext) : FileLoweringPass, IrElementTransformerVoidWithContext() { +internal class FunctionReferenceLowering(private val context: JvmBackendContext) : FileLoweringPass, IrElementTransformerVoidWithContext() { // This pass ignores suspend function references and function references used in inline arguments to inline functions. private val ignoredFunctionReferences = mutableSetOf() private val IrFunctionReference.isIgnored: Boolean - get() = (!type.isFunctionOrKFunction() || ignoredFunctionReferences.contains(this)) && !isSuspendCallableReference() + get() = (!type.isFunctionOrKFunction() || ignoredFunctionReferences.contains(this)) && !isSuspendFunctionReference() // TODO: Currently, origin of callable references is null. Do we need to create one? - private fun IrFunctionReference.isSuspendCallableReference(): Boolean = isSuspend && origin == null + private fun IrFunctionReference.isSuspendFunctionReference(): Boolean = isSuspend && origin == null override fun lower(irFile: IrFile) { ignoredFunctionReferences.addAll(IrInlineReferenceLocator.scan(context, irFile)) @@ -351,7 +348,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext) private fun createGetOwnerMethod(superFunction: IrSimpleFunction): IrSimpleFunction = buildOverride(superFunction).apply { body = context.createIrBuilder(symbol, startOffset, endOffset).run { - irExprBody(calculateOwner(callee.parent, this@CallableReferenceLowering.context)) + irExprBody(calculateOwner(callee.parent, this@FunctionReferenceLowering.context)) } } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt index 0633a4aa44a..4c8bf167e88 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt @@ -93,7 +93,7 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class } private fun IrBuilderWithScope.buildReflectedContainerReference(expression: IrMemberAccessExpression): IrExpression = - with(CallableReferenceLowering) { + with(FunctionReferenceLowering) { calculateOwner(expression.propertyContainer, this@PropertyReferenceLowering.context) }