diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 1dbf3d2ffc8..e19871abf89 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -201,7 +201,7 @@ class GenerationState private constructor( val target = configuration.get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT val runtimeStringConcat = - if (target.bytecodeVersion >= JvmTarget.JVM_9.bytecodeVersion) + if (target.majorVersion >= JvmTarget.JVM_9.majorVersion) configuration.get(JVMConfigurationKeys.STRING_CONCAT) ?: JvmStringConcat.INLINE else JvmStringConcat.INLINE diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt index 8d8fdcc0549..992bf036778 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -39,7 +39,7 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu } val jvmTarget = get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT - if (jvmTarget.bytecodeVersion < JvmTarget.JVM_1_8.bytecodeVersion) { + if (jvmTarget.majorVersion < JvmTarget.JVM_1_8.majorVersion) { val jvmDefaultMode = languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode) if (jvmDefaultMode.forAllMethodsWithBody) { messageCollector.report( @@ -53,7 +53,7 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu val runtimeStringConcat = JvmStringConcat.fromString(arguments.stringConcat!!) if (runtimeStringConcat != null) { put(JVMConfigurationKeys.STRING_CONCAT, runtimeStringConcat) - if (jvmTarget.bytecodeVersion < JvmTarget.JVM_9.bytecodeVersion && runtimeStringConcat != JvmStringConcat.INLINE) { + if (jvmTarget.majorVersion < JvmTarget.JVM_9.majorVersion && runtimeStringConcat != JvmStringConcat.INLINE) { messageCollector.report( WARNING, "`-Xstring-concat=${arguments.stringConcat}` does nothing with JVM target `${jvmTarget.description}`." @@ -242,4 +242,4 @@ fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments) ?.toTypedArray() ?.filterNot { it.isEmpty() } ?.let { put(JVMConfigurationKeys.KLIB_PATHS, it) } -} \ No newline at end of file +} 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 e9f61674f66..bcb55969294 100644 --- a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmTarget.kt +++ b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmTarget.kt @@ -21,34 +21,33 @@ import org.jetbrains.org.objectweb.asm.Opcodes enum class JvmTarget( override val description: String, + val majorVersion: Int, val descriptionForJavacArgument: String = description, val isPreview: Boolean = false, ) : TargetPlatformVersion { - JVM_1_6("1.6"), - JVM_1_8("1.8"), - JVM_9("9"), - JVM_10("10"), - JVM_11("11"), - JVM_12("12"), - JVM_13("13"), - JVM_14("14"), - JVM_15("15"), - JVM_15_PREVIEW("15_PREVIEW", descriptionForJavacArgument = "15", isPreview = true), + JVM_1_6("1.6", Opcodes.V1_6), + JVM_1_8("1.8", Opcodes.V1_8), + JVM_9("9", Opcodes.V9), + JVM_10("10", Opcodes.V10), + JVM_11("11", Opcodes.V11), + JVM_12("12", Opcodes.V12), + JVM_13("13", Opcodes.V13), + JVM_14("14", Opcodes.V14), + JVM_15("15", Opcodes.V15), + JVM_15_PREVIEW( + "15_PREVIEW", Opcodes.V15, + descriptionForJavacArgument = "15", isPreview = true + ), ; + val minorVersion: Int = + if (isPreview) + 0xffff + else + 0 + val bytecodeVersion: Int by lazy { - when (this) { - JVM_1_6 -> Opcodes.V1_6 - JVM_1_8 -> Opcodes.V1_8 - JVM_9 -> Opcodes.V9 - JVM_10 -> Opcodes.V10 - JVM_11 -> Opcodes.V11 - JVM_12 -> Opcodes.V12 - JVM_13 -> Opcodes.V13 - JVM_14 -> Opcodes.V14 - JVM_15 -> Opcodes.V15 - JVM_15_PREVIEW -> Opcodes.V15 + (0xffff shl 16) - } + (minorVersion shl 16) + majorVersion } companion object { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InlinePlatformCompatibilityChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InlinePlatformCompatibilityChecker.kt index 90bbc8802b3..6f99ef8e748 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InlinePlatformCompatibilityChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/InlinePlatformCompatibilityChecker.kt @@ -62,7 +62,7 @@ class InlinePlatformCompatibilityChecker(val jvmTarget: JvmTarget, languageVersi val propertyOrFun = DescriptorUtils.getDirectMember(resultingDescriptor) - val compilingBytecodeVersion = jvmTarget.bytecodeVersion + val compilingBytecodeVersion = jvmTarget.majorVersion if (!properError) { val inliningBytecodeVersion = getBytecodeVersionIfDeserializedDescriptor(propertyOrFun, false) if (inliningBytecodeVersion != null && compilingBytecodeVersion < inliningBytecodeVersion) { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt index 7041075f017..89d8adcb54f 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt @@ -59,7 +59,7 @@ class LocalFunInlineChecker : DeclarationChecker { } class JvmStaticChecker(jvmTarget: JvmTarget, languageVersionSettings: LanguageVersionSettings) : DeclarationChecker { - private val isLessJVM18 = jvmTarget.bytecodeVersion < JvmTarget.JVM_1_8.bytecodeVersion + private val isLessJVM18 = jvmTarget.majorVersion < JvmTarget.JVM_1_8.majorVersion private val supportJvmStaticInInterface = languageVersionSettings.supportsFeature(LanguageFeature.JvmStaticInInterface) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java index 5c46f1b1baf..73d7b592784 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -460,7 +460,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest originalTarget.getBytecodeVersion()) { + if (originalTarget == null || customDefaultTarget.getMajorVersion() > originalTarget.getMajorVersion()) { // It's not safe to substitute target in general // cause it can affect generated bytecode and original behaviour should be tested somehow. // Original behaviour testing is perfomed by