Write and read built-ins binary version
This commit is contained in:
+11
@@ -25,6 +25,17 @@ data class BinaryVersion private constructor(
|
||||
fun toArray(): IntArray =
|
||||
intArrayOf(major, minor, patch, *rest.toIntArray())
|
||||
|
||||
/**
|
||||
* Returns true if this version of some format loaded from some binaries is compatible
|
||||
* to the expected version of that format in the current compiler.
|
||||
*
|
||||
* @param ourVersion the version of this format in the current compiler
|
||||
*/
|
||||
fun isCompatibleTo(ourVersion: BinaryVersion): Boolean {
|
||||
return if (major == 0) ourVersion.major == 0 && minor == ourVersion.minor
|
||||
else major == ourVersion.major && minor <= ourVersion.minor
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
val versions = toArray().takeWhile { it != UNKNOWN }
|
||||
return if (versions.isEmpty()) "unknown" else versions.joinToString(".")
|
||||
|
||||
+7
-7
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.BuiltinsPackageFragment
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -40,15 +41,14 @@ public abstract class DeserializedPackageFragment(
|
||||
|
||||
val builtinsMessage = serializedResourcePaths.getBuiltInsFilePath(fqName)?.let(loadResource)?.let { stream ->
|
||||
val dataInput = DataInputStream(stream)
|
||||
val version = (1..dataInput.readInt()).map { dataInput.readInt() }
|
||||
val version = BinaryVersion.create((1..dataInput.readInt()).map { dataInput.readInt() }.toIntArray())
|
||||
|
||||
// TODO: check version correctly
|
||||
if (!(version.size == 3 && version.let {
|
||||
val (major, minor, patch) = it
|
||||
major == 1 && minor == 0 && patch == 0
|
||||
})) {
|
||||
if (!version.isCompatibleTo(BuiltinsPackageFragment.VERSION)) {
|
||||
// TODO: report a proper diagnostic
|
||||
throw UnsupportedOperationException(
|
||||
"Kotlin built-in definition format version is not supported: expected 1.0.0, actual ${version.joinToString(".")}"
|
||||
"Kotlin built-in definition format version is not supported: " +
|
||||
"expected ${BuiltinsPackageFragment.VERSION}, actual $version. " +
|
||||
"Please update Kotlin"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user