diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java index 1572a5916a0..78f654c9b15 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java @@ -29,7 +29,7 @@ import org.jetbrains.annotations.TestOnly; import org.jetbrains.kotlin.backend.common.output.OutputFile; import org.jetbrains.kotlin.backend.common.output.OutputFileCollection; import org.jetbrains.kotlin.codegen.state.GenerationState; -import org.jetbrains.kotlin.load.java.JvmAbi; +import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion; import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils; import org.jetbrains.kotlin.load.kotlin.PackageParts; import org.jetbrains.kotlin.name.FqName; @@ -123,7 +123,7 @@ public class ClassFileFactory implements OutputFileCollection { try { ByteArrayOutputStream moduleMapping = new ByteArrayOutputStream(4096); DataOutputStream dataOutStream = new DataOutputStream(moduleMapping); - int[] version = JvmAbi.VERSION.toArray(); + int[] version = JvmBytecodeBinaryVersion.INSTANCE.toArray(); dataOutStream.writeInt(version.length); for (int number : version) { dataOutStream.writeInt(number); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java index 400a771ee1d..7023e2a87bc 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.load.java.JvmAbi; import org.jetbrains.kotlin.load.java.JvmAnnotationNames; +import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion; import org.jetbrains.kotlin.load.kotlin.ModuleMapping; import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityUtilsKt; import org.jetbrains.kotlin.psi.KtFile; @@ -223,7 +224,7 @@ public class JvmCodegenUtil { } public static void writeAbiVersion(@NotNull AnnotationVisitor av) { - av.visit(JvmAnnotationNames.VERSION_FIELD_NAME, JvmAbi.VERSION.toArray()); + av.visit(JvmAnnotationNames.VERSION_FIELD_NAME, JvmBytecodeBinaryVersion.INSTANCE.toArray()); } public static void writeModuleName(@NotNull AnnotationVisitor av, @NotNull GenerationState state) { diff --git a/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializer.kt b/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializer.kt index fbaeeabb928..b5dd0a26172 100644 --- a/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializer.kt +++ b/compiler/builtins-serializer/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializer.kt @@ -21,8 +21,8 @@ import com.intellij.openapi.util.Disposer import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.analyzer.ModuleContent import org.jetbrains.kotlin.analyzer.ModuleInfo +import org.jetbrains.kotlin.builtins.BuiltInsBinaryVersion import org.jetbrains.kotlin.builtins.BuiltInsSerializedResourcePaths -import org.jetbrains.kotlin.builtins.BuiltinsPackageFragment import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles @@ -169,7 +169,7 @@ class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) { private fun serializeBuiltInsFile() { val stream = ByteArrayOutputStream() with(DataOutputStream(stream)) { - val version = BuiltinsPackageFragment.VERSION.toArray() + val version = BuiltInsBinaryVersion.INSTANCE.toArray() writeInt(version.size) version.forEach { writeInt(it) } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java index f41a5e0df6b..3f4753721f3 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.diagnostics.*; import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages; import org.jetbrains.kotlin.load.java.JavaBindingContext; -import org.jetbrains.kotlin.load.java.JvmAbi; +import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion; import org.jetbrains.kotlin.load.java.components.TraceBasedErrorReporter; import org.jetbrains.kotlin.load.java.components.TraceBasedErrorReporter.AbiVersionErrorData; import org.jetbrains.kotlin.psi.KtFile; @@ -165,7 +165,7 @@ public final class AnalyzerWithCompilerReport { messageCollector.report( CompilerMessageSeverity.ERROR, "Class '" + JvmClassName.byClassId(data.getClassId()) + "' was compiled with an incompatible version of Kotlin. " + - "Its ABI version is " + data.getActualVersion() + ", expected ABI version is " + JvmAbi.VERSION, + "Its ABI version is " + data.getActualVersion() + ", expected ABI version is " + JvmBytecodeBinaryVersion.INSTANCE, CompilerMessageLocation.create(path, -1, -1, null) ); } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java b/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java index 497bdb57f41..7611cf861c7 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.cli.common.ExitCode; import org.jetbrains.kotlin.cli.common.KotlinVersion; import org.jetbrains.kotlin.cli.js.K2JSCompiler; import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; -import org.jetbrains.kotlin.load.java.JvmAbi; +import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion; import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.Tmpdir; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; @@ -72,7 +72,7 @@ public class CliBaseTest { public static String getNormalizedCompilerOutput(@NotNull String pureOutput, @NotNull ExitCode exitCode, @NotNull String testDataDir) { String normalizedOutputWithoutExitCode = pureOutput .replace(new File(testDataDir).getAbsolutePath(), "$TESTDATA_DIR$") - .replace("expected ABI version is " + JvmAbi.VERSION, "expected ABI version is $ABI_VERSION$") + .replace("expected ABI version is " + JvmBytecodeBinaryVersion.INSTANCE, "expected ABI version is $ABI_VERSION$") .replace("\\", "/") .replace(KotlinVersion.VERSION, "$VERSION$"); diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt index a84d2bd796c..a531b1baaae 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt @@ -30,6 +30,8 @@ class JsBinaryVersion protected constructor( major: Int, minor: Int, patch: Int, rest: List ) : BinaryVersion(major, minor, patch, rest) { companion object { + @JvmField val INSTANCE = create(0, 3, 0) + @JvmField val INVALID_VERSION = JsBinaryVersion.create(IntArray(0)) @JvmStatic fun create(version: IntArray) = create(version, ::JsBinaryVersion) @@ -50,7 +52,7 @@ object KotlinJavascriptMetadataUtils { */ private val METADATA_PATTERN = "(?m)\\w+\\.$KOTLIN_JAVASCRIPT_METHOD_NAME\\((\\d+),\\s*(['\"])([^'\"]*)\\2,\\s*(['\"])([^'\"]*)\\4\\)".toPattern() - @JvmField val ABI_VERSION: Int = JsBinaryVersion.create(0, 3, 0).minor + @JvmField val ABI_VERSION: Int = JsBinaryVersion.INSTANCE.minor fun replaceSuffix(filePath: String): String = filePath.substringBeforeLast(JS_EXT) + META_JS_SUFFIX diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/AbiVersionUtil.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/AbiVersionUtil.java index da5f289a195..7b776aad961 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/AbiVersionUtil.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/AbiVersionUtil.java @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion; public final class AbiVersionUtil { public static boolean isAbiVersionCompatible(@NotNull BinaryVersion actual) { - return actual.isCompatibleTo(JvmAbi.VERSION); + return actual.isCompatibleTo(JvmBytecodeBinaryVersion.INSTANCE); } private AbiVersionUtil() { diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java index fab76d435bc..2319471db68 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java @@ -32,18 +32,6 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.isClassOrEnumClass; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject; public final class JvmAbi { - /** - * This constant is used to identify binary format (class file) versions - * If you change class file metadata format and/or naming conventions, please change this version. - * - Major version should be increased only when the new binary format is neither forward- nor backward compatible. - * This shouldn't really ever happen at all. - * - Minor version should be increased when the new format is backward compatible, - * i.e. the new compiler can process old class files, but the old compiler will not be able to process new class files. - * - Patch version can be increased freely and is only supposed to be used for debugging. Increase the patch version when you - * make a change to the metadata format or the bytecode which is both forward- and backward compatible. - */ - public static final JvmBytecodeBinaryVersion VERSION = JvmBytecodeBinaryVersion.create(1, 0, 2); - public static final String DEFAULT_IMPLS_CLASS_NAME = "DefaultImpls"; public static final String DEFAULT_IMPLS_SUFFIX = "$" + DEFAULT_IMPLS_CLASS_NAME; diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmBytecodeBinaryVersion.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmBytecodeBinaryVersion.kt index bfc33bb765b..753eb8c8e17 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmBytecodeBinaryVersion.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmBytecodeBinaryVersion.kt @@ -22,6 +22,9 @@ class JvmBytecodeBinaryVersion protected constructor( major: Int, minor: Int, patch: Int, rest: List ) : BinaryVersion(major, minor, patch, rest) { companion object { + @JvmField + val INSTANCE = create(1, 0, 2) + @JvmField val INVALID_VERSION = JvmBytecodeBinaryVersion.create(IntArray(0)) diff --git a/core/descriptors.runtime/src/org/jetbrains/kotlin/load/java/components/RuntimeErrorReporter.kt b/core/descriptors.runtime/src/org/jetbrains/kotlin/load/java/components/RuntimeErrorReporter.kt index 5358369eac0..dafca0012c9 100644 --- a/core/descriptors.runtime/src/org/jetbrains/kotlin/load/java/components/RuntimeErrorReporter.kt +++ b/core/descriptors.runtime/src/org/jetbrains/kotlin/load/java/components/RuntimeErrorReporter.kt @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.load.java.components import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.load.java.JvmAbi +import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter @@ -31,7 +31,7 @@ object RuntimeErrorReporter : ErrorReporter { override fun reportIncompatibleAbiVersion(classId: ClassId, filePath: String, actualVersion: BinaryVersion) { throw IllegalStateException("Incompatible ABI version of $classId: $actualVersion " + - "(expected version is ${JvmAbi.VERSION})") + "(expected version is ${JvmBytecodeBinaryVersion.INSTANCE})") } override fun reportCannotInferVisibility(descriptor: CallableMemberDescriptor) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsBinaryVersion.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsBinaryVersion.kt index 3c67f684c9c..c91efe50f4c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsBinaryVersion.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsBinaryVersion.kt @@ -18,10 +18,17 @@ package org.jetbrains.kotlin.builtins import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion +/** + * The version of the format in which the .kotlin_builtins file is stored. This version also includes the version + * of the core protobuf messages (descriptors.proto). + */ class BuiltInsBinaryVersion protected constructor( major: Int, minor: Int, patch: Int, rest: List ) : BinaryVersion(major, minor, patch, rest) { companion object { + @JvmField + val INSTANCE = create(1, 0, 0) + @JvmStatic fun create(version: IntArray) = create(version, ::BuiltInsBinaryVersion) diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltinsPackageFragment.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltinsPackageFragment.kt index 9badd81d33d..4ef79355bb8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltinsPackageFragment.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltinsPackageFragment.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf -import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragment import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope @@ -39,11 +38,11 @@ class BuiltinsPackageFragment( val dataInput = DataInputStream(stream) val version = BuiltInsBinaryVersion.create((1..dataInput.readInt()).map { dataInput.readInt() }.toIntArray()) - if (!version.isCompatibleTo(BuiltinsPackageFragment.VERSION)) { + if (!version.isCompatibleTo(BuiltInsBinaryVersion.INSTANCE)) { // TODO: report a proper diagnostic throw UnsupportedOperationException( "Kotlin built-in definition format version is not supported: " + - "expected ${BuiltinsPackageFragment.VERSION}, actual $version. " + + "expected ${BuiltInsBinaryVersion.INSTANCE}, actual $version. " + "Please update Kotlin" ) } @@ -71,9 +70,4 @@ class BuiltinsPackageFragment( override fun loadClassNames(packageProto: ProtoBuf.Package): Collection { return packageProto.getExtension(BuiltInsProtoBuf.className)?.map { id -> nameResolver.getName(id) } ?: listOf() } - - companion object { - // Advance this version when the common or builtins-specific binary metadata format is changed - val VERSION = BuiltInsBinaryVersion.create(1, 0, 0) - } } diff --git a/core/util.runtime/src/org/jetbrains/kotlin/serialization/deserialization/BinaryVersion.kt b/core/util.runtime/src/org/jetbrains/kotlin/serialization/deserialization/BinaryVersion.kt index 225d022f4db..1d71a17c44b 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/serialization/deserialization/BinaryVersion.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/serialization/deserialization/BinaryVersion.kt @@ -16,6 +16,15 @@ package org.jetbrains.kotlin.serialization.deserialization +/** + * Subclasses of this class are used to identify different versions of the binary output of the compiler and their compatibility guarantees. + * - Major version should be increased only when the new binary format is neither forward- nor backward compatible. + * This shouldn't really ever happen at all. + * - Minor version should be increased when the new format is backward compatible, + * i.e. the new compiler can process old data, but the old compiler will not be able to process new data. + * - Patch version can be increased freely and is only supposed to be used for debugging. Increase the patch version when you + * make a change to binaries which is both forward- and backward compatible. + */ abstract class BinaryVersion protected constructor( val major: Int, val minor: Int, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt index b8463b6d739..cbeb3088db5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClassFileDecompiler.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolverForDecompiler import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledText import org.jetbrains.kotlin.idea.decompiler.textBuilder.defaultDecompilerRendererOptions -import org.jetbrains.kotlin.load.java.JvmAbi +import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion import org.jetbrains.kotlin.load.kotlin.header.isCompatibleClassKind import org.jetbrains.kotlin.load.kotlin.header.isCompatibleFileFacadeKind import org.jetbrains.kotlin.load.kotlin.header.isCompatibleMultifileClassKind @@ -89,7 +89,7 @@ fun buildDecompiledTextForClassFile( !classHeader.isCompatibleAbiVersion -> { DecompiledText( INCOMPATIBLE_ABI_VERSION_COMMENT - .replace(CURRENT_ABI_VERSION_MARKER, JvmAbi.VERSION.toString()) + .replace(CURRENT_ABI_VERSION_MARKER, JvmBytecodeBinaryVersion.INSTANCE.toString()) .replace(FILE_ABI_VERSION_MARKER, classHeader.version.toString()), mapOf()) } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersion.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersion.kt index 493a6e59875..cad343f160a 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersion.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/CacheVersion.kt @@ -22,7 +22,7 @@ import org.jetbrains.jps.builders.storage.BuildDataPaths import org.jetbrains.jps.incremental.ModuleBuildTarget import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.jps.incremental.CacheVersion.Action -import org.jetbrains.kotlin.load.java.JvmAbi +import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion import java.io.File private val NORMAL_VERSION = 8 @@ -47,7 +47,7 @@ class CacheVersion( get() = versionFile.readText().toInt() private val expectedVersion: Int - get() = ownVersion * 1000000 + JvmAbi.VERSION.major * 1000 + JvmAbi.VERSION.minor + get() = ownVersion * 1000000 + JvmBytecodeBinaryVersion.INSTANCE.major * 1000 + JvmBytecodeBinaryVersion.INSTANCE.minor fun checkVersion(): Action = when (versionFile.exists() to isEnabled) {