[IR] Extract some local classes from inline bodies
Among other things, this fixes https://github.com/JetBrains/kotlin-native/issues/3956
This commit is contained in:
+44
-22
@@ -3,6 +3,9 @@ package org.jetbrains.kotlin.backend.konan
|
||||
import org.jetbrains.kotlin.backend.common.*
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.common.lower.inline.FunctionInlining
|
||||
import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesExtractionFromInlineFunctionsLowering
|
||||
import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineFunctionsLowering
|
||||
import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineLambdasLowering
|
||||
import org.jetbrains.kotlin.backend.common.lower.loops.ForLoopsLowering
|
||||
import org.jetbrains.kotlin.backend.common.phaser.*
|
||||
import org.jetbrains.kotlin.backend.konan.lower.*
|
||||
@@ -86,20 +89,57 @@ internal val arrayConstructorPhase = makeKonanModuleLoweringPhase(
|
||||
description = "Transform `Array(size) { index -> value }` into a loop"
|
||||
)
|
||||
|
||||
internal val lateinitPhase = makeKonanModuleOpPhase(
|
||||
{ context, irModule ->
|
||||
NullableFieldsForLateinitCreationLowering(context).lower(irModule)
|
||||
NullableFieldsDeclarationLowering(context).lower(irModule)
|
||||
LateinitUsageLowering(context).lower(irModule)
|
||||
},
|
||||
name = "Lateinit",
|
||||
description = "Lateinit properties lowering"
|
||||
)
|
||||
|
||||
internal val sharedVariablesPhase = makeKonanModuleLoweringPhase(
|
||||
::SharedVariablesLowering,
|
||||
name = "SharedVariables",
|
||||
description = "Shared variable lowering",
|
||||
prerequisite = setOf(lateinitPhase)
|
||||
)
|
||||
|
||||
internal val extractLocalClassesFromInlineBodies = namedIrModulePhase(
|
||||
lower = object : SameTypeCompilerPhase<Context, IrModuleFragment> {
|
||||
override fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment): IrModuleFragment {
|
||||
LocalClassesInInlineLambdasLowering(context).run {
|
||||
input.files.forEach { lower(it) }
|
||||
}
|
||||
LocalClassesInInlineFunctionsLowering(context).run {
|
||||
input.files.forEach { lower(it) }
|
||||
}
|
||||
LocalClassesExtractionFromInlineFunctionsLowering(context).run {
|
||||
input.files.forEach { lower(it) }
|
||||
}
|
||||
return input
|
||||
}
|
||||
},
|
||||
name = "ExtractLocalClassesFromInlineBodies",
|
||||
description = "Extraction of local classes from inline bodies",
|
||||
prerequisite = setOf(sharedVariablesPhase),
|
||||
nlevels = 0,
|
||||
actions = modulePhaseActions
|
||||
)
|
||||
|
||||
internal val inlinePhase = namedIrModulePhase(
|
||||
lower = object : SameTypeCompilerPhase<Context, IrModuleFragment> {
|
||||
override fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment): IrModuleFragment {
|
||||
FunctionInlining(context).run {
|
||||
input.files.forEach {
|
||||
lower(it)
|
||||
}
|
||||
input.files.forEach { lower(it) }
|
||||
}
|
||||
return input
|
||||
}
|
||||
},
|
||||
name = "Inline",
|
||||
description = "Functions inlining",
|
||||
prerequisite = setOf(lowerBeforeInlinePhase, arrayConstructorPhase),
|
||||
prerequisite = setOf(lowerBeforeInlinePhase, arrayConstructorPhase, extractLocalClassesFromInlineBodies),
|
||||
nlevels = 0,
|
||||
actions = modulePhaseActions
|
||||
)
|
||||
@@ -116,17 +156,6 @@ internal val lowerAfterInlinePhase = makeKonanModuleOpPhase(
|
||||
|
||||
/* IrFile phases */
|
||||
|
||||
internal val lateinitPhase = makeKonanFileOpPhase(
|
||||
{ context, irFile ->
|
||||
NullableFieldsForLateinitCreationLowering(context).lower(irFile)
|
||||
NullableFieldsDeclarationLowering(context).lower(irFile)
|
||||
LateinitUsageLowering(context).lower(irFile)
|
||||
},
|
||||
name = "Lateinit",
|
||||
description = "Lateinit properties lowering",
|
||||
prerequisite = setOf(inlinePhase)
|
||||
)
|
||||
|
||||
// TODO make all lambda-related stuff work with IrFunctionExpression and drop this phase (see kotlin: dd3f8ecaacd)
|
||||
internal val provisionalFunctionExpressionPhase = makeKonanModuleLoweringPhase(
|
||||
{ ProvisionalFunctionExpressionLowering() },
|
||||
@@ -153,13 +182,6 @@ internal val initializersPhase = makeKonanFileLoweringPhase(
|
||||
prerequisite = setOf(enumConstructorsPhase)
|
||||
)
|
||||
|
||||
internal val sharedVariablesPhase = makeKonanFileLoweringPhase(
|
||||
::SharedVariablesLowering,
|
||||
name = "SharedVariables",
|
||||
description = "Shared variable lowering",
|
||||
prerequisite = setOf(initializersPhase)
|
||||
)
|
||||
|
||||
internal val localFunctionsPhase = makeKonanFileOpPhase(
|
||||
op = { context, irFile ->
|
||||
LocalDelegatedPropertiesLowering().lower(irFile)
|
||||
|
||||
+4
-3
@@ -326,18 +326,19 @@ internal val allLoweringsPhase = namedIrModulePhase(
|
||||
stripTypeAliasDeclarationsPhase then
|
||||
lowerBeforeInlinePhase then
|
||||
arrayConstructorPhase then
|
||||
lateinitPhase then
|
||||
sharedVariablesPhase then
|
||||
extractLocalClassesFromInlineBodies then
|
||||
inlinePhase then
|
||||
provisionalFunctionExpressionPhase then
|
||||
lowerAfterInlinePhase then
|
||||
performByIrFile(
|
||||
name = "IrLowerByFile",
|
||||
description = "IR Lowering by file",
|
||||
lower = lateinitPhase then
|
||||
forLoopsPhase then
|
||||
lower = forLoopsPhase then
|
||||
stringConcatenationPhase then
|
||||
enumConstructorsPhase then
|
||||
initializersPhase then
|
||||
sharedVariablesPhase then
|
||||
localFunctionsPhase then
|
||||
tailrecPhase then
|
||||
defaultParameterExtentPhase then
|
||||
|
||||
Reference in New Issue
Block a user