From 4f29c113b746708fdd51f0c8cb5b75c5ebff3352 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 3 Aug 2021 21:44:39 +0200 Subject: [PATCH] Remove KotlinCompilerVersion.IS_PRE_RELEASE Now, milestones of major Kotlin releases (e.g. 1.6.0-M1) will NOT generate prerelease binaries anymore. The reason for that is it's proven to be quite a complicated process to turn on IR_PRE_RELEASE after the release is branched, perform double bootstrap and fix tests, and then do it again in reverse just before release. With the new release cadence, we don't have that much time to do it and verify that everything works as intended. Note that this only removes the "global" prerelease flag. Compiler will still generate prerelease binaries if a non-stable language version is used. For example, Kotlin 1.6.0-M1 with `-language-version 1.7` will generate prerelease binaries. --- .../jetbrains/kotlin/build/BuildMetaInfo.kt | 3 +- .../kotlin/config/KotlinCompilerVersion.java | 25 +--- .../CompilerDeserializationConfiguration.kt | 3 +- .../library/a.kt | 5 - .../output.txt | 1 - .../source.kt | 7 -- .../library/a.kt | 5 - .../output.txt | 1 - .../source.kt | 8 -- .../CompilerTestLanguageVersionSettings.kt | 2 +- .../CompileKotlinAgainstCustomBinariesTest.kt | 107 +++--------------- .../kotlin/config/LanguageVersionSettings.kt | 8 +- 12 files changed, 21 insertions(+), 154 deletions(-) delete mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/library/a.kt delete mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/output.txt delete mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/source.kt delete mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/library/a.kt delete mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/output.txt delete mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/source.kt diff --git a/build-common/src/org/jetbrains/kotlin/build/BuildMetaInfo.kt b/build-common/src/org/jetbrains/kotlin/build/BuildMetaInfo.kt index 81df16be9e4..b852deb2d87 100644 --- a/build-common/src/org/jetbrains/kotlin/build/BuildMetaInfo.kt +++ b/build-common/src/org/jetbrains/kotlin/build/BuildMetaInfo.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.build import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.LanguageVersion -import org.jetbrains.kotlin.config.isPreRelease import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion import kotlin.reflect.KClass @@ -43,7 +42,7 @@ abstract class BuildMetaInfoFactory(private val metaInfoClass val languageVersion = args.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: LanguageVersion.LATEST_STABLE return create( - isEAP = languageVersion.isPreRelease(), + isEAP = !languageVersion.isStable, compilerBuildVersion = KotlinCompilerVersion.VERSION, languageVersionString = languageVersion.versionString, apiVersionString = args.apiVersion ?: languageVersion.versionString, diff --git a/compiler/compiler.version/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java b/compiler/compiler.version/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java index d4277393ea9..5c50d2c23aa 100644 --- a/compiler/compiler.version/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java +++ b/compiler/compiler.version/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java @@ -15,23 +15,6 @@ public class KotlinCompilerVersion { public static final String VERSION_FILE_PATH = "/META-INF/compiler.version"; public static final String VERSION; - // True if the latest stable language version supported by this compiler has not yet been released. - // Binaries produced by this compiler with that language version (or any future language version) are going to be marked - // as "pre-release" and will not be loaded by release versions of the compiler. - // Change this value before and after every major release - private static final boolean IS_PRE_RELEASE = false; - - public static final String TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY = "kotlin.test.is.pre.release"; - - public static boolean isPreRelease() { - String overridden = System.getProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY); - if (overridden != null) { - return Boolean.parseBoolean(overridden); - } - - return IS_PRE_RELEASE; - } - /** * @return version of this compiler, or `null` if it isn't known (if VERSION is "@snapshot@") */ @@ -40,6 +23,7 @@ public class KotlinCompilerVersion { return VERSION.equals("@snapshot@") ? null : VERSION; } + @SuppressWarnings({"TryFinallyCanBeTryWithResources", "ConstantConditions"}) private static String loadKotlinCompilerVersion() throws IOException { BufferedReader versionReader = new BufferedReader( new InputStreamReader(KotlinCompilerVersion.class.getResourceAsStream(VERSION_FILE_PATH))); @@ -57,12 +41,5 @@ public class KotlinCompilerVersion { catch (IOException e) { throw new IllegalStateException("Failed to read compiler version from " + VERSION_FILE_PATH); } - - if (!VERSION.equals("@snapshot@") && !VERSION.contains("-") && IS_PRE_RELEASE) { - throw new IllegalStateException( - "IS_PRE_RELEASE cannot be true for a compiler without '-' in its version.\n" + - "Please change IS_PRE_RELEASE to false, commit and push this change to master" - ); - } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/CompilerDeserializationConfiguration.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/CompilerDeserializationConfiguration.kt index 9cf2e90dc65..08ed503963a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/CompilerDeserializationConfiguration.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/CompilerDeserializationConfiguration.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.config.AnalysisFlags -import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration @@ -17,7 +16,7 @@ class CompilerDeserializationConfiguration(languageVersionSettings: LanguageVers override val skipPrereleaseCheck = languageVersionSettings.getFlag(AnalysisFlags.skipPrereleaseCheck) override val reportErrorsOnPreReleaseDependencies = - !skipPrereleaseCheck && !languageVersionSettings.isPreRelease() && !KotlinCompilerVersion.isPreRelease() + !skipPrereleaseCheck && !languageVersionSettings.isPreRelease() override val allowUnstableDependencies = languageVersionSettings.getFlag(AnalysisFlags.allowUnstableDependencies) diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/library/a.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/library/a.kt deleted file mode 100644 index b1828248591..00000000000 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/library/a.kt +++ /dev/null @@ -1,5 +0,0 @@ -package a - -class A - -fun A.foo() = "" diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/output.txt deleted file mode 100644 index d86bac9de59..00000000000 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/output.txt +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/source.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/source.kt deleted file mode 100644 index 298d363e749..00000000000 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryLatestStable/source.kt +++ /dev/null @@ -1,7 +0,0 @@ -package usage - -import a.* - -fun baz(param: A) { - param.foo() -} diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/library/a.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/library/a.kt deleted file mode 100644 index dbf30478826..00000000000 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/library/a.kt +++ /dev/null @@ -1,5 +0,0 @@ -package a - -class A - -fun foo() = "" diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/output.txt deleted file mode 100644 index d86bac9de59..00000000000 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/output.txt +++ /dev/null @@ -1 +0,0 @@ -OK diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/source.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/source.kt deleted file mode 100644 index f21b3de444d..00000000000 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/preReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion/source.kt +++ /dev/null @@ -1,8 +0,0 @@ -package usage - -import a.* - -fun baz(param: A): A { - foo() - return param -} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt index 351ef3c9d29..bb5f206975c 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt @@ -39,7 +39,7 @@ data class CompilerTestLanguageVersionSettings( override fun getFeatureSupport(feature: LanguageFeature): LanguageFeature.State = extraLanguageFeatures[feature] ?: delegate.getFeatureSupport(feature) - override fun isPreRelease(): Boolean = KotlinCompilerVersion.isPreRelease() + override fun isPreRelease(): Boolean = false @Suppress("UNCHECKED_CAST") override fun getFlag(flag: AnalysisFlag): T = analysisFlags[flag] as T? ?: flag.defaultValue diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt index 3b123428cfd..6cbc9bcbc50 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.jvm.compiler import com.intellij.openapi.util.io.FileUtil -import junit.framework.TestCase import org.jetbrains.kotlin.cli.common.CLICompiler import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport @@ -20,9 +19,6 @@ import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler import org.jetbrains.kotlin.cli.transformMetadataInClassFile import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.config.JvmTarget -import org.jetbrains.kotlin.config.KotlinCompilerVersion -import org.jetbrains.kotlin.config.KotlinCompilerVersion.TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY -import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PackageViewDescriptor @@ -38,7 +34,6 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.MockLibraryUtil import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile -import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.org.objectweb.asm.* import org.jetbrains.org.objectweb.asm.tree.ClassNode import java.io.ByteArrayInputStream @@ -115,29 +110,29 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration usageDestination: File, vararg additionalOptions: String ) { - // Compiles the library with the "pre-release" flag, then compiles a usage of this library in the release mode + // Compiles the library with some non-stable language version, then compiles a usage of this library with stable LV. + // If there's no non-stable language version yet, the test does nothing. + val someNonStableVersion = LanguageVersion.values().firstOrNull { it > LanguageVersion.LATEST_STABLE } ?: return - val result = withPreRelease(true) { + val libraryOptions = listOf( + "-language-version", someNonStableVersion.versionString, + // Suppress the "language version X is experimental..." warning. + "-Xsuppress-version-warnings" + ) + + val result = when (compiler) { - is K2JSCompiler -> compileJsLibrary(libraryName) - is K2JVMCompiler -> compileLibrary(libraryName) + is K2JSCompiler -> compileJsLibrary(libraryName, additionalOptions = libraryOptions) + is K2JVMCompiler -> compileLibrary(libraryName, additionalOptions = libraryOptions) else -> throw UnsupportedOperationException(compiler.toString()) } - } - withPreRelease(false) { - compileKotlin("source.kt", usageDestination, listOf(result), compiler, additionalOptions.toList()) - } + compileKotlin( + "source.kt", usageDestination, listOf(result), compiler, + additionalOptions.toList() + listOf("-language-version", LanguageVersion.LATEST_STABLE.versionString) + ) } - private fun withPreRelease(value: Boolean, block: () -> T): T = - try { - System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, value.toString()) - block() - } finally { - System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY) - } - // ------------------------------------------------------------------------------ fun testRawTypes() { @@ -311,31 +306,6 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration doTestPreReleaseKotlinLibrary(K2JVMCompiler(), "library", tmpdir, "-Xskip-metadata-version-check") } - fun testPreReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion() { - withPreRelease(true) { - val library = compileLibrary("library") - val someStableReleasedVersion = LanguageVersion.values().first { it.isStable && it >= LanguageVersion.FIRST_SUPPORTED } - compileKotlin( - "source.kt", tmpdir, listOf(library), K2JVMCompiler(), - listOf("-language-version", someStableReleasedVersion.versionString) - ) - - checkPreReleaseness(File(tmpdir, "usage/SourceKt.class"), shouldBePreRelease = false) - } - } - - fun testPreReleaseCompilerAgainstPreReleaseLibraryLatestStable() { - withPreRelease(true) { - val library = compileLibrary("library") - compileKotlin( - "source.kt", tmpdir, listOf(library), K2JVMCompiler(), - listOf("-language-version", LanguageVersion.LATEST_STABLE.versionString) - ) - - checkPreReleaseness(File(tmpdir, "usage/SourceKt.class"), shouldBePreRelease = true) - } - } - fun testWrongMetadataVersion() { doTestKotlinLibraryWithWrongMetadataVersion("library", null) } @@ -685,25 +655,6 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration assertEquals("Output:\n$output", ExitCode.INTERNAL_ERROR, exitCode) } - // If this test fails, then bootstrap compiler most likely should be advanced - fun testPreReleaseFlagIsConsistentBetweenBootstrapAndCurrentCompiler() { - val bootstrapCompiler = JarFile(PathUtil.kotlinPathsForCompiler.compilerPath) - val classFromBootstrapCompiler = bootstrapCompiler.getEntry(LanguageFeature::class.java.name.replace(".", "/") + ".class") - checkPreReleaseness( - bootstrapCompiler.getInputStream(classFromBootstrapCompiler).readBytes(), - KotlinCompilerVersion.isPreRelease() - ) - } - - fun testPreReleaseFlagIsConsistentBetweenStdlibAndCurrentCompiler() { - val stdlib = JarFile(PathUtil.kotlinPathsForCompiler.stdlibPath) - val classFromStdlib = stdlib.getEntry(KotlinVersion::class.java.name.replace(".", "/") + ".class") - checkPreReleaseness( - stdlib.getInputStream(classFromStdlib).readBytes(), - KotlinCompilerVersion.isPreRelease() - ) - } - fun testAnonymousObjectTypeMetadata() { val library = compileCommonLibrary( libraryName = "library", @@ -798,31 +749,5 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration return outputFile } - - private fun checkPreReleaseness(classFileBytes: ByteArray, shouldBePreRelease: Boolean) { - // If there's no "xi" field in the Metadata annotation, it's value is assumed to be 0, i.e. _not_ pre-release - var isPreRelease = false - - ClassReader(classFileBytes).accept(object : ClassVisitor(Opcodes.API_VERSION) { - override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? { - if (desc != JvmAnnotationNames.METADATA_DESC) return null - - return object : AnnotationVisitor(Opcodes.API_VERSION) { - override fun visit(name: String, value: Any) { - if (name != JvmAnnotationNames.METADATA_EXTRA_INT_FIELD_NAME) return - - isPreRelease = (value as Int and JvmAnnotationNames.METADATA_PRE_RELEASE_FLAG) != 0 - } - } - } - }, 0) - - TestCase.assertEquals("Pre-release flag of the class file has incorrect value", shouldBePreRelease, isPreRelease) - } - - - private fun checkPreReleaseness(file: File, shouldBePreRelease: Boolean) { - checkPreReleaseness(file.readBytes(), shouldBePreRelease) - } } } diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 19b52ae3033..4323c680b0e 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -434,7 +434,7 @@ class LanguageVersionSettingsImpl @JvmOverloads constructor( } } - override fun isPreRelease(): Boolean = languageVersion.isPreRelease() || + override fun isPreRelease(): Boolean = !languageVersion.isStable || specificFeatures.any { (feature, state) -> state == LanguageFeature.State.ENABLED && feature.forcesPreReleaseBinariesIfEnabled() } @@ -445,12 +445,6 @@ class LanguageVersionSettingsImpl @JvmOverloads constructor( } } -fun LanguageVersion.isPreRelease(): Boolean { - if (!isStable) return true - - return KotlinCompilerVersion.isPreRelease() && this == LanguageVersion.LATEST_STABLE -} - fun LanguageFeature.forcesPreReleaseBinariesIfEnabled(): Boolean { val isFeatureNotReleasedYet = sinceVersion?.isStable != true return isFeatureNotReleasedYet && kind.forcesPreReleaseBinaries