[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
|
package org.jetbrains.kotlin.cli.common
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.phaser.FlexiblePhaseConfig
|
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.cli.common.arguments.CommonCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||||
|
|
||||||
fun createFlexiblePhaseConfig(
|
fun createFlexiblePhaseConfig(
|
||||||
arguments: CommonCompilerArguments,
|
arguments: CommonCompilerArguments,
|
||||||
): FlexiblePhaseConfig {
|
): FlexiblePhaseConfig {
|
||||||
fun Array<String>?.asNonNullSet(): Set<String> = this?.toSet() ?: emptySet()
|
fun Array<String>?.asNonNullSet(): Set<String> = this?.toSet() ?: emptySet()
|
||||||
|
|
||||||
val toDumpBoth = arguments.phasesToDump.asNonNullSet()
|
val toDumpBoth = createPhaseSetFromArguments(arguments.phasesToDump)
|
||||||
val toValidateBoth = arguments.phasesToValidate.asNonNullSet()
|
val toValidateBoth = createPhaseSetFromArguments(arguments.phasesToValidate)
|
||||||
|
|
||||||
return FlexiblePhaseConfig(
|
return FlexiblePhaseConfig(
|
||||||
disabled = arguments.disablePhases.asNonNullSet(),
|
disabled = arguments.disablePhases.asNonNullSet(),
|
||||||
verbose = arguments.verbosePhases.asNonNullSet(),
|
verbose = arguments.verbosePhases.asNonNullSet(),
|
||||||
toDumpStateBefore = arguments.phasesToDumpBefore.asNonNullSet() + toDumpBoth,
|
toDumpStateBefore = createPhaseSetFromArguments(arguments.phasesToDumpBefore) + toDumpBoth,
|
||||||
toDumpStateAfter = arguments.phasesToDumpAfter.asNonNullSet() + toDumpBoth,
|
toDumpStateAfter = createPhaseSetFromArguments(arguments.phasesToDumpAfter) + toDumpBoth,
|
||||||
toValidateStateBefore = arguments.phasesToValidateBefore.asNonNullSet() + toValidateBoth,
|
toValidateStateBefore = createPhaseSetFromArguments(arguments.phasesToValidateBefore) + toValidateBoth,
|
||||||
toValidateStateAfter = arguments.phasesToValidateAfter.asNonNullSet() + toValidateBoth,
|
toValidateStateAfter = createPhaseSetFromArguments(arguments.phasesToValidateAfter) + toValidateBoth,
|
||||||
dumpOnlyFqName = arguments.dumpOnlyFqName,
|
dumpOnlyFqName = arguments.dumpOnlyFqName,
|
||||||
dumpToDirectory = arguments.dumpDirectory,
|
dumpToDirectory = arguments.dumpDirectory,
|
||||||
needProfiling = arguments.profilePhases,
|
needProfiling = arguments.profilePhases,
|
||||||
checkConditions = arguments.checkPhaseConditions,
|
checkConditions = arguments.checkPhaseConditions,
|
||||||
checkStickyConditions = arguments.checkStickyPhaseConditions,
|
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
|
package org.jetbrains.kotlin.backend.common.phaser
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phase configuration that does not know anything
|
* Phase configuration that does not know anything
|
||||||
* about actual compiler pipeline upfront.
|
* about actual compiler pipeline upfront.
|
||||||
@@ -12,10 +14,10 @@ package org.jetbrains.kotlin.backend.common.phaser
|
|||||||
class FlexiblePhaseConfig(
|
class FlexiblePhaseConfig(
|
||||||
disabled: Set<String>,
|
disabled: Set<String>,
|
||||||
private val verbose: Set<String>,
|
private val verbose: Set<String>,
|
||||||
private val toDumpStateBefore: Set<String>,
|
private val toDumpStateBefore: PhaseSet,
|
||||||
private val toDumpStateAfter: Set<String>,
|
private val toDumpStateAfter: PhaseSet,
|
||||||
private val toValidateStateBefore: Set<String>,
|
private val toValidateStateBefore: PhaseSet,
|
||||||
private val toValidateStateAfter: Set<String>,
|
private val toValidateStateAfter: PhaseSet,
|
||||||
override val dumpToDirectory: String? = null,
|
override val dumpToDirectory: String? = null,
|
||||||
override val dumpOnlyFqName: String? = null,
|
override val dumpOnlyFqName: String? = null,
|
||||||
override val needProfiling: Boolean = false,
|
override val needProfiling: Boolean = false,
|
||||||
@@ -35,14 +37,37 @@ class FlexiblePhaseConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldDumpStateBefore(phase: AnyNamedPhase): Boolean =
|
override fun shouldDumpStateBefore(phase: AnyNamedPhase): Boolean =
|
||||||
phase.name in toDumpStateBefore
|
phase in toDumpStateBefore
|
||||||
|
|
||||||
override fun shouldDumpStateAfter(phase: AnyNamedPhase): Boolean =
|
override fun shouldDumpStateAfter(phase: AnyNamedPhase): Boolean =
|
||||||
phase.name in toDumpStateAfter
|
phase in toDumpStateAfter
|
||||||
|
|
||||||
override fun shouldValidateStateBefore(phase: AnyNamedPhase): Boolean =
|
override fun shouldValidateStateBefore(phase: AnyNamedPhase): Boolean =
|
||||||
phase.name in toValidateStateBefore
|
phase in toValidateStateBefore
|
||||||
|
|
||||||
override fun shouldValidateStateAfter(phase: AnyNamedPhase): Boolean =
|
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