From bbeae23b04fe4934bbcafacff516a140117f55a3 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 28 Dec 2022 15:20:22 +0100 Subject: [PATCH] Allow to read metadata 2.0 from version 1.8 --- .../oldJvmAgainstFir/output.txt | 8 +++----- .../oldJvmAgainstFirWithStableAbi/output.txt | 9 ++++++++- .../library/a.kt | 5 +++++ .../output.txt | 1 + .../source.kt | 5 +++++ .../compiler/CompileKotlinAgainstCustomBinariesTest.kt | 7 +++++-- .../metadata/jvm/deserialization/JvmMetadataVersion.kt | 2 ++ 7 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/library/a.kt create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/output.txt create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/source.kt diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/output.txt index 7a5353abb58..4931db5f9de 100644 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/output.txt +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/output.txt @@ -1,10 +1,8 @@ -error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors -$TMP_DIR$/library.jar!/META-INF/main.kotlin_module: error: module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.0.0, expected version is $ABI_VERSION$. -compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:5: error: unresolved reference: get +error: pre-release classes were found in dependencies. Remove them from the classpath, recompile with a release compiler or use '-Xskip-prerelease-check' to suppress errors +compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:5: error: class 'lib.AKt' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler get { Box("OK").value } ^ -compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:11: error: class 'lib.Box' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.0.0, expected version is $ABI_VERSION$. -The class is loaded from $TMP_DIR$/library.jar!/lib/Box.class +compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFir/source.kt:4:11: error: class 'lib.Box' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler get { Box("OK").value } ^ COMPILATION_ERROR diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbi/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbi/output.txt index d86bac9de59..2d0dc08d41d 100644 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbi/output.txt +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbi/output.txt @@ -1 +1,8 @@ -OK +error: pre-release classes were found in dependencies. Remove them from the classpath, recompile with a release compiler or use '-Xskip-prerelease-check' to suppress errors +compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbi/source.kt:4:5: error: class 'lib.AKt' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler + get { Box("OK").value } + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbi/source.kt:4:11: error: class 'lib.Box' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler + get { Box("OK").value } + ^ +COMPILATION_ERROR diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/library/a.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/library/a.kt new file mode 100644 index 00000000000..71e3e5d293d --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/library/a.kt @@ -0,0 +1,5 @@ +package lib + +class Box(val value: String) + +inline fun get(block: () -> T): T = block() diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/output.txt new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/output.txt @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/source.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/source.kt new file mode 100644 index 00000000000..ffadd735100 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/oldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck/source.kt @@ -0,0 +1,5 @@ +import lib.* + +fun main() { + get { Box("OK").value } +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt index 2dc03d6de7e..c602cc6a057 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt @@ -697,12 +697,15 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration } fun testOldJvmAgainstFirWithStableAbi() { - // TODO: looks like now it's not possible to compile library with version 2.0 to be able to compile against it without additional flags - // Should we delete this test? val library = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0", "-Xabi-stability=stable")) compileKotlin("source.kt", tmpdir, listOf(library)) } + fun testOldJvmAgainstFirWithStableAbiAndNoPrereleaseCheck() { + val library = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0", "-Xabi-stability=stable")) + compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xskip-prerelease-check")) + } + fun testOldJvmAgainstFirWithAllowUnstableDependencies() { val library = compileLibrary("library", additionalOptions = listOf("-language-version", "2.0")) compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xallow-unstable-dependencies", "-Xskip-metadata-version-check")) diff --git a/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/JvmMetadataVersion.kt b/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/JvmMetadataVersion.kt index 5c2169d4293..a14a4d2e377 100644 --- a/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/JvmMetadataVersion.kt +++ b/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/JvmMetadataVersion.kt @@ -19,6 +19,8 @@ class JvmMetadataVersion(versionArray: IntArray, val isStrictSemantics: Boolean) } fun isCompatible(metadataVersionFromLanguageVersion: JvmMetadataVersion): Boolean { + // Special case for bootstrap: 1.8 can read 2.0 + if (major == 2 && minor == 0 && INSTANCE.major == 1 && INSTANCE.minor == 8) return true // * Compiler of deployVersion X (INSTANCE) with LV Y (metadataVersionFromLanguageVersion) // * can read metadata with version <= max(X+1, Y) val forwardCompatibility = if (isStrictSemantics) INSTANCE else INSTANCE_NEXT