Extract createPhaseConfig from PhaseConfig
To remove dependency of PhaseConfig on CLI-dependent concepts such as CompilerConfiguration
This commit is contained in:
committed by
Georgy Bronnikov
parent
ce40bfb259
commit
ddad3034da
+52
-38
@@ -9,44 +9,69 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
|||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||||
|
|
||||||
class PhaseConfig(private val compoundPhase: CompilerPhase<*, *, *>, config: CompilerConfiguration) {
|
fun createPhaseConfig(compoundPhase: CompilerPhase<*, *, *>, config: CompilerConfiguration): PhaseConfig {
|
||||||
|
|
||||||
val phases = compoundPhase.getNamedSubphases().fold(mutableMapOf<String, AnyNamedPhase>()) { acc, (_, phase) ->
|
val phases = compoundPhase.getNamedSubphases().fold(mutableMapOf<String, AnyNamedPhase>()) { acc, (_, phase) ->
|
||||||
check(phase.name !in acc) { "Duplicate phase name '${phase.name}'"}
|
check(phase.name !in acc) { "Duplicate phase name '${phase.name}'"}
|
||||||
acc[phase.name] = phase
|
acc[phase.name] = phase
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
private val enabledMut = computeEnabled(config).toMutableSet()
|
|
||||||
|
|
||||||
val enabled: Set<AnyNamedPhase> get() = enabledMut
|
val enabled = computeEnabled(phases, config).toMutableSet()
|
||||||
|
val verbose = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.VERBOSE_PHASES)
|
||||||
|
|
||||||
val verbose = phaseSetFromConfiguration(config, CommonConfigurationKeys.VERBOSE_PHASES)
|
val beforeDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE)
|
||||||
val toDumpStateBefore: Set<AnyNamedPhase>
|
val afterDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER)
|
||||||
|
val bothDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE)
|
||||||
val toDumpStateAfter: Set<AnyNamedPhase>
|
val toDumpStateBefore = beforeDumpSet + bothDumpSet
|
||||||
val toValidateStateBefore: Set<AnyNamedPhase>
|
val toDumpStateAfter = afterDumpSet + bothDumpSet
|
||||||
|
val beforeValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_BEFORE)
|
||||||
val toValidateStateAfter: Set<AnyNamedPhase>
|
val afterValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_AFTER)
|
||||||
|
val bothValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE)
|
||||||
init {
|
val toValidateStateBefore = beforeValidateSet + bothValidateSet
|
||||||
with(CommonConfigurationKeys) {
|
val toValidateStateAfter = afterValidateSet + bothValidateSet
|
||||||
val beforeDumpSet = phaseSetFromConfiguration(config, PHASES_TO_DUMP_STATE_BEFORE)
|
|
||||||
val afterDumpSet = phaseSetFromConfiguration(config, PHASES_TO_DUMP_STATE_AFTER)
|
|
||||||
val bothDumpSet = phaseSetFromConfiguration(config, PHASES_TO_DUMP_STATE)
|
|
||||||
toDumpStateBefore = beforeDumpSet + bothDumpSet
|
|
||||||
toDumpStateAfter = afterDumpSet + bothDumpSet
|
|
||||||
val beforeValidateSet = phaseSetFromConfiguration(config, PHASES_TO_VALIDATE_BEFORE)
|
|
||||||
val afterValidateSet = phaseSetFromConfiguration(config, PHASES_TO_VALIDATE_AFTER)
|
|
||||||
val bothValidateSet = phaseSetFromConfiguration(config, PHASES_TO_VALIDATE)
|
|
||||||
toValidateStateBefore = beforeValidateSet + bothValidateSet
|
|
||||||
toValidateStateAfter = afterValidateSet + bothValidateSet
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES)
|
val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES)
|
||||||
val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS)
|
val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS)
|
||||||
val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS)
|
val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS)
|
||||||
|
|
||||||
|
return PhaseConfig(compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter, needProfiling, checkConditions, checkStickyConditions)
|
||||||
|
}
|
||||||
|
|
||||||
|
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>,
|
||||||
|
enabled: MutableSet<AnyNamedPhase>,
|
||||||
|
val verbose: Set<AnyNamedPhase>,
|
||||||
|
val toDumpStateBefore: Set<AnyNamedPhase>,
|
||||||
|
val toDumpStateAfter: Set<AnyNamedPhase>,
|
||||||
|
val toValidateStateBefore: Set<AnyNamedPhase>,
|
||||||
|
val toValidateStateAfter: Set<AnyNamedPhase>,
|
||||||
|
val needProfiling: Boolean,
|
||||||
|
val checkConditions: Boolean,
|
||||||
|
val checkStickyConditions: Boolean
|
||||||
|
) {
|
||||||
|
private val enabledMut = enabled
|
||||||
|
|
||||||
|
val enabled: Set<AnyNamedPhase> get() = enabledMut
|
||||||
|
|
||||||
fun known(name: String): String {
|
fun known(name: String): String {
|
||||||
if (phases[name] == null) {
|
if (phases[name] == null) {
|
||||||
error("Unknown phase: $name. Use -Xlist-phases to see the list of phases.")
|
error("Unknown phase: $name. Use -Xlist-phases to see the list of phases.")
|
||||||
@@ -63,18 +88,6 @@ class PhaseConfig(private val compoundPhase: CompilerPhase<*, *, *>, config: Com
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeEnabled(config: CompilerConfiguration) =
|
|
||||||
with(CommonConfigurationKeys) {
|
|
||||||
val disabledPhases = phaseSetFromConfiguration(config, DISABLED_PHASES)
|
|
||||||
phases.values.toSet() - disabledPhases
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun phaseSetFromConfiguration(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()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun enable(phase: AnyNamedPhase) {
|
fun enable(phase: AnyNamedPhase) {
|
||||||
enabledMut.add(phase)
|
enabledMut.add(phase)
|
||||||
}
|
}
|
||||||
@@ -82,6 +95,7 @@ class PhaseConfig(private val compoundPhase: CompilerPhase<*, *, *>, config: Com
|
|||||||
fun disable(phase: AnyNamedPhase) {
|
fun disable(phase: AnyNamedPhase) {
|
||||||
enabledMut.remove(phase)
|
enabledMut.remove(phase)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun switch(phase: AnyNamedPhase, onOff: Boolean) {
|
fun switch(phase: AnyNamedPhase, onOff: Boolean) {
|
||||||
if (onOff) {
|
if (onOff) {
|
||||||
enable(phase)
|
enable(phase)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.common.descriptors.KnownPackageFragmentDescr
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||||
|
import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig
|
||||||
import org.jetbrains.kotlin.backend.js.JsDeclarationFactory
|
import org.jetbrains.kotlin.backend.js.JsDeclarationFactory
|
||||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
@@ -49,7 +50,7 @@ class JsIrBackendContext(
|
|||||||
|
|
||||||
override val builtIns = module.builtIns
|
override val builtIns = module.builtIns
|
||||||
|
|
||||||
val phaseConfig = PhaseConfig(jsPhases, configuration)
|
val phaseConfig = createPhaseConfig(jsPhases, configuration)
|
||||||
override var inVerbosePhase: Boolean = false
|
override var inVerbosePhase: Boolean = false
|
||||||
|
|
||||||
val externalNestedClasses = mutableListOf<IrClass>()
|
val externalNestedClasses = mutableListOf<IrClass>()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||||
|
import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig
|
||||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
||||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
@@ -38,7 +39,7 @@ class JvmBackendContext(
|
|||||||
|
|
||||||
override val ir = JvmIr(irModuleFragment, symbolTable)
|
override val ir = JvmIr(irModuleFragment, symbolTable)
|
||||||
|
|
||||||
val phaseConfig = PhaseConfig(jvmPhases, state.configuration)
|
val phaseConfig = createPhaseConfig(jvmPhases, state.configuration)
|
||||||
override var inVerbosePhase: Boolean = false
|
override var inVerbosePhase: Boolean = false
|
||||||
|
|
||||||
override val configuration get() = state.configuration
|
override val configuration get() = state.configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user