JVM IR: rename CallableReferenceLowering -> FunctionReferenceLowering
Property references are handled by PropertyReferenceLowering.
This commit is contained in:
@@ -143,7 +143,7 @@ internal val localDeclarationsPhase = makeIrFilePhase<CommonBackendContext>(
|
|||||||
},
|
},
|
||||||
name = "JvmLocalDeclarations",
|
name = "JvmLocalDeclarations",
|
||||||
description = "Move local declarations to classes",
|
description = "Move local declarations to classes",
|
||||||
prerequisite = setOf(callableReferencePhase, sharedVariablesPhase)
|
prerequisite = setOf(functionReferencePhase, sharedVariablesPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val jvmLocalClassExtractionPhase = makeIrFilePhase(
|
private val jvmLocalClassExtractionPhase = makeIrFilePhase(
|
||||||
@@ -181,7 +181,7 @@ private val defaultArgumentInjectorPhase = makeIrFilePhase(
|
|||||||
::JvmDefaultParameterInjector,
|
::JvmDefaultParameterInjector,
|
||||||
name = "DefaultParameterInjector",
|
name = "DefaultParameterInjector",
|
||||||
description = "Transform calls with default arguments into calls to stubs",
|
description = "Transform calls with default arguments into calls to stubs",
|
||||||
prerequisite = setOf(callableReferencePhase, inlineCallableReferenceToLambdaPhase)
|
prerequisite = setOf(functionReferencePhase, inlineCallableReferenceToLambdaPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val interfacePhase = makeIrFilePhase(
|
private val interfacePhase = makeIrFilePhase(
|
||||||
@@ -303,7 +303,7 @@ private val jvmFilePhases =
|
|||||||
enumWhenPhase then
|
enumWhenPhase then
|
||||||
singletonReferencesPhase then
|
singletonReferencesPhase then
|
||||||
|
|
||||||
callableReferencePhase then
|
functionReferencePhase then
|
||||||
singleAbstractMethodPhase then
|
singleAbstractMethodPhase then
|
||||||
assertionPhase then
|
assertionPhase then
|
||||||
returnableBlocksPhase then
|
returnableBlocksPhase then
|
||||||
|
|||||||
+2
-2
@@ -39,7 +39,7 @@ internal val assertionPhase = makeIrFilePhase(
|
|||||||
description = "Lower assert calls depending on the assertions mode",
|
description = "Lower assert calls depending on the assertions mode",
|
||||||
// Necessary to place the `$assertionsDisabled` field into the reference's class, not the
|
// Necessary to place the `$assertionsDisabled` field into the reference's class, not the
|
||||||
// class that contains it.
|
// class that contains it.
|
||||||
prerequisite = setOf(callableReferencePhase)
|
prerequisite = setOf(functionReferencePhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private class AssertionLowering(private val context: JvmBackendContext) :
|
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) =
|
private fun IrBuilderWithScope.getJavaClass(backendContext: JvmBackendContext, irClass: IrClass) =
|
||||||
with(CallableReferenceLowering) {
|
with(FunctionReferenceLowering) {
|
||||||
javaClassReference(irClass.defaultType, backendContext)
|
javaClassReference(irClass.defaultType, backendContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ private class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringP
|
|||||||
|
|
||||||
IrSyntheticBodyKind.ENUM_VALUEOF ->
|
IrSyntheticBodyKind.ENUM_VALUEOF ->
|
||||||
irCall(backendContext.ir.symbols.enumValueOfFunction).apply {
|
irCall(backendContext.ir.symbols.enumValueOfFunction).apply {
|
||||||
putValueArgument(0, with(CallableReferenceLowering) {
|
putValueArgument(0, with(FunctionReferenceLowering) {
|
||||||
javaClassReference(irClass.defaultType, backendContext)
|
javaClassReference(irClass.defaultType, backendContext)
|
||||||
})
|
})
|
||||||
putValueArgument(1, irGet(declaration.valueParameters[0]))
|
putValueArgument(1, irGet(declaration.valueParameters[0]))
|
||||||
|
|||||||
+8
-11
@@ -36,24 +36,21 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
|
|
||||||
internal val callableReferencePhase = makeIrFilePhase(
|
internal val functionReferencePhase = makeIrFilePhase(
|
||||||
::CallableReferenceLowering,
|
::FunctionReferenceLowering,
|
||||||
name = "CallableReference",
|
name = "FunctionReference",
|
||||||
description = "Handle callable references"
|
description = "Construct instances of anonymous KFunction subclasses for function references"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internal class FunctionReferenceLowering(private val context: JvmBackendContext) : FileLoweringPass, IrElementTransformerVoidWithContext() {
|
||||||
|
|
||||||
// Originally copied from K/Native
|
|
||||||
internal class CallableReferenceLowering(private val context: JvmBackendContext) : FileLoweringPass, IrElementTransformerVoidWithContext() {
|
|
||||||
// This pass ignores suspend function references and function references used in inline arguments to inline functions.
|
// This pass ignores suspend function references and function references used in inline arguments to inline functions.
|
||||||
private val ignoredFunctionReferences = mutableSetOf<IrCallableReference>()
|
private val ignoredFunctionReferences = mutableSetOf<IrCallableReference>()
|
||||||
|
|
||||||
private val IrFunctionReference.isIgnored: Boolean
|
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?
|
// 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) {
|
override fun lower(irFile: IrFile) {
|
||||||
ignoredFunctionReferences.addAll(IrInlineReferenceLocator.scan(context, 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 {
|
private fun createGetOwnerMethod(superFunction: IrSimpleFunction): IrSimpleFunction = buildOverride(superFunction).apply {
|
||||||
body = context.createIrBuilder(symbol, startOffset, endOffset).run {
|
body = context.createIrBuilder(symbol, startOffset, endOffset).run {
|
||||||
irExprBody(calculateOwner(callee.parent, this@CallableReferenceLowering.context))
|
irExprBody(calculateOwner(callee.parent, this@FunctionReferenceLowering.context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -93,7 +93,7 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun IrBuilderWithScope.buildReflectedContainerReference(expression: IrMemberAccessExpression): IrExpression =
|
private fun IrBuilderWithScope.buildReflectedContainerReference(expression: IrMemberAccessExpression): IrExpression =
|
||||||
with(CallableReferenceLowering) {
|
with(FunctionReferenceLowering) {
|
||||||
calculateOwner(expression.propertyContainer, this@PropertyReferenceLowering.context)
|
calculateOwner(expression.propertyContainer, this@PropertyReferenceLowering.context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user