From 7a61578e083751a8d0fe5936d103c89d056df417 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 9 Jan 2023 11:51:48 +0100 Subject: [PATCH] Language version 2.0: fix compiler messages and minor details --- .../src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java | 8 ++++---- .../org/jetbrains/kotlin/cli/common/CLICompiler.kt | 11 ++++++----- .../jvm/compiler/FirKotlinToJvmBytecodeCompiler.kt | 2 +- .../kotlin/cli/metadata/K2MetadataCompiler.kt | 2 +- compiler/testData/cli/jvm/firHello.out | 2 +- compiler/testData/cli/jvm/firHello20WithFlag.out | 2 +- compiler/testData/cli/jvm/firHello20WithOldLV.out | 2 +- compiler/testData/cli/metadata/fir.out | 2 +- .../firAgainstFirUsingFlag/output.txt | 2 +- .../src/org/jetbrains/kotlin/cli/bc/K2Native.kt | 3 --- .../plugin/sources/DefaultLanguageSettingsBuilder.kt | 2 +- .../src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt | 2 +- 12 files changed, 19 insertions(+), 21 deletions(-) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java index aa1c7314f12..652c97ae9e8 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java @@ -175,15 +175,15 @@ public class K2JSCompiler extends CLICompiler { ExitCode exitCode = OK; - LanguageVersionSettings languageVersionSettings = CommonConfigurationKeysKt.getLanguageVersionSettings(configuration); - LanguageVersion languageVersion = languageVersionSettings.getLanguageVersion(); - if (K2JSCompilerArgumentsKt.isIrBackendEnabled(arguments) || languageVersion.getUsesK2()) { + boolean useFir = Boolean.TRUE.equals(configuration.get(CommonConfigurationKeys.USE_FIR)); + if (K2JSCompilerArgumentsKt.isIrBackendEnabled(arguments) || useFir) { exitCode = getIrCompiler().doExecute(arguments, configuration.copy(), rootDisposable, paths); } - if (K2JSCompilerArgumentsKt.isPreIrBackendDisabled(arguments) || languageVersion.getUsesK2()) { + if (K2JSCompilerArgumentsKt.isPreIrBackendDisabled(arguments) || useFir) { return exitCode; } + LanguageVersionSettings languageVersionSettings = CommonConfigurationKeysKt.getLanguageVersionSettings(configuration); if (CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.getValue() != "true" && languageVersionSettings.getLanguageVersion().compareTo(LanguageVersion.KOTLIN_1_9) >= 0) { messageCollector.report(ERROR, "Old Kotlin/JS compiler is no longer supported. Please migrate to the new JS IR backend", null); diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt index 112faf29c79..88da94786ca 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt @@ -104,19 +104,19 @@ abstract class CLICompiler : CLITool() { arguments.languageVersion == null -> { messageCollector.report( STRONG_WARNING, - "Compiler flag -Xuse-k2 is deprecated, please use -language-version 2.0 instead" + "Compiler flag -Xuse-k2 is deprecated, please use \"-language-version 2.0\" instead" ) } languageVersion.usesK2 -> { messageCollector.report( STRONG_WARNING, - "Compiler flag -Xuse-k2 is redundant" + "Compiler flag -Xuse-k2 is redundant, the \"-language-version 2.0\" is used instead" ) } else -> { messageCollector.report( STRONG_WARNING, - "With -Xuse-k2 compiler flag -language-version $languageVersion has no effect, please remove -Xuse-k2 flag or use -language-version 2.0 instead" + "With -Xuse-k2 compiler flag \"-language-version $languageVersion\" has no effect, please remove -Xuse-k2 flag and use \"-language-version 2.0\" instead" ) } } @@ -202,7 +202,8 @@ abstract class CLICompiler : CLITool() { val pluginConfigurations = arguments.pluginConfigurations.orEmpty().toMutableList() val messageCollector = configuration.getNotNull(MESSAGE_COLLECTOR_KEY) - if (!checkPluginsArguments(messageCollector, arguments.useK2, pluginClasspaths, pluginOptions, pluginConfigurations)) { + val useK2 = configuration.get(CommonConfigurationKeys.USE_FIR) == true + if (!checkPluginsArguments(messageCollector, useK2, pluginClasspaths, pluginOptions, pluginConfigurations)) { return INTERNAL_ERROR } @@ -274,7 +275,7 @@ fun checkPluginsArguments( hasErrors = true messageCollector.report( ERROR, - "-Xcompiler-plugin argument is allowed only for for K2 compiler. Please use -Xplugin argument or enable -Xuse-k2" + "-Xcompiler-plugin argument is allowed only for language version 2.0. Please use -Xplugin argument for language version 1.9 and below" ) } if (pluginClasspaths.isNotEmpty() || pluginOptions.isNotEmpty()) { diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/FirKotlinToJvmBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/FirKotlinToJvmBytecodeCompiler.kt index d325d38a6eb..646dcd32e96 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/FirKotlinToJvmBytecodeCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/FirKotlinToJvmBytecodeCompiler.kt @@ -86,7 +86,7 @@ object FirKotlinToJvmBytecodeCompiler { """ |There are some plugins incompatible with language version 2.0: |${notSupportedPlugins.joinToString(separator = "\n|") { " $it" }} - |Please use language version 1.* (e.g. 1.9) + |Please use language version 1.9 or below """.trimMargin() ) return false diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt index c3ce86f1ab6..d899a0c171b 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt @@ -59,7 +59,7 @@ class K2MetadataCompiler : CLICompiler() { ): ExitCode { val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) { - collector.report(ERROR, "Compilation to metadata is not supported in language version 2.0 right now") + collector.report(ERROR, "Compilation to metadata is not supported with language version 2.0 right now") return ExitCode.COMPILATION_ERROR } val performanceManager = configuration.getNotNull(CLIConfigurationKeys.PERF_MANAGER) diff --git a/compiler/testData/cli/jvm/firHello.out b/compiler/testData/cli/jvm/firHello.out index b9afd3e03f8..cc6ea4c496a 100644 --- a/compiler/testData/cli/jvm/firHello.out +++ b/compiler/testData/cli/jvm/firHello.out @@ -1,3 +1,3 @@ -warning: compiler flag -Xuse-k2 is deprecated, please use -language-version 2.0 instead +warning: compiler flag -Xuse-k2 is deprecated, please use "-language-version 2.0" instead warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features OK diff --git a/compiler/testData/cli/jvm/firHello20WithFlag.out b/compiler/testData/cli/jvm/firHello20WithFlag.out index 42f0672c715..b9be8766ccf 100644 --- a/compiler/testData/cli/jvm/firHello20WithFlag.out +++ b/compiler/testData/cli/jvm/firHello20WithFlag.out @@ -1,3 +1,3 @@ -warning: compiler flag -Xuse-k2 is redundant +warning: compiler flag -Xuse-k2 is redundant, the "-language-version 2.0" is used instead warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features OK diff --git a/compiler/testData/cli/jvm/firHello20WithOldLV.out b/compiler/testData/cli/jvm/firHello20WithOldLV.out index 9929407d72b..c58f921bef1 100644 --- a/compiler/testData/cli/jvm/firHello20WithOldLV.out +++ b/compiler/testData/cli/jvm/firHello20WithOldLV.out @@ -1,3 +1,3 @@ -warning: with -Xuse-k2 compiler flag -language-version 1.5 has no effect, please remove -Xuse-k2 flag or use -language-version 2.0 instead +warning: with -Xuse-k2 compiler flag "-language-version 1.5" has no effect, please remove -Xuse-k2 flag and use "-language-version 2.0" instead warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features OK diff --git a/compiler/testData/cli/metadata/fir.out b/compiler/testData/cli/metadata/fir.out index fe413a1beb5..4cb9b6a0e99 100644 --- a/compiler/testData/cli/metadata/fir.out +++ b/compiler/testData/cli/metadata/fir.out @@ -1,3 +1,3 @@ warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features -error: compilation to metadata is not supported in language version 2.0 right now +error: compilation to metadata is not supported with language version 2.0 right now COMPILATION_ERROR diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/firAgainstFirUsingFlag/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/firAgainstFirUsingFlag/output.txt index 63445d07c89..01275a94aad 100644 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/firAgainstFirUsingFlag/output.txt +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/firAgainstFirUsingFlag/output.txt @@ -1,2 +1,2 @@ -warning: compiler flag -Xuse-k2 is deprecated, please use -language-version 2.0 instead +warning: compiler flag -Xuse-k2 is deprecated, please use "-language-version 2.0" instead OK diff --git a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index e0e545b2e30..59ccc662032 100644 --- a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -58,9 +58,6 @@ class K2Native : CLICompiler() { if (pluginLoadResult != ExitCode.OK) return pluginLoadResult val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) ?: MessageCollector.NONE - if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) { - messageCollector.report(WARNING, "New compiler pipeline K2 is experimental in Kotlin/Native. No compatibility guarantees are yet provided") - } val enoughArguments = arguments.freeArgs.isNotEmpty() || arguments.isUsefulWithoutFreeArgs if (!enoughArguments) { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/DefaultLanguageSettingsBuilder.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/DefaultLanguageSettingsBuilder.kt index cb0a6a5b732..90d6feba6e4 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/DefaultLanguageSettingsBuilder.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/DefaultLanguageSettingsBuilder.kt @@ -146,7 +146,7 @@ private val apiVersionValues = ApiVersion.run { KOTLIN_1_7, KOTLIN_1_8, KOTLIN_1_9, - KOTLIN_2_0 + KOTLIN_2_0, ) } diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt index 50d1be27ac3..b78fc3638fa 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt @@ -71,7 +71,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor { if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) { configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]?.report( CompilerMessageSeverity.ERROR, - "kapt currently doesn't support language version 2.0\nPlease use language version 1.* (e.g. 1.9) instead" + "kapt currently doesn't support language version 2.0\nPlease use language version 1.9 or below" ) }