From 06182fe5471ebd200663b1ec6f1766036d28bcdf Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Mon, 3 Oct 2022 12:01:12 +0300 Subject: [PATCH] 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. --- .../backend/common/phaser/PhaseConfig.kt | 32 ++++++-- .../phaser/PhaseConfigurationService.kt | 79 +++++++++++++++++++ 2 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfigurationService.kt diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt index 71e16d4361e..f17373b6296 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt @@ -42,15 +42,15 @@ class PhaseConfig( val verbose: Set = emptySet(), val toDumpStateBefore: Set = emptySet(), val toDumpStateAfter: Set = emptySet(), - val dumpToDirectory: String? = null, - val dumpOnlyFqName: String? = null, + override val dumpToDirectory: String? = null, + override val dumpOnlyFqName: String? = null, val toValidateStateBefore: Set = emptySet(), val toValidateStateAfter: Set = emptySet(), val namesOfElementsExcludedFromDumping: Set = 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 get() = enabledMut @@ -90,7 +108,7 @@ class PhaseConfig( enabledMut.add(phase) } - fun disable(phase: AnyNamedPhase) { + override fun disable(phase: AnyNamedPhase) { enabledMut.remove(phase) } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfigurationService.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfigurationService.kt new file mode 100644 index 00000000000..146d1c602c2 --- /dev/null +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfigurationService.kt @@ -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? +} \ No newline at end of file