From e8181c0473763b6d8ee481638193024967351c8a Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Thu, 29 Mar 2018 13:17:09 +0300 Subject: [PATCH] Introduce -Xprogressive --- .../arguments/CommonCompilerArguments.kt | 26 +++++++++++++++++++ compiler/testData/cli/js/jsExtraHelp.out | 5 ++++ compiler/testData/cli/jvm/extraHelp.out | 5 ++++ .../progressive/dataClassOverridingCopy.kt | 5 ++++ .../nonConstValueAsVarargInAnnotation.kt | 6 +++++ .../valReassignmentViaBackingField.kt | 5 ++++ .../testData/cli/jvm/progressiveModeOff.args | 3 +++ .../testData/cli/jvm/progressiveModeOff.out | 10 +++++++ .../testData/cli/jvm/progressiveModeOn.args | 4 +++ .../testData/cli/jvm/progressiveModeOn.out | 10 +++++++ .../kotlin/cli/CliTestGenerated.java | 12 +++++++++ .../kotlin/config/LanguageVersionSettings.kt | 23 ++++++++-------- 12 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 compiler/testData/cli/jvm/progressive/dataClassOverridingCopy.kt create mode 100644 compiler/testData/cli/jvm/progressive/nonConstValueAsVarargInAnnotation.kt create mode 100644 compiler/testData/cli/jvm/progressive/valReassignmentViaBackingField.kt create mode 100644 compiler/testData/cli/jvm/progressiveModeOff.args create mode 100644 compiler/testData/cli/jvm/progressiveModeOff.out create mode 100644 compiler/testData/cli/jvm/progressiveModeOn.args create mode 100644 compiler/testData/cli/jvm/progressiveModeOn.out diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 791be09d7b9..da92f82d1f1 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -160,6 +160,16 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) var dumpPerf: String? by FreezableVar(null) + @Argument( + value = "-Xprogressive", + description = "Enable compiler progressive mode.\n" + + "In this mode, deprecations and bug fixes for unstable code take effect immediately,\n" + + "instead of going through graceful migration cycle.\n" + + "Code, written in progressive mode is backward compatible; however, code written in\n" + + "non-progressive mode may cause compilation errors in progressive mode." + ) + var progressiveMode by FreezableVar(false) + open fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> { return HashMap, Any>().apply { put(AnalysisFlag.skipMetadataVersionCheck, skipMetadataVersionCheck) @@ -207,6 +217,14 @@ abstract class CommonCompilerArguments : CommonToolArguments() { if (properIeee754Comparisons) { put(LanguageFeature.ProperIeee754Comparisons, LanguageFeature.State.ENABLED) } + + if (progressiveMode) { + LanguageFeature.values().filter { it.enabledInProgressiveMode }.forEach { + // Don't overwrite other settings: users may want to turn off some particular + // breaking change manually instead of turning off whole progressive mode + if (!contains(it)) put(it, LanguageFeature.State.ENABLED) + } + } } fun configureLanguageVersionSettings(collector: MessageCollector): LanguageVersionSettings { @@ -232,6 +250,14 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) } + if (progressiveMode && languageVersion < LanguageVersion.LATEST_STABLE) { + collector.report( + CompilerMessageSeverity.STRONG_WARNING, + "'-Xprogressive' meaningful only for latest language version (${LanguageVersion.LATEST_STABLE}), while this build uses $languageVersion\n" + + "Behaviour of compiler in such mode is undefined; please, consider moving to the latest stable version or turning off progressive mode." + ) + } + return LanguageVersionSettingsImpl( languageVersion, ApiVersion.createByLanguageVersion(apiVersion), diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index 54f547aa718..0ec84caafa5 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -16,6 +16,11 @@ where advanced options include: -Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects -Xno-inline Disable method inlining -Xplugin= Load plugins from the given classpath + -Xprogressive Enable compiler progressive mode. + In this mode, deprecations and bug fixes for unstable code take effect immediately, + instead of going through graceful migration cycle. + Code, written in progressive mode is backward compatible; however, code written in + non-progressive mode may cause compilation errors in progressive mode. -Xproper-ieee754-comparisons Generate proper IEEE 754 comparisons in all cases if values are statically known to be of primitive numeric types -Xread-deserialized-contracts Enable reading of contracts from metadata -Xreport-output-files Report source to output files mapping diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 51143a54813..84e33cb7935 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -58,6 +58,11 @@ where advanced options include: -Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects -Xno-inline Disable method inlining -Xplugin= Load plugins from the given classpath + -Xprogressive Enable compiler progressive mode. + In this mode, deprecations and bug fixes for unstable code take effect immediately, + instead of going through graceful migration cycle. + Code, written in progressive mode is backward compatible; however, code written in + non-progressive mode may cause compilation errors in progressive mode. -Xproper-ieee754-comparisons Generate proper IEEE 754 comparisons in all cases if values are statically known to be of primitive numeric types -Xread-deserialized-contracts Enable reading of contracts from metadata -Xreport-output-files Report source to output files mapping diff --git a/compiler/testData/cli/jvm/progressive/dataClassOverridingCopy.kt b/compiler/testData/cli/jvm/progressive/dataClassOverridingCopy.kt new file mode 100644 index 00000000000..b99b20d8c06 --- /dev/null +++ b/compiler/testData/cli/jvm/progressive/dataClassOverridingCopy.kt @@ -0,0 +1,5 @@ +interface WithCopy { + fun copy(str: T): WithCopy +} + +data class Test(val str: String): WithCopy \ No newline at end of file diff --git a/compiler/testData/cli/jvm/progressive/nonConstValueAsVarargInAnnotation.kt b/compiler/testData/cli/jvm/progressive/nonConstValueAsVarargInAnnotation.kt new file mode 100644 index 00000000000..e9a2e152b4b --- /dev/null +++ b/compiler/testData/cli/jvm/progressive/nonConstValueAsVarargInAnnotation.kt @@ -0,0 +1,6 @@ +val nonConstArray = longArrayOf(0) + +annotation class Anno(vararg val value: Long) + +@Anno(value = nonConstArray) +fun foo1() {} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/progressive/valReassignmentViaBackingField.kt b/compiler/testData/cli/jvm/progressive/valReassignmentViaBackingField.kt new file mode 100644 index 00000000000..294d9f37b43 --- /dev/null +++ b/compiler/testData/cli/jvm/progressive/valReassignmentViaBackingField.kt @@ -0,0 +1,5 @@ +val my: Int = 1 + get() { + field++ + return field + } diff --git a/compiler/testData/cli/jvm/progressiveModeOff.args b/compiler/testData/cli/jvm/progressiveModeOff.args new file mode 100644 index 00000000000..cfe8ab049db --- /dev/null +++ b/compiler/testData/cli/jvm/progressiveModeOff.args @@ -0,0 +1,3 @@ +$TESTDATA_DIR$/progressive +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/progressiveModeOff.out b/compiler/testData/cli/jvm/progressiveModeOff.out new file mode 100644 index 00000000000..55607b301d8 --- /dev/null +++ b/compiler/testData/cli/jvm/progressiveModeOff.out @@ -0,0 +1,10 @@ +compiler/testData/cli/jvm/progressive/dataClassOverridingCopy.kt:5:1: warning: function 'copy' generated for the data class has default values for parameters, and conflicts with member of supertype 'WithCopy' +data class Test(val str: String): WithCopy +^ +compiler/testData/cli/jvm/progressive/nonConstValueAsVarargInAnnotation.kt:5:15: warning: an annotation argument must be a compile-time constant +@Anno(value = nonConstArray) + ^ +compiler/testData/cli/jvm/progressive/valReassignmentViaBackingField.kt:3:9: warning: reassignment of read-only property via backing field is deprecated + field++ + ^ +OK diff --git a/compiler/testData/cli/jvm/progressiveModeOn.args b/compiler/testData/cli/jvm/progressiveModeOn.args new file mode 100644 index 00000000000..d1d42e61f3e --- /dev/null +++ b/compiler/testData/cli/jvm/progressiveModeOn.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/progressive +-d +$TEMP_DIR$ +-Xprogressive \ No newline at end of file diff --git a/compiler/testData/cli/jvm/progressiveModeOn.out b/compiler/testData/cli/jvm/progressiveModeOn.out new file mode 100644 index 00000000000..d878cf0e340 --- /dev/null +++ b/compiler/testData/cli/jvm/progressiveModeOn.out @@ -0,0 +1,10 @@ +compiler/testData/cli/jvm/progressive/dataClassOverridingCopy.kt:5:1: error: function 'copy' generated for the data class has default values for parameters, and conflicts with member of supertype 'WithCopy' +data class Test(val str: String): WithCopy +^ +compiler/testData/cli/jvm/progressive/nonConstValueAsVarargInAnnotation.kt:5:15: error: an annotation argument must be a compile-time constant +@Anno(value = nonConstArray) + ^ +compiler/testData/cli/jvm/progressive/valReassignmentViaBackingField.kt:3:9: error: reassignment of read-only property via backing field + field++ + ^ +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index e60511d7448..98d1a5f8427 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -397,6 +397,18 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/pluginSimple.args"); } + @TestMetadata("progressiveModeOff.args") + public void testProgressiveModeOff() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/progressiveModeOff.args"); + doJvmTest(fileName); + } + + @TestMetadata("progressiveModeOn.args") + public void testProgressiveModeOn() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/progressiveModeOn.args"); + doJvmTest(fileName); + } + @TestMetadata("returnAsWhenKey.args") public void testReturnAsWhenKey() throws Exception { runTest("compiler/testData/cli/jvm/returnAsWhenKey.args"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 292b79ec347..35ac72947b9 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -13,7 +13,8 @@ enum class LanguageFeature( val sinceVersion: LanguageVersion?, val sinceApiVersion: ApiVersion = ApiVersion.KOTLIN_1_0, val hintUrl: String? = null, - val defaultState: State = State.ENABLED + val defaultState: State = State.ENABLED, + val enabledInProgressiveMode: Boolean = false ) { // Note: names of these entries are also used in diagnostic tests and in user-visible messages (see presentableText below) TypeAliases(KOTLIN_1_1), @@ -56,23 +57,23 @@ enum class LanguageFeature( DefaultMethodsCallFromJava6TargetError(KOTLIN_1_2), BooleanElvisBoundSmartCasts(KOTLIN_1_3), - RestrictionOfValReassignmentViaBackingField(KOTLIN_1_3), - NestedClassesInEnumEntryShouldBeInner(KOTLIN_1_3), - ProhibitDataClassesOverridingCopy(KOTLIN_1_3), - RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes(KOTLIN_1_3), - ProhibitInnerClassesOfGenericClassExtendingThrowable(KOTLIN_1_3), - ProperVisibilityForCompanionObjectInstanceField(KOTLIN_1_3), - ProperForInArrayLoopRangeVariableAssignmentSemantic(KOTLIN_1_3), + RestrictionOfValReassignmentViaBackingField(KOTLIN_1_3, enabledInProgressiveMode = true), + NestedClassesInEnumEntryShouldBeInner(KOTLIN_1_3, enabledInProgressiveMode = true), + ProhibitDataClassesOverridingCopy(KOTLIN_1_3, enabledInProgressiveMode = true), + RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes(KOTLIN_1_3, enabledInProgressiveMode = true), + ProhibitInnerClassesOfGenericClassExtendingThrowable(KOTLIN_1_3, enabledInProgressiveMode = true), + ProperVisibilityForCompanionObjectInstanceField(KOTLIN_1_3, enabledInProgressiveMode = true), + ProperForInArrayLoopRangeVariableAssignmentSemantic(KOTLIN_1_3, enabledInProgressiveMode = true), NestedClassesInAnnotations(KOTLIN_1_3), JvmStaticInInterface(KOTLIN_1_3), - ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion(KOTLIN_1_3), - ProhibitNonConstValuesAsVarargsInAnnotations(KOTLIN_1_3), + ProhibitVisibilityOfNestedClassifiersFromSupertypesOfCompanion(KOTLIN_1_3, enabledInProgressiveMode = true), + ProhibitNonConstValuesAsVarargsInAnnotations(KOTLIN_1_3, enabledInProgressiveMode = true), ReleaseCoroutines(KOTLIN_1_3), ReadDeserializedContracts(KOTLIN_1_3), UseReturnsEffect(KOTLIN_1_3), UseCallsInPlaceEffect(KOTLIN_1_3), AllowContractsForCustomFunctions(KOTLIN_1_3), - ProhibitLocalAnnotations(KOTLIN_1_3), + ProhibitLocalAnnotations(KOTLIN_1_3, enabledInProgressiveMode = true), StrictJavaNullabilityAssertions(sinceVersion = null, defaultState = State.DISABLED), ProperIeee754Comparisons(sinceVersion = null, defaultState = State.DISABLED),