From f9d0755f9495be25b7db45c81c1d58dc5190ba44 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Tue, 24 Jan 2023 15:14:52 +0200 Subject: [PATCH] [K/N] Introduce more createFileLoweringPhase overloads They simplify porting from the old builders --- .../backend/konan/driver/phases/Lowerings.kt | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Lowerings.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Lowerings.kt index 27316ed62db..3fd4c348c99 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Lowerings.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Lowerings.kt @@ -48,46 +48,39 @@ internal val modulePhaseActions: Set ReturnsInsertionLowering(context.context).lower(irFile) } + lowering = ::ReturnsInsertionLowering, ) -internal val InlineClassPropertyAccessorsPhase = createSimpleNamedCompilerPhase( +internal val InlineClassPropertyAccessorsPhase = createFileLoweringPhase( name = "InlineClassPropertyAccessorsLowering", description = "Inline class property accessors", - postactions = fileLoweringActions, - op = { context, irFile -> InlineClassPropertyAccessorsLowering(context.context).lower(irFile) } + lowering = ::InlineClassPropertyAccessorsLowering, ) -internal val RedundantCoercionsCleaningPhase = createSimpleNamedCompilerPhase( +internal val RedundantCoercionsCleaningPhase = createFileLoweringPhase( name = "RedundantCoercionsCleaning", description = "Redundant coercions cleaning", - postactions = fileLoweringActions, - op = { context, irFile -> RedundantCoercionsCleaner(context.context).lower(irFile) } + lowering = ::RedundantCoercionsCleaner, ) -internal val PropertyAccessorInlinePhase = createSimpleNamedCompilerPhase( +internal val PropertyAccessorInlinePhase = createFileLoweringPhase( name = "PropertyAccessorInline", description = "Property accessor inline lowering", - postactions = fileLoweringActions -) { context, irFile -> - PropertyAccessorInlineLowering(context.context).lower(irFile) -} + lowering = ::PropertyAccessorInlineLowering, +) -internal val UnboxInlinePhase = createSimpleNamedCompilerPhase( +internal val UnboxInlinePhase = createFileLoweringPhase( name = "UnboxInline", description = "Unbox functions inline lowering", - postactions = fileLoweringActions -) { context, irFile -> - UnboxInlineLowering(context.context).lower(irFile) -} + lowering = ::UnboxInlineLowering, +) private val InlinePhase = createFileLoweringPhase( - lowering = { context -> + lowering = { context: NativeGenerationState -> object : FileLoweringPass { override fun lower(irFile: IrFile) { FunctionInlining(context.context, NativeInlineFunctionResolver(context.context, context)).lower(irFile) @@ -136,7 +129,7 @@ private val ObjectClassesPhase = createFileLoweringPhase( ) private val CoroutinesPhase = createFileLoweringPhase( - lowering = { context -> + lowering = { context: NativeGenerationState -> object : FileLoweringPass { override fun lower(irFile: IrFile) { NativeSuspendFunctionsLowering(context).lower(irFile) @@ -246,3 +239,37 @@ private fun createFileLoweringPhase( } ) +private fun createFileLoweringPhase( + lowering: (Context) -> FileLoweringPass, + name: String, + description: String, + prerequisite: Set> = emptySet(), +): SimpleNamedCompilerPhase = createSimpleNamedCompilerPhase( + name, + description, + postactions = fileLoweringActions, + prerequisite = prerequisite, + outputIfNotEnabled = { _, _, _, irFile -> irFile }, + op = { context, irFile -> + lowering(context.context).lower(irFile) + irFile + } +) + +private fun createFileLoweringPhase( + op: (context: Context, irFile: IrFile) -> Unit, + name: String, + description: String, + prerequisite: Set> = emptySet(), +): SimpleNamedCompilerPhase = createSimpleNamedCompilerPhase( + name, + description, + postactions = fileLoweringActions, + prerequisite = prerequisite, + outputIfNotEnabled = { _, _, _, irFile -> irFile }, + op = { context, irFile -> + op(context.context, irFile) + irFile + } +) +