Introduce language version 2.0 and associate K2 compiler with it

This commit is contained in:
Mikhail Glukhikh
2022-11-28 18:20:10 +01:00
parent afe1150aec
commit 3dc05f4ec5
84 changed files with 233 additions and 151 deletions
@@ -453,6 +453,7 @@ class GenerationState private constructor(
this[KOTLIN_1_7] = JvmMetadataVersion(1, 7, 0)
this[KOTLIN_1_8] = JvmMetadataVersion.INSTANCE
this[KOTLIN_1_9] = JvmMetadataVersion(1, 9, 0)
this[KOTLIN_2_0] = JvmMetadataVersion(2, 0, 0)
check(size == LanguageVersion.values().size) {
"Please add mappings from the missing LanguageVersion instances to the corresponding JvmMetadataVersion " +
@@ -643,7 +643,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
}
}
private fun checkLanguageVersionIsStable(languageVersion: LanguageVersion, collector: MessageCollector) {
fun checkLanguageVersionIsStable(languageVersion: LanguageVersion, collector: MessageCollector) {
if (!languageVersion.isStable && !suppressVersionWarnings) {
collector.report(
CompilerMessageSeverity.STRONG_WARNING,
@@ -573,7 +573,7 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
result[JvmAnalysisFlags.sanitizeParentheses] = sanitizeParentheses
result[JvmAnalysisFlags.suppressMissingBuiltinsError] = suppressMissingBuiltinsError
result[JvmAnalysisFlags.enableJvmPreview] = enableJvmPreview
result[AnalysisFlags.allowUnstableDependencies] = allowUnstableDependencies || useK2
result[AnalysisFlags.allowUnstableDependencies] = allowUnstableDependencies || useK2 || languageVersion.usesK2
result[JvmAnalysisFlags.disableUltraLightClasses] = disableUltraLightClasses
result[JvmAnalysisFlags.useIR] = !useOldBackend
return result
@@ -175,14 +175,15 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
ExitCode exitCode = OK;
if (K2JSCompilerArgumentsKt.isIrBackendEnabled(arguments)) {
LanguageVersionSettings languageVersionSettings = CommonConfigurationKeysKt.getLanguageVersionSettings(configuration);
LanguageVersion languageVersion = languageVersionSettings.getLanguageVersion();
if (K2JSCompilerArgumentsKt.isIrBackendEnabled(arguments) || languageVersion.getUsesK2()) {
exitCode = getIrCompiler().doExecute(arguments, configuration.copy(), rootDisposable, paths);
}
if (K2JSCompilerArgumentsKt.isPreIrBackendDisabled(arguments)) {
if (K2JSCompilerArgumentsKt.isPreIrBackendDisabled(arguments) || languageVersion.getUsesK2()) {
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);
@@ -287,11 +287,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
val outputKlibPath =
if (arguments.irProduceKlibFile) outputDir.resolve("$outputName.klib").normalize().absolutePath
else outputDirPath
if (arguments.useK2) {
messageCollector.report(
STRONG_WARNING,
"ATTENTION!\n This build uses experimental K2 compiler: \n -Xuse-k2"
)
if (configuration.get(CommonConfigurationKeys.USE_FIR) == true) {
sourceModule = processSourceModuleWithK2(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
} else {
sourceModule = processSourceModule(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
@@ -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) {
@@ -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)
@@ -108,6 +108,8 @@ object FirSessionFactoryHelper {
override fun <T> getFlag(flag: AnalysisFlag<T>): T = stub()
override fun copy(languageVersion: LanguageVersion): LanguageVersionSettings = this
override val apiVersion: ApiVersion
get() = stub()
override val languageVersion: LanguageVersion
+2 -1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/fir.kt
-Xuse-k2
-language-version
2.0
-ir-output-dir
$TEMP_DIR$
-ir-output-name
+1 -3
View File
@@ -1,4 +1,2 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
+1 -1
View File
@@ -1,3 +1,3 @@
error: unknown API version: 239.42
Supported API versions: 1.3 (deprecated), 1.4 (deprecated), 1.5, 1.6, 1.7, 1.8, 1.9 (experimental)
Supported API versions: 1.3 (deprecated), 1.4 (deprecated), 1.5, 1.6, 1.7, 1.8, 1.9 (experimental), 2.0 (experimental)
COMPILATION_ERROR
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/conflictingJvmDeclarations.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:2:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
fun `<get-x>`(): Int defined in Foo
fun getX(): Int defined in Foo
+2 -1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/conflictingProjection.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/conflictingProjection.kt:10:19: error: projection is conflicting with variance of the corresponding type parameter of Out<in kotlin/Int>. Remove the projection or replace it with '*'
fun a8(value: Out<in Int>) {}
^
+2 -1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/extendedCheckers.kt
-Xuse-k2
-language-version
2.0
-Xuse-fir-extended-checkers
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/extendedCheckers.kt:2:12: warning: redundant explicit type
val i: Int = 1
^
+2 -1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/extendedCheckersNoWarning.kt
-Xuse-k2
-language-version
2.0
-Xuse-fir-extended-checkers
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,4 +1,2 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
+2 -1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/firDeprecationJava.kt
$TESTDATA_DIR$/firDeprecationJava
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/firDeprecationJava.kt:3:12: warning: '@Deprecated(...) fun stop(): Unit
' is deprecated. Deprecated in Java
thread.stop()
+2 -1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/firDfa.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+4 -3
View File
@@ -1,4 +1,5 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/firDfa.kt:3:10: warning: unnecessary non-null assertion (!!) on a non-null receiver of type kotlin/String
x!!.length
^
OK
+2 -1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/firError.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/firError.kt:1:13: error: 'val' on function parameter is not allowed
fun println(val x: Int) {}
^
+2 -3
View File
@@ -1,4 +1,3 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
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
+5
View File
@@ -0,0 +1,5 @@
$TESTDATA_DIR$/firHello20.kt
-language-version
2.0
-d
$TEMP_DIR$
+1
View File
@@ -0,0 +1 @@
fun main() {}
+2
View File
@@ -0,0 +1,2 @@
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
+6
View File
@@ -0,0 +1,6 @@
$TESTDATA_DIR$/firHello20.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+3
View File
@@ -0,0 +1,3 @@
warning: compiler flag -Xuse-k2 is redundant
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
+6
View File
@@ -0,0 +1,6 @@
$TESTDATA_DIR$/firHello20.kt
-Xuse-k2
-language-version
1.5
-d
$TEMP_DIR$
+3
View File
@@ -0,0 +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: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
@@ -2,7 +2,8 @@ $TESTDATA_DIR$/firMultiplatformCompilationWithError/common.kt
$TESTDATA_DIR$/firMultiplatformCompilationWithError/jvm.kt
-Xcommon-sources
$TESTDATA_DIR$/firMultiplatformCompilationWithError/common.kt
-Xuse-k2
-language-version
2.0
-cp
.
-d
@@ -8,9 +8,7 @@ This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/firMultiplatformCompilationWithError/jvm.kt:1:18: error: actual class 'actual interface A : Any' has no corresponding members for expected class members:
expect fun foo(): Unit
@@ -8,7 +8,6 @@ This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
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
@@ -2,7 +2,8 @@ $TESTDATA_DIR$/firMultiplatformCompilationWithoutErrors/common.kt
$TESTDATA_DIR$/firMultiplatformCompilationWithoutErrors/jvm.kt
-Xcommon-sources
$TESTDATA_DIR$/firMultiplatformCompilationWithoutErrors/common.kt
-Xuse-k2
-language-version
2.0
-cp
.
-d
@@ -8,7 +8,5 @@ This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
+2 -1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/firStdlibDependency.kt
-Xuse-k2
-language-version
2.0
-cp
.
-d
+1 -3
View File
@@ -1,4 +1,2 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
+2 -1
View File
@@ -1,6 +1,7 @@
$TESTDATA_DIR$/firVsClassicAnnotation.kt
-classpath
$TESTDATA_DIR$/firVsClassicAnnotation
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,4 +1,2 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/inapplicableLateinitModifier.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/inapplicableLateinitModifier.kt:6:1: error: 'lateinit' modifier is not allowed on delegated properties
lateinit var kest by Delegate
^
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/instanceAccessBeforeSuperCall.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:2:26: error: unresolved reference: getSomeInt
constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {}
^
+1 -1
View File
@@ -1,3 +1,3 @@
error: unknown language version: 239.42
Supported language versions: 1.3 (deprecated), 1.4 (deprecated), 1.5, 1.6, 1.7, 1.8, 1.9 (experimental)
Supported language versions: 1.3 (deprecated), 1.4 (deprecated), 1.5, 1.6, 1.7, 1.8, 1.9 (experimental), 2.0 (experimental)
COMPILATION_ERROR
+2 -1
View File
@@ -2,5 +2,6 @@ $TESTDATA_DIR$/optInEmptyMessageFir.kt
-d
$TEMP_DIR$
-opt-in=kotlin.RequiresOptIn
-Xuse-k2
-language-version
2.0
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/optInEmptyMessageFir.kt:8:5: error: this declaration needs opt-in. Its usage must be marked with '@EmptyMarker' or '@OptIn(EmptyMarker::class)'
foo()
^
+2 -1
View File
@@ -2,4 +2,5 @@ $TESTDATA_DIR$/optInOverrideMessageFir.kt
-d
$TEMP_DIR$
-opt-in=kotlin.RequiresOptIn
-Xuse-k2
-language-version
2.0
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/optInOverrideMessageFir.kt:16:18: error: base declaration of supertype 'Base' needs opt-in. This API is experimental and can change at any time, please use with care. The declaration override must be annotated with '@Marker' or '@OptIn(Marker::class)'
override fun foo() {}
^
@@ -1,5 +1,6 @@
-d
$TEMP_DIR$
-Xuse-k2
-language-version
2.0
-Xcompiler-plugin=dist/kotlinc/lib/allopen-compiler-plugin.jar=annotation=foo.AllOpen
$TESTDATA_DIR$/firAllOpenPlugin.kt
@@ -1,5 +1,3 @@
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
warning: argument -Xcompiler-plugin is experimental
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
OK
@@ -1,8 +1,8 @@
-d
$TEMP_DIR$
-Xcompiler-plugin=dist/kotlinc/lib/noarg-compiler-plugin.jar=annotation=foo.NoArg
-Xuse-k2
-language-version
2.0
-Xplugin=dist/kotlinc/lib/allopen-compiler-plugin.jar
-P
plugin\:org.jetbrains.kotlin.allopen\:annotation=foo.AllOpen
@@ -1,3 +1,4 @@
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: mixing legacy and modern plugin arguments is prohibited. Please use only one syntax
Legacy arguments:
-Xplugin=dist/kotlinc/lib/allopen-compiler-plugin.jar
@@ -1,5 +1,6 @@
-d
$TEMP_DIR$
-Xuse-k2
-language-version
2.0
-Xcompiler-plugin=dist/kotlinc/lib/allopen-compiler-plugin.jar=annotation=foo.AllOpen1,annotation=foo.AllOpen2
$TESTDATA_DIR$/multipleOptionsForOnePlugin.kt
@@ -1,5 +1,3 @@
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
warning: argument -Xcompiler-plugin is experimental
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
OK
+2 -1
View File
@@ -1,6 +1,7 @@
-d
$TEMP_DIR$
-Xuse-k2
-language-version
2.0
-Xcompiler-plugin=dist/kotlinc/lib/allopen-compiler-plugin.jar=annotation=foo.AllOpen
-Xcompiler-plugin=dist/kotlinc/lib/noarg-compiler-plugin.jar=annotation=foo.NoArg
$TESTDATA_DIR$/multiplePlugins.kt
+1 -3
View File
@@ -1,6 +1,4 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/plugins/multiplePlugins.kt:11:17: error:
inner class Inner(val s: String)
^
@@ -1,5 +1,6 @@
-d
$TEMP_DIR$
-Xuse-k2
-language-version
2.0
-Xcompiler-plugin=dist/kotlinc/lib/allopen-compiler-plugin.jar,dist/kotlinc/lib/noarg-compiler-plugin.jar=annotation=foo.AllOpen
$TESTDATA_DIR$/multiplePluginsInSameArg.kt
@@ -1,3 +1,4 @@
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: multiple plugins found in given classpath: org.jetbrains.kotlin.allopen.AllOpenComponentRegistrar, org.jetbrains.kotlin.noarg.NoArgComponentRegistrar
Plugin configuration is: dist/kotlinc/lib/allopen-compiler-plugin.jar,dist/kotlinc/lib/noarg-compiler-plugin.jar=annotation=foo.AllOpen
COMPILATION_ERROR
+2 -1
View File
@@ -1,5 +1,6 @@
-d
$TEMP_DIR$
-Xuse-k2
-language-version
2.0
-Xcompiler-plugin=dist/kotlinc/lib/kotlin-reflect.jar
$TESTDATA_DIR$/noPluginInClasspath.kt
@@ -1,2 +1,3 @@
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: no plugins found in given classpath: dist/kotlinc/lib/kotlin-reflect.jar
COMPILATION_ERROR
+2 -1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/fir.kt
-Xuse-k2
-language-version
2.0
-d
$TEMP_DIR$
+2 -1
View File
@@ -1,2 +1,3 @@
error: k2 does not support compilation to metadata right now
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
COMPILATION_ERROR
@@ -1,8 +1,10 @@
error: classes compiled by the new Kotlin compiler frontend were found in dependencies. Remove them from the classpath or use '-Xallow-unstable-dependencies' to suppress errors
compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:5: error: class 'lib.AKt' is compiled by the new Kotlin compiler frontend and cannot be loaded by the old compiler
error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
$TMP_DIR$/library.jar!/META-INF/main.kotlin_module: error: module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.0.0, expected version is $ABI_VERSION$.
compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:5: error: unresolved reference: get
get { Box("OK").value }
^
compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:11: error: class 'lib.Box' is compiled by the new Kotlin compiler frontend and cannot be loaded by the old compiler
compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:11: error: class 'lib.Box' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.0.0, expected version is $ABI_VERSION$.
The class is loaded from $TMP_DIR$/library.jar!/lib/Box.class
get { Box("OK").value }
^
COMPILATION_ERROR
@@ -26,19 +26,23 @@ const val SANITIZE_PARENTHESES = "SANITIZE_PARENTHESES"
const val ENABLE_JVM_PREVIEW = "ENABLE_JVM_PREVIEW"
data class CompilerTestLanguageVersionSettings(
private val initialLanguageFeatures: Map<LanguageFeature, LanguageFeature.State>,
override val apiVersion: ApiVersion,
override val languageVersion: LanguageVersion,
val analysisFlags: Map<AnalysisFlag<*>, Any?> = emptyMap()
private val initialLanguageFeatures: Map<LanguageFeature, LanguageFeature.State>,
override val apiVersion: ApiVersion,
override val languageVersion: LanguageVersion,
val analysisFlags: Map<AnalysisFlag<*>, Any?> = emptyMap()
) : LanguageVersionSettings {
val extraLanguageFeatures = specificFeaturesForTests() + initialLanguageFeatures
private val delegate = LanguageVersionSettingsImpl(languageVersion, apiVersion, emptyMap(), extraLanguageFeatures)
override fun getFeatureSupport(feature: LanguageFeature): LanguageFeature.State =
extraLanguageFeatures[feature] ?: delegate.getFeatureSupport(feature)
extraLanguageFeatures[feature] ?: delegate.getFeatureSupport(feature)
override fun isPreRelease(): Boolean = false
override fun copy(languageVersion: LanguageVersion): LanguageVersionSettings {
return CompilerTestLanguageVersionSettings(initialLanguageFeatures, apiVersion, languageVersion, analysisFlags)
}
@Suppress("UNCHECKED_CAST")
override fun <T> getFlag(flag: AnalysisFlag<T>): T = analysisFlags[flag] as T? ?: flag.defaultValue
}
@@ -138,7 +138,7 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() {
private fun String.removeFirWarning(): String {
return this.replace(
"warning: ATTENTION!\n This build uses experimental K2 compiler: \n -Xuse-k2\n", ""
"warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features\n", ""
)
}
@@ -447,6 +447,21 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/firHello.args");
}
@TestMetadata("firHello20.args")
public void testFirHello20() throws Exception {
runTest("compiler/testData/cli/jvm/firHello20.args");
}
@TestMetadata("firHello20WithFlag.args")
public void testFirHello20WithFlag() throws Exception {
runTest("compiler/testData/cli/jvm/firHello20WithFlag.args");
}
@TestMetadata("firHello20WithOldLV.args")
public void testFirHello20WithOldLV() throws Exception {
runTest("compiler/testData/cli/jvm/firHello20WithOldLV.args");
}
@TestMetadata("firMultiplatformCompilationWithError.args")
public void testFirMultiplatformCompilationWithError() throws Exception {
runTest("compiler/testData/cli/jvm/firMultiplatformCompilationWithError.args");
@@ -406,7 +406,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
// Starting from Kotlin 1.4, major.minor version of JVM metadata must be equal to the language version.
// From Kotlin 1.0 to 1.4, we used JVM metadata version 1.1.*.
val expectedMajor = 1
val expectedMajor = if (languageVersion.usesK2) 2 else 1
val expectedMinor = if (languageVersion < LanguageVersion.KOTLIN_1_4) 1 else languageVersion.minor
val topLevelClass = LocalFileKotlinClass.create(File(tmpdir.absolutePath, "Foo.class"))!!
@@ -563,7 +563,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
fun testInternalFromFriendModuleFir() {
val library = compileLibrary("library")
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xfriend-paths=${library.path}", "-Xuse-k2"))
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xfriend-paths=${library.path}", "-language-version", "2.0"))
}
fun testJvmDefaultClashWithOld() {
@@ -642,20 +642,20 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
}
fun testFirAgainstFir() {
val library = compileLibrary("library", additionalOptions = listOf("-Xuse-k2"))
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xuse-k2"))
val library = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0"))
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-language-version", "2.0"))
}
fun testFirAgainstOldJvm() {
val library = compileLibrary("library")
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xuse-k2"))
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-language-version", "2.0"))
}
fun testFirIncorrectJavaSignature() {
compileKotlin(
"source.kt", tmpdir,
listOf(),
additionalOptions = listOf("-Xuse-k2"),
additionalOptions = listOf("-language-version", "2.0"),
additionalSources = listOf("A.java", "B.java"),
)
}
@@ -664,7 +664,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
compileKotlin(
"source.kt", tmpdir,
listOf(),
additionalOptions = listOf("-Xuse-k2"),
additionalOptions = listOf("-language-version", "2.0"),
additionalSources = listOf("A.java", "B.java"),
)
}
@@ -678,10 +678,10 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
}
fun testOldJvmAgainstFir() {
val library = compileLibrary("library", additionalOptions = listOf("-Xuse-k2"))
val library = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0"))
compileKotlin("source.kt", tmpdir, listOf(library))
val library2 = compileLibrary("library", additionalOptions = listOf("-Xuse-k2", "-Xabi-stability=unstable"))
val library2 = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0", "-Xabi-stability=unstable"))
compileKotlin("source.kt", tmpdir, listOf(library2))
}
@@ -691,13 +691,13 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
}
fun testOldJvmAgainstFirWithStableAbi() {
val library = compileLibrary("library", additionalOptions = listOf("-Xuse-k2", "-Xabi-stability=stable"))
val library = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0", "-Xabi-stability=stable"))
compileKotlin("source.kt", tmpdir, listOf(library))
}
fun testOldJvmAgainstFirWithAllowUnstableDependencies() {
val library = compileLibrary("library", additionalOptions = listOf("-Xuse-k2"))
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xallow-unstable-dependencies"))
val library = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0"))
compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xallow-unstable-dependencies", "-Xskip-metadata-version-check"))
}
fun testSealedClassesAndInterfaces() {
@@ -63,6 +63,9 @@ class ApiVersion private constructor(
@JvmField
val KOTLIN_1_9 = createByLanguageVersion(LanguageVersion.KOTLIN_1_9)
@JvmField
val KOTLIN_2_0 = createByLanguageVersion(LanguageVersion.KOTLIN_2_0)
@JvmField
val LATEST: ApiVersion = createByLanguageVersion(LanguageVersion.values().last())
@@ -282,6 +282,11 @@ enum class LanguageFeature(
ValueClassesSecondaryConstructorWithBody(sinceVersion = KOTLIN_1_9, kind = UNSTABLE_FEATURE), // KT-55333
NativeJsProhibitLateinitIsInitalizedIntrinsicWithoutPrivateAccess(KOTLIN_1_9, kind = BUG_FIX), // KT-27002
// End of 1.* language features --------------------------------------------------
// 2.0
// End of 2.* language features --------------------------------------------------
// This feature effectively might be removed because we decided to disable it until K2 and there it will be unconditionally enabled.
// But we leave it here just to minimize the changes in K1 and also to allow use the feature once somebody needs it.
@@ -414,11 +419,16 @@ enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware, L
KOTLIN_1_7(1, 7),
KOTLIN_1_8(1, 8),
KOTLIN_1_9(1, 9),
KOTLIN_2_0(2, 0),
;
override val isStable: Boolean
get() = this <= LATEST_STABLE
val usesK2: Boolean
get() = this >= KOTLIN_2_0
override val isDeprecated: Boolean
get() = FIRST_SUPPORTED <= this && this < FIRST_NON_DEPRECATED
@@ -498,6 +508,8 @@ interface LanguageVersionSettings {
// Please do not use this to enable/disable specific features/checks. Instead add a new LanguageFeature entry and call supportsFeature
val languageVersion: LanguageVersion
fun copy(languageVersion: LanguageVersion): LanguageVersionSettings = this
companion object {
const val RESOURCE_NAME_TO_ALLOW_READING_FROM_ENVIRONMENT = "META-INF/allow-configuring-from-environment"
}
@@ -546,6 +558,9 @@ class LanguageVersionSettingsImpl @JvmOverloads constructor(
state == LanguageFeature.State.ENABLED && feature.forcesPreReleaseBinariesIfEnabled()
}
override fun copy(languageVersion: LanguageVersion): LanguageVersionSettings =
LanguageVersionSettingsImpl(languageVersion, apiVersion, analysisFlags, specificFeatures)
companion object {
@JvmField
val DEFAULT = LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE)
@@ -21,7 +21,11 @@ class JvmMetadataVersion(versionArray: IntArray, val isStrictSemantics: Boolean)
isCompatibleTo(INSTANCE)
} else {
// Kotlin 1.N is able to read metadata of versions up to Kotlin 1.{N+1} (unless the version has strict semantics).
major == INSTANCE.major && minor <= INSTANCE.minor + 1
// Kotlin 1.9 is able to read Kotlin 2.0
// Kotlin K.* is able to read Kotlin M.* if K > M
major == INSTANCE.major && minor <= INSTANCE.minor + 1 ||
major == 2 && INSTANCE.major == 1 && minor == 9 ||
major < INSTANCE.major
}
companion object {
@@ -146,7 +146,7 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
// Try to set Language version to Stable+2 (there is no promises that metadata will be supported)
val experimentalLevelVersion: LanguageVersion
try {
experimentalLevelVersion = LanguageVersion.values()[LanguageVersion.LATEST_STABLE.ordinal+2]
experimentalLevelVersion = LanguageVersion.values()[LanguageVersion.LATEST_STABLE.ordinal + 2]
} catch (e: ArrayIndexOutOfBoundsException) {
// there is no Stable+2 version for now, skiping test
return
@@ -16,6 +16,7 @@ enum class KotlinVersion(val version: String) {
KOTLIN_1_7("1.7"),
KOTLIN_1_8("1.8"),
KOTLIN_1_9("1.9"),
KOTLIN_2_0("2.0"),
;
companion object {
@@ -538,6 +538,7 @@ public final class org/jetbrains/kotlin/gradle/dsl/KotlinVersion : java/lang/Enu
public static final field KOTLIN_1_7 Lorg/jetbrains/kotlin/gradle/dsl/KotlinVersion;
public static final field KOTLIN_1_8 Lorg/jetbrains/kotlin/gradle/dsl/KotlinVersion;
public static final field KOTLIN_1_9 Lorg/jetbrains/kotlin/gradle/dsl/KotlinVersion;
public static final field KOTLIN_2_0 Lorg/jetbrains/kotlin/gradle/dsl/KotlinVersion;
public final fun getVersion ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/kotlin/gradle/dsl/KotlinVersion;
public static fun values ()[Lorg/jetbrains/kotlin/gradle/dsl/KotlinVersion;
@@ -9,7 +9,7 @@ interface KotlinCommonCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCo
/**
* Allow using declarations only from the specified version of bundled libraries
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)"
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)", "2.0 (experimental)"
* Default value: null
*/
@get:org.gradle.api.tasks.Optional
@@ -18,7 +18,7 @@ interface KotlinCommonCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCo
/**
* Provide source compatibility with the specified version of Kotlin
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)"
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)", "2.0 (experimental)"
* Default value: null
*/
@get:org.gradle.api.tasks.Optional
@@ -14,7 +14,7 @@ interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonTool
/**
* Allow using declarations only from the specified version of bundled libraries
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)"
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)", "2.0 (experimental)"
* Default value: null
*/
var apiVersion: kotlin.String?
@@ -27,7 +27,7 @@ interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonTool
/**
* Provide source compatibility with the specified version of Kotlin
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)"
* Possible values: "1.3 (deprecated)", "1.4 (deprecated)", "1.5", "1.6", "1.7", "1.8", "1.9 (experimental)", "2.0 (experimental)"
* Default value: null
*/
var languageVersion: kotlin.String?
@@ -145,7 +145,8 @@ private val apiVersionValues = ApiVersion.run {
KOTLIN_1_6,
KOTLIN_1_7,
KOTLIN_1_8,
KOTLIN_1_9
KOTLIN_1_9,
KOTLIN_2_0
)
}
@@ -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 experimental K2 compiler\nDisable K2 compiler by removing -Xuse-k2 flag"
"kapt currently doesn't support language version 2.0\nPlease use language version 1.* (e.g. 1.9) instead"
)
}