[K/N] Fix ALL phases value
This commit is contained in:
committed by
Space Team
parent
9f4e086ff9
commit
0b4db4beca
@@ -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<String>?.asNonNullSet(): Set<String> = 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<String>?): PhaseSet = when {
|
||||
names == null -> PhaseSet.Enum(emptySet())
|
||||
"all" in names.map { it.toLowerCaseAsciiOnly() } -> PhaseSet.ALL
|
||||
else -> PhaseSet.Enum(names.map { it.toLowerCaseAsciiOnly() }.toSet())
|
||||
}
|
||||
+33
-8
@@ -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<String>,
|
||||
private val verbose: Set<String>,
|
||||
private val toDumpStateBefore: Set<String>,
|
||||
private val toDumpStateAfter: Set<String>,
|
||||
private val toValidateStateBefore: Set<String>,
|
||||
private val toValidateStateAfter: Set<String>,
|
||||
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<String>) : 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user