Restore writing bytecode version to metadata for LV < 1.5
#KT-45323 Fixed
This commit is contained in:
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.codegen
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.config.JvmAnalysisFlags
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmBytecodeBinaryVersion
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmBytecodeBinaryVersion
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor
|
||||
|
||||
fun writeKotlinMetadata(
|
||||
@@ -32,7 +32,9 @@ fun writeKotlinMetadata(
|
||||
) {
|
||||
val av = cb.newAnnotation(JvmAnnotationNames.METADATA_DESC, true)
|
||||
av.visit(JvmAnnotationNames.METADATA_VERSION_FIELD_NAME, state.metadataVersion.toArray())
|
||||
av.visit(JvmAnnotationNames.BYTECODE_VERSION_FIELD_NAME, JvmBytecodeBinaryVersion.INSTANCE.toArray())
|
||||
if (!state.metadataVersion.isAtLeast(1, 5, 0)) {
|
||||
av.visit("bv", JvmBytecodeBinaryVersion.INSTANCE.toArray())
|
||||
}
|
||||
av.visit(JvmAnnotationNames.KIND_FIELD_NAME, kind.id)
|
||||
var flags = extraFlags
|
||||
if (state.languageVersionSettings.isPreRelease()) {
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
|
||||
/**
|
||||
* Bytecode version was in the Kotlin metadata ([Metadata.bytecodeVersion]) since 1.0, but it was never used meaningfully in the compiler,
|
||||
* outside of one very special case regarding experimental coroutines, which is now obsolete.
|
||||
* It is still used for two reasons:
|
||||
* 1) We write the latest observed bytecode version, `1.0.3` (see [INSTANCE]), to class files if metadata version is less than 1.5.
|
||||
* The reason is that Kotlin compilers of versions 1.0.0-1.3.72 can still read these class files, and they had a strict check which
|
||||
* results in a compilation error if there's no bytecode version in the `@Metadata` annotation (see KT-45323).
|
||||
* This will not be needed at the moment when the earliest supported language version becomes 1.5, i.e. in Kotlin 1.7.
|
||||
* 2) It's stored in persistent incremental compilation caches. We can probably simply remove it and increase the cache version there.
|
||||
* Once both these usages are dealt with, this class can be removed.
|
||||
*/
|
||||
class JvmBytecodeBinaryVersion(vararg numbers: Int) {
|
||||
val major: Int = numbers.getOrNull(0) ?: -1
|
||||
val minor: Int = numbers.getOrNull(1) ?: -1
|
||||
val patch: Int = numbers.getOrNull(2) ?: -1
|
||||
|
||||
fun toArray(): IntArray = intArrayOf(major, minor, patch)
|
||||
|
||||
override fun toString(): String = buildString {
|
||||
append(major)
|
||||
if (minor != -1) {
|
||||
append(".$minor")
|
||||
if (patch != -1) append(".$patch")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE = JvmBytecodeBinaryVersion(1, 0, 3)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user