Introduce abstraction layer atop of PhaseConfig.
PhaseConfig is tied to some root `compoundPhase` that defines the whole compilation pipeline. To lift this restriction and allow dynamically-defined compilation pipelines, let's move parts of PhaseConfig interface that do not depend on `compoundPhase` to an interface.
This commit is contained in:
committed by
Space Team
parent
7b2c125754
commit
06182fe547
+25
-7
@@ -42,15 +42,15 @@ class PhaseConfig(
|
||||
val verbose: Set<AnyNamedPhase> = emptySet(),
|
||||
val toDumpStateBefore: Set<AnyNamedPhase> = emptySet(),
|
||||
val toDumpStateAfter: Set<AnyNamedPhase> = emptySet(),
|
||||
val dumpToDirectory: String? = null,
|
||||
val dumpOnlyFqName: String? = null,
|
||||
override val dumpToDirectory: String? = null,
|
||||
override val dumpOnlyFqName: String? = null,
|
||||
val toValidateStateBefore: Set<AnyNamedPhase> = emptySet(),
|
||||
val toValidateStateAfter: Set<AnyNamedPhase> = emptySet(),
|
||||
val namesOfElementsExcludedFromDumping: Set<String> = emptySet(),
|
||||
val needProfiling: Boolean = false,
|
||||
val checkConditions: Boolean = false,
|
||||
val checkStickyConditions: Boolean = false
|
||||
) {
|
||||
override val needProfiling: Boolean = false,
|
||||
override val checkConditions: Boolean = false,
|
||||
override val checkStickyConditions: Boolean = false
|
||||
) : PhaseConfigurationService {
|
||||
fun toBuilder() = PhaseConfigBuilder(compoundPhase).also {
|
||||
it.enabled.addAll(initiallyEnabled)
|
||||
it.verbose.addAll(verbose)
|
||||
@@ -66,6 +66,24 @@ class PhaseConfig(
|
||||
it.checkStickyConditions = checkStickyConditions
|
||||
}
|
||||
|
||||
override fun isEnabled(phase: AnyNamedPhase): Boolean =
|
||||
phase in enabled
|
||||
|
||||
override fun isVerbose(phase: AnyNamedPhase): Boolean =
|
||||
phase in verbose
|
||||
|
||||
override fun shouldDumpStateBefore(phase: AnyNamedPhase): Boolean =
|
||||
phase in toDumpStateBefore
|
||||
|
||||
override fun shouldDumpStateAfter(phase: AnyNamedPhase): Boolean =
|
||||
phase in toDumpStateAfter
|
||||
|
||||
override fun shouldValidateStateBefore(phase: AnyNamedPhase): Boolean =
|
||||
phase in toValidateStateBefore
|
||||
|
||||
override fun shouldValidateStateAfter(phase: AnyNamedPhase): Boolean =
|
||||
phase in toValidateStateAfter
|
||||
|
||||
private val enabledMut = initiallyEnabled.toMutableSet()
|
||||
|
||||
val enabled: Set<AnyNamedPhase> get() = enabledMut
|
||||
@@ -90,7 +108,7 @@ class PhaseConfig(
|
||||
enabledMut.add(phase)
|
||||
}
|
||||
|
||||
fun disable(phase: AnyNamedPhase) {
|
||||
override fun disable(phase: AnyNamedPhase) {
|
||||
enabledMut.remove(phase)
|
||||
}
|
||||
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.phaser
|
||||
|
||||
/**
|
||||
* Control which parts of compilation pipeline are enabled and
|
||||
* how compiler should validate their invariants.
|
||||
*/
|
||||
interface PhaseConfigurationService {
|
||||
/**
|
||||
* Check if the given [phase] should be executed during compilation.
|
||||
*/
|
||||
fun isEnabled(phase: AnyNamedPhase): Boolean
|
||||
|
||||
/**
|
||||
* Check if the compiler should print additional information
|
||||
* during [phase] execution.
|
||||
*/
|
||||
fun isVerbose(phase: AnyNamedPhase): Boolean
|
||||
|
||||
/**
|
||||
* Prevent compiler from executing the given [phase].
|
||||
*/
|
||||
fun disable(phase: AnyNamedPhase)
|
||||
|
||||
/**
|
||||
* Check if compiler should dump its state right before
|
||||
* the execution of the given [phase].
|
||||
*/
|
||||
fun shouldDumpStateBefore(phase: AnyNamedPhase): Boolean
|
||||
|
||||
/**
|
||||
* Check if compiler should dump its state right after
|
||||
* the execution of the given [phase].
|
||||
*/
|
||||
fun shouldDumpStateAfter(phase: AnyNamedPhase): Boolean
|
||||
|
||||
/**
|
||||
* Check if compiler should validate its state right before
|
||||
* the execution of the given [phase].
|
||||
*/
|
||||
fun shouldValidateStateBefore(phase: AnyNamedPhase): Boolean
|
||||
|
||||
/**
|
||||
* Check if compiler should validate its state right after
|
||||
* the execution of the given [phase].
|
||||
*/
|
||||
fun shouldValidateStateAfter(phase: AnyNamedPhase): Boolean
|
||||
|
||||
/**
|
||||
* Returns true if compiler should measure how long takes each phase.
|
||||
*/
|
||||
val needProfiling: Boolean
|
||||
|
||||
/**
|
||||
* Returns true if compiler should check pre- and post-conditions of compiler phases.
|
||||
*/
|
||||
val checkConditions: Boolean
|
||||
|
||||
/**
|
||||
* Returns true if compiler should check post-conditions that are applicable to subsequent (thus "sticky") phases.
|
||||
*/
|
||||
val checkStickyConditions: Boolean
|
||||
|
||||
/**
|
||||
* Returns a path to a directory that should store phase dump.
|
||||
* null if directory is not set.
|
||||
*/
|
||||
val dumpToDirectory: String?
|
||||
|
||||
/**
|
||||
* Returns a fully-qualified name that should be used to filter phase dump.
|
||||
* null if dump should not be filtered.
|
||||
*/
|
||||
val dumpOnlyFqName: String?
|
||||
}
|
||||
Reference in New Issue
Block a user