Restore writing bytecode version to metadata for LV < 1.5
#KT-45323 Fixed
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.build
|
package org.jetbrains.kotlin.build
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.JvmBytecodeBinaryVersion
|
||||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.codegen
|
|||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.config.JvmAnalysisFlags
|
import org.jetbrains.kotlin.config.JvmAnalysisFlags
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
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.load.kotlin.header.KotlinClassHeader
|
||||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmBytecodeBinaryVersion
|
|
||||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor
|
import org.jetbrains.org.objectweb.asm.AnnotationVisitor
|
||||||
|
|
||||||
fun writeKotlinMetadata(
|
fun writeKotlinMetadata(
|
||||||
@@ -32,7 +32,9 @@ fun writeKotlinMetadata(
|
|||||||
) {
|
) {
|
||||||
val av = cb.newAnnotation(JvmAnnotationNames.METADATA_DESC, true)
|
val av = cb.newAnnotation(JvmAnnotationNames.METADATA_DESC, true)
|
||||||
av.visit(JvmAnnotationNames.METADATA_VERSION_FIELD_NAME, state.metadataVersion.toArray())
|
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)
|
av.visit(JvmAnnotationNames.KIND_FIELD_NAME, kind.id)
|
||||||
var flags = extraFlags
|
var flags = extraFlags
|
||||||
if (state.languageVersionSettings.isPreRelease()) {
|
if (state.languageVersionSettings.isPreRelease()) {
|
||||||
|
|||||||
+11
-4
@@ -3,19 +3,26 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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.build
|
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,
|
* 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 in incremental compilation
|
* outside of one very special case regarding experimental coroutines, which is now obsolete.
|
||||||
* caches though. We should probably just pretend that the bytecode version of any Kotlin file from now on is equal to the latest observed
|
* It is still used for two reasons:
|
||||||
* bytecode version, `1.0.3` (see [INSTANCE]).
|
* 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) {
|
class JvmBytecodeBinaryVersion(vararg numbers: Int) {
|
||||||
val major: Int = numbers.getOrNull(0) ?: -1
|
val major: Int = numbers.getOrNull(0) ?: -1
|
||||||
val minor: Int = numbers.getOrNull(1) ?: -1
|
val minor: Int = numbers.getOrNull(1) ?: -1
|
||||||
val patch: Int = numbers.getOrNull(2) ?: -1
|
val patch: Int = numbers.getOrNull(2) ?: -1
|
||||||
|
|
||||||
|
fun toArray(): IntArray = intArrayOf(major, minor, patch)
|
||||||
|
|
||||||
override fun toString(): String = buildString {
|
override fun toString(): String = buildString {
|
||||||
append(major)
|
append(major)
|
||||||
if (minor != -1) {
|
if (minor != -1) {
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.incremental
|
package org.jetbrains.kotlin.jps.incremental
|
||||||
|
|
||||||
import org.jetbrains.kotlin.build.JvmBytecodeBinaryVersion
|
import org.jetbrains.kotlin.load.kotlin.JvmBytecodeBinaryVersion
|
||||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.jps.incremental
|
package org.jetbrains.kotlin.jps.incremental
|
||||||
|
|
||||||
import org.jetbrains.annotations.TestOnly
|
import org.jetbrains.annotations.TestOnly
|
||||||
import org.jetbrains.kotlin.build.JvmBytecodeBinaryVersion
|
import org.jetbrains.kotlin.load.kotlin.JvmBytecodeBinaryVersion
|
||||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|||||||
Reference in New Issue
Block a user