JVM_IR: Run CallableReferenceLowering before LocalDeclarationsLowering
This commit is contained in:
committed by
max-kammerer
parent
9816e62d08
commit
c38fb27676
@@ -81,7 +81,7 @@ private val localDeclarationsPhase = makeIrFilePhase<CommonBackendContext>(
|
||||
},
|
||||
name = "JvmLocalDeclarations",
|
||||
description = "Move local declarations to classes",
|
||||
prerequisite = setOf(sharedVariablesPhase)
|
||||
prerequisite = setOf(callableReferencePhase, sharedVariablesPhase)
|
||||
)
|
||||
|
||||
private val defaultArgumentStubPhase = makeIrFilePhase<CommonBackendContext>(
|
||||
@@ -124,6 +124,7 @@ private val jvmFilePhases =
|
||||
|
||||
enumWhenPhase then
|
||||
singletonReferencesPhase then
|
||||
callableReferencePhase then
|
||||
localDeclarationsPhase then
|
||||
defaultArgumentStubPhase then
|
||||
|
||||
@@ -133,7 +134,6 @@ private val jvmFilePhases =
|
||||
|
||||
singleAbstractMethodPhase then
|
||||
addContinuationPhase then
|
||||
callableReferencePhase then
|
||||
functionNVarargInvokePhase then
|
||||
|
||||
innerClassesPhase then
|
||||
|
||||
+12
@@ -64,6 +64,17 @@ internal class CallableReferenceLowering(val context: JvmBackendContext) : FileL
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.transformChildrenVoid(object : IrElementTransformerVoidWithContext() {
|
||||
override fun visitTypeOperator(expression: IrTypeOperatorCall): IrExpression {
|
||||
if (expression.operator == IrTypeOperator.SAM_CONVERSION) {
|
||||
val invokable = expression.argument
|
||||
if (invokable is IrFunctionReference) {
|
||||
inlineLambdaReferences += invokable
|
||||
} else if (invokable is IrBlock && invokable.statements.last() is IrFunctionReference) {
|
||||
inlineLambdaReferences += invokable.statements.last() as IrFunctionReference
|
||||
}
|
||||
}
|
||||
return super.visitTypeOperator(expression)
|
||||
}
|
||||
|
||||
override fun visitFunctionAccess(expression: IrFunctionAccessExpression): IrExpression {
|
||||
val callee = expression.symbol.owner
|
||||
@@ -177,6 +188,7 @@ internal class CallableReferenceLowering(val context: JvmBackendContext) : FileL
|
||||
|
||||
private val functionReferenceClass = buildClass {
|
||||
setSourceRange(irFunctionReference)
|
||||
visibility = Visibilities.LOCAL
|
||||
origin = JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL
|
||||
name = Name.special("<function reference to ${callee.fqNameWhenAvailable}>")
|
||||
}.apply {
|
||||
|
||||
Reference in New Issue
Block a user