From 518b03125cb57c915efe0744b87f7dda541ad247 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 1 Mar 2019 21:54:29 +0100 Subject: [PATCH] Support JVM target versions up to 12 #KT-26240 Fixed --- .../kotlin/codegen/AnnotationCodegen.java | 4 ++++ .../arguments/K2JVMCompilerArguments.kt | 2 +- .../org/jetbrains/kotlin/config/JvmTarget.kt | 23 +++++++++++-------- .../InterfaceDefaultMethodCallChecker.kt | 2 +- compiler/testData/cli/jvm/help.out | 2 +- .../cli/jvm/wrongJvmTargetVersion.out | 2 +- .../kotlin/gradle/dsl/KotlinJvmOptions.kt | 4 ++-- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java index 06b84733773..43fd26301b2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java @@ -244,6 +244,10 @@ public abstract class AnnotationCodegen { annotationTargetMaps.put(JvmTarget.JVM_1_6, jvm6); annotationTargetMaps.put(JvmTarget.JVM_1_8, jvm8); + annotationTargetMaps.put(JvmTarget.JVM_9, jvm8); + annotationTargetMaps.put(JvmTarget.JVM_10, jvm8); + annotationTargetMaps.put(JvmTarget.JVM_11, jvm8); + annotationTargetMaps.put(JvmTarget.JVM_12, jvm8); } private void generateTargetAnnotation( diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index a2be4846baa..eba75fedb3c 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -62,7 +62,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @Argument( value = "-jvm-target", valueDescription = "", - description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6" + description = "Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11 or 12), default is 1.6" ) var jvmTarget: String? by NullableStringFreezableVar(JvmTarget.DEFAULT.description) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JvmTarget.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JvmTarget.kt index e9c88fdf31c..aeb26a4280b 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JvmTarget.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JvmTarget.kt @@ -14,6 +14,7 @@ * limitations under the License. */ + package org.jetbrains.kotlin.config import org.jetbrains.org.objectweb.asm.Opcodes @@ -21,10 +22,13 @@ import org.jetbrains.org.objectweb.asm.Opcodes enum class JvmTarget(override val description: String) : TargetPlatformVersion { JVM_1_6("1.6"), JVM_1_8("1.8"), + JVM_9("9"), + JVM_10("10"), + JVM_11("11"), + JVM_12("12"), ; val bytecodeVersion: Int by lazy { - @Suppress("DEPRECATION") when (this) { JVM_1_6 -> Opcodes.V1_6 JVM_1_8 -> @@ -33,6 +37,10 @@ enum class JvmTarget(override val description: String) : TargetPlatformVersion { java.lang.Boolean.valueOf(System.getProperty("kotlin.test.substitute.bytecode.1.8.to.1.9")) -> Opcodes.V9 else -> Opcodes.V1_8 } + JVM_9 -> Opcodes.V9 + JVM_10 -> Opcodes.V9 + 1 + JVM_11 -> Opcodes.V9 + 2 + JVM_12 -> Opcodes.V9 + 3 } } @@ -44,16 +52,13 @@ enum class JvmTarget(override val description: String) : TargetPlatformVersion { fun fromString(string: String) = values().find { it.description == string } fun getDescription(bytecodeVersion: Int): String { - @Suppress("DEPRECATION") - val platformDescription = values().find { it.bytecodeVersion == bytecodeVersion }?.description ?: - when (bytecodeVersion) { - Opcodes.V1_7 -> "1.7" - Opcodes.V9 -> "1.9" - else -> null - } + val platformDescription = values().find { it.bytecodeVersion == bytecodeVersion }?.description ?: when (bytecodeVersion) { + Opcodes.V1_7 -> "1.7" + else -> null + } return if (platformDescription != null) "JVM target $platformDescription" - else "JVM bytecode version $bytecodeVersion" + else "JVM bytecode version $bytecodeVersion" } } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InterfaceDefaultMethodCallChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InterfaceDefaultMethodCallChecker.kt index 229a2efd33c..9f8fcdfaaa8 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InterfaceDefaultMethodCallChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InterfaceDefaultMethodCallChecker.kt @@ -41,7 +41,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.* class InterfaceDefaultMethodCallChecker(val jvmTarget: JvmTarget) : CallChecker { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { - val supportDefaults = jvmTarget == JvmTarget.JVM_1_8 + val supportDefaults = jvmTarget >= JvmTarget.JVM_1_8 val descriptor = resolvedCall.resultingDescriptor as? CallableMemberDescriptor ?: return if (descriptor is JavaPropertyDescriptor) return diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index 6e4f3eca8a2..32706b154e2 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -5,7 +5,7 @@ where possible options include: -include-runtime Include Kotlin runtime in to resulting .jar -java-parameters Generate metadata for Java 1.8 reflection on method parameters -jdk-home Path to JDK home directory to include into classpath, if differs from default JAVA_HOME - -jvm-target Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6 + -jvm-target Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11 or 12), default is 1.6 -module-name Name of the generated .kotlin_module file -no-jdk Don't include Java runtime into classpath -no-reflect Don't include kotlin-reflect.jar into classpath diff --git a/compiler/testData/cli/jvm/wrongJvmTargetVersion.out b/compiler/testData/cli/jvm/wrongJvmTargetVersion.out index 4a0a38a31ab..1dd8238be49 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 +Supported versions: 1.6, 1.8, 9, 10, 11, 12 COMPILATION_ERROR diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt index efc4cbf5676..a95c9d8a475 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt @@ -23,8 +23,8 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption var jdkHome: kotlin.String? /** - * Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6 - * Possible values: "1.6", "1.8" + * Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11 or 12), default is 1.6 + * Possible values: "1.6", "1.8", "9", "10", "11", "12" * Default value: "1.6" */ var jvmTarget: kotlin.String