KT-64385 Enable K2 KAPT by default

Also adds support for front-end compiler plugins in Kapt
This commit is contained in:
strangepleasures
2024-01-15 10:22:32 +00:00
committed by Space Team
parent 8156c91c47
commit 7e9d6e601d
58 changed files with 218 additions and 476 deletions
@@ -78,7 +78,6 @@ fun copyK2JVMCompilerArguments(from: K2JVMCompilerArguments, to: K2JVMCompilerAr
to.typeEnhancementImprovementsInStrictMode = from.typeEnhancementImprovementsInStrictMode
to.useFastJarFileSystem = from.useFastJarFileSystem
to.useJavac = from.useJavac
to.useKapt4 = from.useKapt4
to.useOldBackend = from.useOldBackend
to.useOldClassFilesReading = from.useOldClassFilesReading
to.useOldInlineClassesManglingScheme = from.useOldInlineClassesManglingScheme
@@ -845,16 +845,6 @@ This option is deprecated and will be deleted in future versions."""
field = value
}
@Argument(
value = "-Xuse-kapt4",
description = "Enable the experimental KAPT 4."
)
var useKapt4 = false
set(value) {
checkFrozen()
field = value
}
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
val result = super.configureAnalysisFlags(collector, languageVersion)
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.cli.common
import com.intellij.ide.highlighter.JavaFileType
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.ManualLanguageFeatureSetting
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@@ -48,7 +47,6 @@ fun CompilerConfiguration.setupCommonArguments(
}
}
switchToFallbackModeIfNecessary(arguments, messageCollector)
setupLanguageVersionSettings(arguments)
val usesK2 = arguments.useK2 || languageVersionSettings.languageVersion.usesK2
@@ -57,34 +55,6 @@ fun CompilerConfiguration.setupCommonArguments(
buildHmppModuleStructure(arguments)?.let { put(CommonConfigurationKeys.HMPP_MODULE_STRUCTURE, it) }
}
private fun switchToFallbackModeIfNecessary(arguments: CommonCompilerArguments, messageCollector: MessageCollector) {
fun warn(message: String) {
if (!arguments.suppressVersionWarnings) messageCollector.report(CompilerMessageSeverity.STRONG_WARNING, message)
}
if (arguments !is K2JVMCompilerArguments) return
val isK2 =
arguments.useK2 || (arguments.languageVersion?.startsWith('2') ?: (LanguageVersion.LATEST_STABLE >= LanguageVersion.KOTLIN_2_0))
val isKaptUsed = arguments.pluginOptions?.any { it.startsWith("plugin:org.jetbrains.kotlin.kapt3") } == true
when {
isK2 && isKaptUsed && !arguments.useKapt4 -> {
warn("Kapt currently doesn't support language version 2.0+. Falling back to 1.9.")
arguments.languageVersion = LanguageVersion.KOTLIN_1_9.versionString
if (arguments.apiVersion?.startsWith("2") == true) {
arguments.apiVersion = ApiVersion.KOTLIN_1_9.versionString
}
arguments.useK2 = false
arguments.skipMetadataVersionCheck = true
arguments.skipPrereleaseCheck = true
arguments.allowUnstableDependencies = true
}
arguments.useKapt4 -> warn(
if (isK2) "K2 kapt is an experimental feature. Use with caution."
else "-Xuse-kapt4 flag can be only used with language version 2.0+."
)
}
}
fun CompilerConfiguration.setupLanguageVersionSettings(arguments: CommonCompilerArguments) {
languageVersionSettings = arguments.toLanguageVersionSettings(getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY))
}