From d4b559937386fac3a7ea399818f981b44c445c1d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 25 Jul 2023 19:08:45 +0200 Subject: [PATCH] Add JVM target bytecode version 21 Unfortunately, there are still problems with running JVM backend tests with JVM target 21 because: 1) The D8 version that we use does not support bytecode version 21, and updating to a newer version requires to change JVM target of compiler tests to 11. This will be addressed separately when we enable JVM 21 in tests-different-jdk. 2) Some tests are failing because of KT-60659 and KT-60770: - builtinStubMethods/bridgesForStubs/emptyStringListAdd.kt - jdk/stream.kt - regressions/kt528.kt #KT-60662 Fixed --- .../src/org/jetbrains/kotlin/config/JvmTarget.kt | 11 ++++++----- compiler/testData/cli/jvm/extraHelp.out | 2 +- compiler/testData/cli/jvm/help.out | 2 +- compiler/testData/cli/jvm/wrongJvmTargetVersion.out | 2 +- .../codegen/box/reflection/classes/nestedClasses.kt | 2 +- .../org/jetbrains/kotlin/gradle/dsl/JvmTarget.kt | 1 + .../api/kotlin-gradle-plugin-api.api | 1 + .../kotlin/gradle/dsl/KotlinJvmCompilerOptions.kt | 4 ++-- .../jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt | 4 ++-- 9 files changed, 16 insertions(+), 13 deletions(-) diff --git a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmTarget.kt b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmTarget.kt index 5133cca5513..f3087e498b9 100644 --- a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmTarget.kt +++ b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmTarget.kt @@ -37,6 +37,7 @@ enum class JvmTarget( JVM_18("18", Opcodes.V16 + 2), JVM_19("19", Opcodes.V16 + 3), JVM_20("20", Opcodes.V16 + 4), + JVM_21("21", Opcodes.V16 + 5), ; override fun toString() = description @@ -46,10 +47,10 @@ enum class JvmTarget( val DEFAULT = JVM_1_8 @JvmStatic - fun fromString(string: String) = values().find { it.description == string } + fun fromString(string: String) = entries.find { it.description == string } fun getDescription(majorVersion: Int): String { - val platformDescription = values().find { it.majorVersion == majorVersion }?.description ?: when (majorVersion) { + val platformDescription = entries.find { it.majorVersion == majorVersion }?.description ?: when (majorVersion) { Opcodes.V1_7 -> "1.7" else -> null } @@ -59,13 +60,13 @@ enum class JvmTarget( } fun supportedValues(): List = - values().asList() - JVM_1_6 + entries - JVM_1_6 const val SUPPORTED_VERSIONS_DESCRIPTION = - "1.8, 9, 10, ..., 20" + "1.8, 9, 10, ..., 21" init { - check(SUPPORTED_VERSIONS_DESCRIPTION == "1.8, 9, 10, ..., ${values().last().description}") { + check(SUPPORTED_VERSIONS_DESCRIPTION == "1.8, 9, 10, ..., ${entries.last().description}") { "Please update the value of the constant JvmTarget.SUPPORTED_VERSIONS_DESCRIPTION." } } diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 3d2354f90fe..605d4de7b39 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -42,7 +42,7 @@ where advanced options include: -Xjava-source-roots= Paths to directories with Java source files -Xjavac-arguments= Java compiler arguments -Xjdk-release= Compile against the specified JDK API version, similarly to javac's `-release`. Requires JDK 9 or newer. - Supported versions depend on the used JDK; for JDK 17+ supported versions are 1.8, 9, 10, ..., 20. + Supported versions depend on the used JDK; for JDK 17+ supported versions are 1.8, 9, 10, ..., 21. Also sets `-jvm-target` value equal to the selected JDK version -Xjspecify-annotations=ignore|strict|warn Specify behavior for jspecify annotations. diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index b6ac7a47bc5..bf16ade93c5 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -6,7 +6,7 @@ where possible options include: -include-runtime Include Kotlin runtime into the resulting JAR -java-parameters Generate metadata for Java 1.8 reflection on method parameters -jdk-home Include a custom JDK from the specified location into the classpath instead of the default JAVA_HOME - -jvm-target Target version of the generated JVM bytecode (1.8, 9, 10, ..., 20), default is 1.8 + -jvm-target Target version of the generated JVM bytecode (1.8, 9, 10, ..., 21), default is 1.8 -module-name Name of the generated .kotlin_module file -no-jdk Don't automatically include the Java runtime into the classpath -no-reflect Don't automatically include Kotlin reflection into the classpath diff --git a/compiler/testData/cli/jvm/wrongJvmTargetVersion.out b/compiler/testData/cli/jvm/wrongJvmTargetVersion.out index 240dfa0f232..6644aeb6389 100644 --- a/compiler/testData/cli/jvm/wrongJvmTargetVersion.out +++ b/compiler/testData/cli/jvm/wrongJvmTargetVersion.out @@ -1,3 +1,3 @@ error: unknown JVM target version: 1.5 -Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 +Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 COMPILATION_ERROR diff --git a/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt b/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt index e2f4d9fa6b6..6e1ac8ae434 100644 --- a/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt +++ b/compiler/testData/codegen/box/reflection/classes/nestedClasses.kt @@ -26,7 +26,7 @@ fun box(): String { // Java interface with nested classes assertEquals(listOf("Entry"), nestedNames(java.util.Map::class)) // Java class with nested classes - assertEquals(listOf("SimpleEntry", "SimpleImmutableEntry"), nestedNames(java.util.AbstractMap::class)) + assertEquals(listOf("SimpleEntry", "SimpleImmutableEntry"), nestedNames(java.util.AbstractMap::class) - "ViewCollection") // Built-ins assertEquals(emptyList(), nestedNames(Array::class)) diff --git a/libraries/tools/kotlin-gradle-compiler-types/src/generated/kotlin/org/jetbrains/kotlin/gradle/dsl/JvmTarget.kt b/libraries/tools/kotlin-gradle-compiler-types/src/generated/kotlin/org/jetbrains/kotlin/gradle/dsl/JvmTarget.kt index 79114bc2310..942096cc528 100644 --- a/libraries/tools/kotlin-gradle-compiler-types/src/generated/kotlin/org/jetbrains/kotlin/gradle/dsl/JvmTarget.kt +++ b/libraries/tools/kotlin-gradle-compiler-types/src/generated/kotlin/org/jetbrains/kotlin/gradle/dsl/JvmTarget.kt @@ -19,6 +19,7 @@ enum class JvmTarget(val target: String) { JVM_18("18"), JVM_19("19"), JVM_20("20"), + JVM_21("21"), ; companion object { diff --git a/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api b/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api index 5ec3ab0a764..41eb8c30667 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api +++ b/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api @@ -92,6 +92,7 @@ public final class org/jetbrains/kotlin/gradle/dsl/JvmTarget : java/lang/Enum { public static final field JVM_19 Lorg/jetbrains/kotlin/gradle/dsl/JvmTarget; public static final field JVM_1_8 Lorg/jetbrains/kotlin/gradle/dsl/JvmTarget; public static final field JVM_20 Lorg/jetbrains/kotlin/gradle/dsl/JvmTarget; + public static final field JVM_21 Lorg/jetbrains/kotlin/gradle/dsl/JvmTarget; public static final field JVM_9 Lorg/jetbrains/kotlin/gradle/dsl/JvmTarget; public final fun getTarget ()Ljava/lang/String; public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/kotlin/gradle/dsl/JvmTarget; diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmCompilerOptions.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmCompilerOptions.kt index 8024bb037a8..3556e0a7c6f 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmCompilerOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmCompilerOptions.kt @@ -15,8 +15,8 @@ interface KotlinJvmCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommo val javaParameters: org.gradle.api.provider.Property /** - * Target version of the generated JVM bytecode (1.8, 9, 10, ..., 20), default is 1.8 - * Possible values: "1.8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" + * Target version of the generated JVM bytecode (1.8, 9, 10, ..., 21), default is 1.8 + * Possible values: "1.8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21" * Default value: JvmTarget.DEFAULT */ @get:org.gradle.api.tasks.Input diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt index 6cc5e285d41..09332e70b97 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt @@ -21,8 +21,8 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions private val org.jetbrains.kotlin.gradle.dsl.JvmTarget.jvmTargetKotlinOption get() = this.target /** - * Target version of the generated JVM bytecode (1.8, 9, 10, ..., 20), default is 1.8 - * Possible values: "1.8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" + * Target version of the generated JVM bytecode (1.8, 9, 10, ..., 21), default is 1.8 + * Possible values: "1.8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21" * Default value: JvmTarget.DEFAULT */ var jvmTarget: kotlin.String