diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/createFlexiblePhaseConfig.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/createFlexiblePhaseConfig.kt index b5171abc397..087e414c3e8 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/createFlexiblePhaseConfig.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/createFlexiblePhaseConfig.kt @@ -6,27 +6,35 @@ package org.jetbrains.kotlin.cli.common import org.jetbrains.kotlin.backend.common.phaser.FlexiblePhaseConfig +import org.jetbrains.kotlin.backend.common.phaser.PhaseSet import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly fun createFlexiblePhaseConfig( arguments: CommonCompilerArguments, ): FlexiblePhaseConfig { fun Array?.asNonNullSet(): Set = this?.toSet() ?: emptySet() - val toDumpBoth = arguments.phasesToDump.asNonNullSet() - val toValidateBoth = arguments.phasesToValidate.asNonNullSet() + val toDumpBoth = createPhaseSetFromArguments(arguments.phasesToDump) + val toValidateBoth = createPhaseSetFromArguments(arguments.phasesToValidate) return FlexiblePhaseConfig( disabled = arguments.disablePhases.asNonNullSet(), verbose = arguments.verbosePhases.asNonNullSet(), - toDumpStateBefore = arguments.phasesToDumpBefore.asNonNullSet() + toDumpBoth, - toDumpStateAfter = arguments.phasesToDumpAfter.asNonNullSet() + toDumpBoth, - toValidateStateBefore = arguments.phasesToValidateBefore.asNonNullSet() + toValidateBoth, - toValidateStateAfter = arguments.phasesToValidateAfter.asNonNullSet() + toValidateBoth, + toDumpStateBefore = createPhaseSetFromArguments(arguments.phasesToDumpBefore) + toDumpBoth, + toDumpStateAfter = createPhaseSetFromArguments(arguments.phasesToDumpAfter) + toDumpBoth, + toValidateStateBefore = createPhaseSetFromArguments(arguments.phasesToValidateBefore) + toValidateBoth, + toValidateStateAfter = createPhaseSetFromArguments(arguments.phasesToValidateAfter) + toValidateBoth, dumpOnlyFqName = arguments.dumpOnlyFqName, dumpToDirectory = arguments.dumpDirectory, needProfiling = arguments.profilePhases, checkConditions = arguments.checkPhaseConditions, checkStickyConditions = arguments.checkStickyPhaseConditions, ) +} + +private fun createPhaseSetFromArguments(names: Array?): PhaseSet = when { + names == null -> PhaseSet.Enum(emptySet()) + "all" in names.map { it.toLowerCaseAsciiOnly() } -> PhaseSet.ALL + else -> PhaseSet.Enum(names.map { it.toLowerCaseAsciiOnly() }.toSet()) } \ No newline at end of file diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/FlexiblePhaseConfig.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/FlexiblePhaseConfig.kt index 74d8da7be45..02d5c3145e1 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/FlexiblePhaseConfig.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/FlexiblePhaseConfig.kt @@ -5,6 +5,8 @@ package org.jetbrains.kotlin.backend.common.phaser +import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly + /** * Phase configuration that does not know anything * about actual compiler pipeline upfront. @@ -12,10 +14,10 @@ package org.jetbrains.kotlin.backend.common.phaser class FlexiblePhaseConfig( disabled: Set, private val verbose: Set, - private val toDumpStateBefore: Set, - private val toDumpStateAfter: Set, - private val toValidateStateBefore: Set, - private val toValidateStateAfter: Set, + private val toDumpStateBefore: PhaseSet, + private val toDumpStateAfter: PhaseSet, + private val toValidateStateBefore: PhaseSet, + private val toValidateStateAfter: PhaseSet, override val dumpToDirectory: String? = null, override val dumpOnlyFqName: String? = null, override val needProfiling: Boolean = false, @@ -35,14 +37,37 @@ class FlexiblePhaseConfig( } override fun shouldDumpStateBefore(phase: AnyNamedPhase): Boolean = - phase.name in toDumpStateBefore + phase in toDumpStateBefore override fun shouldDumpStateAfter(phase: AnyNamedPhase): Boolean = - phase.name in toDumpStateAfter + phase in toDumpStateAfter override fun shouldValidateStateBefore(phase: AnyNamedPhase): Boolean = - phase.name in toValidateStateBefore + phase in toValidateStateBefore override fun shouldValidateStateAfter(phase: AnyNamedPhase): Boolean = - phase.name in toValidateStateAfter + phase in toValidateStateAfter +} + +sealed class PhaseSet { + abstract operator fun contains(phase: AnyNamedPhase): Boolean + + abstract operator fun plus(phaseSet: PhaseSet): PhaseSet + + class Enum(val phases: Set) : PhaseSet() { + override fun contains(phase: AnyNamedPhase): Boolean = + phase.name.toLowerCaseAsciiOnly() in phases + + override fun plus(phaseSet: PhaseSet): PhaseSet = when (phaseSet) { + ALL -> ALL + is Enum -> Enum(phases + phaseSet.phases) + } + } + object ALL : PhaseSet() { + override fun contains(phase: AnyNamedPhase): Boolean = + true + + override fun plus(phaseSet: PhaseSet): PhaseSet = ALL + } + }