Move createPhaseConfig to module cli
To use things like MessageCollector to report errors/warnings related to incorrect phase configuration flags
This commit is contained in:
committed by
Georgy Bronnikov
parent
2995be8bd2
commit
0fb444a5d1
+1
-46
@@ -5,33 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.phaser
|
||||
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
|
||||
fun createPhaseConfig(compoundPhase: CompilerPhase<*, *, *>, config: CompilerConfiguration): PhaseConfig {
|
||||
val phases = compoundPhase.toPhaseMap()
|
||||
val enabled = computeEnabled(phases, config).toMutableSet()
|
||||
val verbose = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.VERBOSE_PHASES)
|
||||
|
||||
val beforeDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE)
|
||||
val afterDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER)
|
||||
val bothDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE)
|
||||
val toDumpStateBefore = beforeDumpSet + bothDumpSet
|
||||
val toDumpStateAfter = afterDumpSet + bothDumpSet
|
||||
val beforeValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_BEFORE)
|
||||
val afterValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_AFTER)
|
||||
val bothValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE)
|
||||
val toValidateStateBefore = beforeValidateSet + bothValidateSet
|
||||
val toValidateStateAfter = afterValidateSet + bothValidateSet
|
||||
|
||||
val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES)
|
||||
val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS)
|
||||
val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS)
|
||||
|
||||
return PhaseConfig(compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter, needProfiling, checkConditions, checkStickyConditions)
|
||||
}
|
||||
|
||||
fun createDefaultPhaseConfig(compoundPhase: CompilerPhase<*, *, *>): PhaseConfig {
|
||||
val phases = compoundPhase.toPhaseMap()
|
||||
val enabled = phases.values.toMutableSet()
|
||||
@@ -44,31 +17,13 @@ fun createDefaultPhaseConfig(compoundPhase: CompilerPhase<*, *, *>): PhaseConfig
|
||||
)
|
||||
}
|
||||
|
||||
private fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap<String, AnyNamedPhase> =
|
||||
fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap<String, AnyNamedPhase> =
|
||||
getNamedSubphases().fold(mutableMapOf()) { acc, (_, phase) ->
|
||||
check(phase.name !in acc) { "Duplicate phase name '${phase.name}'"}
|
||||
acc[phase.name] = phase
|
||||
acc
|
||||
}
|
||||
|
||||
private fun computeEnabled(
|
||||
phases: MutableMap<String, AnyNamedPhase>,
|
||||
config: CompilerConfiguration
|
||||
): Set<AnyNamedPhase> {
|
||||
val disabledPhases = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.DISABLED_PHASES)
|
||||
return phases.values.toSet() - disabledPhases
|
||||
}
|
||||
|
||||
private fun phaseSetFromConfiguration(
|
||||
phases: MutableMap<String, AnyNamedPhase>,
|
||||
config: CompilerConfiguration,
|
||||
key: CompilerConfigurationKey<Set<String>>
|
||||
): Set<AnyNamedPhase> {
|
||||
val phaseNames = config.get(key) ?: emptySet()
|
||||
if ("ALL" in phaseNames) return phases.values.toSet()
|
||||
return phaseNames.map { phases[it]!! }.toSet()
|
||||
}
|
||||
|
||||
class PhaseConfig(
|
||||
private val compoundPhase: CompilerPhase<*, *, *>,
|
||||
private val phases: MutableMap<String, AnyNamedPhase>,
|
||||
|
||||
Reference in New Issue
Block a user