Introduce language version 2.0 and associate K2 compiler with it
This commit is contained in:
@@ -31,8 +31,7 @@ import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
||||
import org.jetbrains.kotlin.cli.plugins.processCompilerPluginsOptions
|
||||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledException
|
||||
@@ -77,7 +76,7 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
|
||||
configuration.put(CLIConfigurationKeys.ORIGINAL_MESSAGE_COLLECTOR_KEY, messageCollector)
|
||||
|
||||
val collector = GroupingMessageCollector(messageCollector, arguments.allWarningsAsErrors).also {
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, it)
|
||||
configuration.put(MESSAGE_COLLECTOR_KEY, it)
|
||||
}
|
||||
|
||||
configuration.put(IrMessageLogger.IR_MESSAGE_LOGGER, IrMessageCollector(collector))
|
||||
@@ -88,7 +87,7 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
|
||||
setupPlatformSpecificArgumentsAndServices(configuration, arguments, services)
|
||||
val paths = computeKotlinPaths(collector, arguments)
|
||||
if (collector.hasErrors()) {
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
|
||||
val canceledStatus = services[CompilationCanceledStatus::class.java]
|
||||
@@ -98,6 +97,36 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
|
||||
try {
|
||||
setIdeaIoUseFallback()
|
||||
|
||||
val useK2FromFlag = arguments.useK2
|
||||
val languageVersion = configuration.languageVersionSettings.languageVersion
|
||||
if (useK2FromFlag) {
|
||||
when {
|
||||
arguments.languageVersion == null -> {
|
||||
messageCollector.report(
|
||||
STRONG_WARNING,
|
||||
"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"
|
||||
)
|
||||
}
|
||||
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"
|
||||
)
|
||||
}
|
||||
}
|
||||
if (!languageVersion.usesK2) {
|
||||
val languageVersionSettings = configuration.languageVersionSettings
|
||||
configuration.languageVersionSettings = languageVersionSettings.copy(LanguageVersion.KOTLIN_2_0)
|
||||
arguments.checkLanguageVersionIsStable(LanguageVersion.KOTLIN_2_0, messageCollector)
|
||||
}
|
||||
}
|
||||
|
||||
val code = doExecute(arguments, configuration, rootDisposable, paths)
|
||||
|
||||
performanceManager.notifyCompilationFinished()
|
||||
@@ -115,12 +144,12 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
|
||||
return if (collector.hasErrors()) COMPILATION_ERROR else code
|
||||
} catch (e: CompilationCanceledException) {
|
||||
collector.reportCompilationCancelled(e)
|
||||
return ExitCode.OK
|
||||
return OK
|
||||
} catch (e: RuntimeException) {
|
||||
val cause = e.cause
|
||||
if (cause is CompilationCanceledException) {
|
||||
collector.reportCompilationCancelled(cause)
|
||||
return ExitCode.OK
|
||||
return OK
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ fun <A : CommonCompilerArguments> CompilerConfiguration.setupCommonArguments(
|
||||
createMetadataVersion: ((IntArray) -> BinaryVersion)? = null
|
||||
) {
|
||||
put(CommonConfigurationKeys.DISABLE_INLINE, arguments.noInline)
|
||||
put(CommonConfigurationKeys.USE_FIR, arguments.useK2)
|
||||
put(CommonConfigurationKeys.USE_LIGHT_TREE, arguments.useFirLT)
|
||||
put(CommonConfigurationKeys.USE_FIR_EXTENDED_CHECKERS, arguments.useFirExtendedCheckers)
|
||||
put(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER, arguments.expectActualLinker)
|
||||
putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot)
|
||||
@@ -45,6 +43,10 @@ fun <A : CommonCompilerArguments> CompilerConfiguration.setupCommonArguments(
|
||||
}
|
||||
|
||||
setupLanguageVersionSettings(arguments)
|
||||
|
||||
val usesK2 = arguments.useK2 || languageVersionSettings.languageVersion.usesK2
|
||||
put(CommonConfigurationKeys.USE_FIR, usesK2)
|
||||
put(CommonConfigurationKeys.USE_LIGHT_TREE, usesK2)
|
||||
}
|
||||
|
||||
fun <A : CommonCompilerArguments> CompilerConfiguration.setupLanguageVersionSettings(arguments: A) {
|
||||
|
||||
+2
-7
@@ -75,11 +75,6 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
): Boolean {
|
||||
val performanceManager = projectConfiguration.get(CLIConfigurationKeys.PERF_MANAGER)
|
||||
|
||||
messageCollector.report(
|
||||
STRONG_WARNING,
|
||||
"ATTENTION!\n This build uses experimental K2 compiler: \n -Xuse-k2"
|
||||
)
|
||||
|
||||
val notSupportedPlugins = mutableListOf<String?>().apply {
|
||||
projectConfiguration.get(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS).collectIncompatiblePluginNamesTo(this, ComponentRegistrar::supportsK2)
|
||||
projectConfiguration.get(CompilerPluginRegistrar.COMPILER_PLUGIN_REGISTRARS).collectIncompatiblePluginNamesTo(this, CompilerPluginRegistrar::supportsK2)
|
||||
@@ -89,9 +84,9 @@ object FirKotlinToJvmBytecodeCompiler {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
"""
|
||||
|There are some plugins incompatible with K2 compiler:
|
||||
|There are some plugins incompatible with language version 2.0:
|
||||
|${notSupportedPlugins.joinToString(separator = "\n|") { " $it" }}
|
||||
|Please remove -Xuse-k2
|
||||
|Please use language version 1.* (e.g. 1.9)
|
||||
""".trimMargin()
|
||||
)
|
||||
return false
|
||||
|
||||
@@ -99,11 +99,6 @@ fun compileModulesUsingFrontendIrAndLightTree(
|
||||
|
||||
performanceManager?.notifyCompilerInitialized(0, 0, targetDescription)
|
||||
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
"ATTENTION!\n This build uses experimental K2 compiler: \n -Xuse-k2"
|
||||
)
|
||||
|
||||
val outputs = mutableListOf<GenerationState>()
|
||||
var mainClassFqName: FqName? = null
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
||||
|
||||
// TODO: ignore previous configuration value when we do not need old backend in scripting by default
|
||||
val useOldBackend = arguments.useOldBackend || (!arguments.useIR && get(JVMConfigurationKeys.IR) == false)
|
||||
val useIR = arguments.useK2 ||
|
||||
val useIR = arguments.useK2 || languageVersionSettings.languageVersion.usesK2 ||
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.JvmIrEnabledByDefault)) {
|
||||
!useOldBackend
|
||||
} else {
|
||||
|
||||
@@ -59,7 +59,7 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
|
||||
): ExitCode {
|
||||
val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) {
|
||||
collector.report(ERROR, "K2 does not support compilation to metadata right now")
|
||||
collector.report(ERROR, "Compilation to metadata is not supported in language version 2.0 right now")
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
val performanceManager = configuration.getNotNull(CLIConfigurationKeys.PERF_MANAGER)
|
||||
|
||||
Reference in New Issue
Block a user