Separate JvmTarget::bytecodeVersion version into major/minor parts

This commit is contained in:
Denis.Zharkov
2020-12-01 18:17:57 +03:00
parent c8851c4f75
commit b860a0c664
6 changed files with 28 additions and 29 deletions
@@ -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
@@ -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) }
}
}
@@ -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 {
@@ -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) {
@@ -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)
@@ -460,7 +460,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
JvmTarget customDefaultTarget = JvmTarget.fromString(DEFAULT_JVM_TARGET);
assert customDefaultTarget != null : "Can't construct JvmTarget for " + DEFAULT_JVM_TARGET;
JvmTarget originalTarget = configuration.get(JVMConfigurationKeys.JVM_TARGET);
if (originalTarget == null || customDefaultTarget.getBytecodeVersion() > 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