diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt index 30fb52f74ca..a6e810519f4 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt @@ -8,6 +8,15 @@ package org.jetbrains.kotlin.backend.common.phaser import org.jetbrains.kotlin.backend.common.LoggingContext import kotlin.system.measureTimeMillis +/** + * Represents global compilation context and stores information about phases that were executed. + * + * @property alreadyDone A set of already executed phases. + * @property depth shows The index of the currently running phase. + * @property phaseCount A unique ID that can show the order in which phases were executed. + * @property stickyPostconditions A set of conditions that must be checked after each phase. + * When a condition is added into [stickyPostconditions], it will be executed each time some phase is executed, until we change [Data]. + */ class PhaserState( val alreadyDone: MutableSet = mutableSetOf(), var depth: Int = 0, @@ -27,7 +36,17 @@ inline fun PhaserState.downlevel(nlevels: Int, block: () -> R): R { return result } +/** + * Represents some compiler phase that can be executed. + */ interface CompilerPhase { + /** + * Executes this compiler phase. It accepts some parameter of type [Input] and transforms it into [Output]. + * + * @param phaseConfig Controls which parts of the compilation pipeline are enabled and how the compiler should validate their invariants. + * @param phaserState The global context. + * @param context The local context in which the compiler stores all the necessary information for the given phase. + */ fun invoke(phaseConfig: PhaseConfigurationService, phaserState: PhaserState, context: Context, input: Input): Output fun getNamedSubphases(startDepth: Int = 0): List>> = emptyList() diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt index bbbd9db8bb3..22e1af12537 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt @@ -33,6 +33,10 @@ class PhaseConfigBuilder(private val compoundPhase: CompilerPhase<*, *, *>) { ) } +/** + * Phase configuration that defines and configures [CompilerPhase]s that the compiler should execute. + * It is defined before compilation and can't be modified in the process. + */ class PhaseConfig( private val compoundPhase: CompilerPhase<*, *, *>, private val phases: Map = compoundPhase.toPhaseMap(),