From 8b576750025f1fc5f80ef2a2f508f28add138fe5 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 10 Jan 2022 13:46:03 +0100 Subject: [PATCH] Revert "Remove obsolete check for language version and IR backends" This check is no longer obsolete since language version 1.3 support is restored for Kotlin/JVM, but JS and Native never supported LV 1.3. This is a partial revert of 0213c25c9b67ee6aed4ac71f9c682c168c99fd33, without the diagnostic in K2JVMCompilerArguments (which is not needed since the earliest supported LV is 1.3). #KT-50695 Fixed --- .../arguments/CommonCompilerArguments.kt | 6 ++++++ .../common/arguments/K2JSCompilerArguments.kt | 18 +++++++++++++++--- .../kotlin/cli/bc/K2NativeCompilerArguments.kt | 11 +++++++++++ 3 files changed, 32 insertions(+), 3 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 2fdb52565a6..7589ee27dd8 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 @@ -574,6 +574,8 @@ abstract class CommonCompilerArguments : CommonToolArguments() { checkLanguageVersionIsStable(languageVersion, collector) checkOutdatedVersions(languageVersion, apiVersion, collector) checkProgressiveMode(languageVersion, collector) + + checkIrSupport(languageVersionSettings, collector) } checkPlatformSpecificSettings(languageVersionSettings, collector) @@ -652,6 +654,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() { protected open fun checkPlatformSpecificSettings(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { } + protected open fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + // backend-specific + } + private enum class VersionKind(val text: String) { LANGUAGE("Language"), API("API") } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index d8d0ca6fe1f..0c4f47b2c01 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -6,11 +6,10 @@ package org.jetbrains.kotlin.cli.common.arguments import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.* +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.config.AnalysisFlag +import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.AnalysisFlags.allowFullyQualifiedNameInKClass -import org.jetbrains.kotlin.config.LanguageFeature -import org.jetbrains.kotlin.config.LanguageVersion class K2JSCompilerArguments : CommonCompilerArguments() { companion object { @@ -257,6 +256,19 @@ class K2JSCompilerArguments : CommonCompilerArguments() { } } + override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + if (!isIrBackendEnabled()) return + + if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_4 + || languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_4 + ) { + collector.report( + CompilerMessageSeverity.ERROR, + "IR backend cannot be used with language or API version below 1.4" + ) + } + } + override fun configureLanguageFeatures(collector: MessageCollector): MutableMap { return super.configureLanguageFeatures(collector).apply { if (extensionFunctionsInExternals) { diff --git a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index 2010cff7723..15458940189 100644 --- a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -371,6 +371,17 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { if (printIr) phasesToDumpAfter = arrayOf("ALL") } + + override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_4 + || languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_4 + ) { + collector.report( + severity = CompilerMessageSeverity.ERROR, + message = "Native backend cannot be used with language or API version below 1.4" + ) + } + } } const val EMBED_BITCODE_FLAG = "-Xembed-bitcode"