JVM_IR: Run CallableReferenceLowering before LocalDeclarationsLowering

This commit is contained in:
Steven Schäfer
2019-07-19 11:38:52 +02:00
committed by max-kammerer
parent 9816e62d08
commit c38fb27676
2 changed files with 14 additions and 2 deletions
@@ -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
@@ -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 {