From ba9baa7457d4ab26984fea58127e3b9398d6588f Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 18 Oct 2023 10:51:44 +0300 Subject: [PATCH] [FIR] Don't enable features without `sinceKotlin` in Progressive Mode There are two BUG_FIX features that have been added to the compiler, without a clear decision to enable them somewhere in the future. Since there is no decision to force users rewrite their code, such features should not be enabled in Progressive Mode. ^KT-62644 Fixed ^KT-62143 Fixed --- .../common/arguments/CommonCompilerArguments.kt | 2 +- .../kotlin/config/LanguageVersionSettings.kt | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 17887a85db7..bf00e031570 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -883,7 +883,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { } if (progressiveMode) { - LanguageFeature.values().filter { it.kind.enabledInProgressiveMode }.forEach { + LanguageFeature.entries.filter { it.enabledInProgressiveMode }.forEach { // Don't overwrite other settings: users may want to turn off some particular // breaking change manually instead of turning off whole progressive mode if (!contains(it)) put(it, LanguageFeature.State.ENABLED) diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 72a689bed68..2f6ea47635d 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -392,6 +392,13 @@ enum class LanguageFeature( DISABLED("Disabled"); } + /** + * If 'true', then this feature will be automatically enabled under '-progressive' mode. + * + * Please, see `canBeEnabledInProgressiveMode` in [Kind] for more details. + */ + val enabledInProgressiveMode: Boolean get() = kind.canBeEnabledInProgressiveMode && sinceVersion != null + /** * # [forcesPreReleaseBinaries] * If 'true', then enabling this feature (e.g. by '-XXLanguage:', or dedicated '-X'-flag) @@ -404,8 +411,8 @@ enum class LanguageFeature( * generate 'kotlin-compiler' as pre-release. * * - * # [enabledInProgressiveMode] - * If 'true', then this feature will be automatically enabled under '-progressive' mode. + * # [canBeEnabledInProgressiveMode] + * If 'true', then this feature will be automatically enabled under '-progressive' mode if `sinceKotlin` is set. * * Restrictions for using this flag for particular feature follow from restrictions of the progressive mode: * - enabling it *must not* break compatibility with non-progressive compiler, i.e. code written under progressive @@ -418,9 +425,9 @@ enum class LanguageFeature( * Example: silently changing semantics of generated low-level code is not fine, but deprecating some language * construction immediately instead of a going through complete deprecation cycle is fine. * - * NB: Currently, [enabledInProgressiveMode] makes sense only for features with [sinceVersion] > [LanguageVersion.LATEST_STABLE] + * NB: Currently, [canBeEnabledInProgressiveMode] makes sense only for features with [sinceVersion] > [LanguageVersion.LATEST_STABLE] */ - enum class Kind(val enabledInProgressiveMode: Boolean, val forcesPreReleaseBinaries: Boolean) { + enum class Kind(val canBeEnabledInProgressiveMode: Boolean, val forcesPreReleaseBinaries: Boolean) { /** * Simple bug fix which just forbids some language constructions. * Rule of thumb: it turns "green code" into "red".