Revert metadata version reading advancement for JS/Common

This commit reverts 59e2101a25 partially,
leaving only the implementation of KT-25972 for JVM. The reason is that
we can't fully commit to stabilizing JS (and .kotlin_metadata) binary
metadata formats so much as to postpone any changes done to it for a
whole release year time. It's likely that we will need to update JS
metadata format incompatibly pretty soon, and with the scheme where we
can read the "current + 1" version, it'd require advancing the metadata
version by 2, which would break the nice property that the metadata
version (since Kotlin 1.4) is equal to the version of the compiler that
produced it.

See KT-25972
This commit is contained in:
Alexander Udalov
2018-08-24 19:10:17 +02:00
parent 4067d6b196
commit afd53c9870
5 changed files with 11 additions and 12 deletions
@@ -326,7 +326,10 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
fun testRequireKotlinInNestedClassesAgainst14Js() {
val library = compileJsLibrary("library", additionalOptions = listOf("-Xmetadata-version=1.4.0"))
compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler())
compileKotlin(
"source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(),
additionalOptions = listOf("-Xskip-metadata-version-check")
)
}
/*test source mapping generation when source info is absent*/
@@ -27,7 +27,7 @@ class KotlinJavascriptMetadata(val version: JsMetadataVersion, val moduleName: S
// TODO: move to JS modules
class JsMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
override fun isCompatible(): Boolean =
isMetadataVersionCompatible()
this.isCompatibleTo(INSTANCE)
fun toInteger() = (patch shl 16) + (minOf(minor, 255) shl 8) + minOf(major, 255)
@@ -12,9 +12,11 @@ import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
* This version includes the version of the core protobuf messages (metadata.proto) as well as JVM extensions (jvm_metadata.proto).
*/
class JvmMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
// NOTE: 1.1 is incompatible with 1.0
// In Kotlin 1.4, JVM metadata version is going to be advanced to 1.4.0.
// Kotlin 1.3 is able to read metadata of versions up to Kotlin 1.4.
// NOTE: 1.0 is a pre-Kotlin-1.0 metadata version, with which the current compiler is incompatible
override fun isCompatible() =
isMetadataVersionCompatible() && minor != 0
major == 1 && minor in 1..4
companion object {
@JvmField
@@ -14,8 +14,8 @@ import java.io.InputStream
* of the core protobuf messages (metadata.proto).
*/
class BuiltInsBinaryVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
override fun isCompatible() =
isMetadataVersionCompatible()
override fun isCompatible(): Boolean =
this.isCompatibleTo(INSTANCE)
companion object {
@JvmField
@@ -35,12 +35,6 @@ abstract class BinaryVersion(private vararg val numbers: Int) {
else major == ourVersion.major && minor <= ourVersion.minor
}
// In Kotlin 1.4, all metadata versions (JVM, JS, built-ins/metadata) are going to be advanced to 1.4.0.
// Kotlin 1.3 is able to read metadata of versions up to Kotlin 1.4
protected fun isMetadataVersionCompatible(): Boolean {
return major == 1 && minor <= 4
}
fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean {
if (this.major > major) return true
if (this.major < major) return false