From d8417fd622749bdcef028e1d7f75d992725b0765 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 7 Jul 2021 12:51:36 +0300 Subject: [PATCH] Introduce -opt-in stable compiler option instead of -Xopt-in #KT-47099 Fixed --- .../arguments/CommonCompilerArguments.kt | 24 ++++++++++++++++--- .../diagnostics/FirDefaultErrorMessages.kt | 2 +- compiler/testData/cli/js/jsHelp.out | 1 + ...lAndUseExperimentalWithSameAnnotation.args | 6 +++-- .../cli/jvm/experimentalDeprecated.args | 9 ++++--- .../jvm/experimentalDeprecatedWarning.args | 5 +++- .../cli/jvm/experimentalDeprecatedWarning.out | 3 ++- .../cli/jvm/experimentalIsNotAnnotation.args | 3 ++- .../cli/jvm/experimentalIsNotMarker.args | 3 ++- .../testData/cli/jvm/experimentalNested.args | 3 ++- .../cli/jvm/experimentalUnresolved.args | 7 ++++-- compiler/testData/cli/jvm/help.out | 1 + ...entalWithoutExplicitImportCommandLine.args | 3 ++- .../optionalExpectation/common.kt | 2 +- .../optionalExpectationIncorrectUse/common.kt | 2 +- .../experimental/experimentalUnused.kt | 2 +- 16 files changed, 56 insertions(+), 20 deletions(-) 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 ed49a397c04..3b69f0055b6 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 @@ -83,6 +83,15 @@ abstract class CommonCompilerArguments : CommonToolArguments() { @Argument(value = "-P", valueDescription = PLUGIN_OPTION_FORMAT, description = "Pass an option to a plugin") var pluginOptions: Array? by FreezableVar(null) + @Argument( + value = "-opt-in", + // Uncomment after deletion of optInDeprecated + // deprecatedName = "-Xopt-in", + valueDescription = "", + description = "Enable usages of API that requires opt-in with an opt-in requirement marker with the given fully qualified name" + ) + var optIn: Array? by FreezableVar(null) + // Advanced options @Argument(value = "-Xno-inline", description = "Disable method inlining") @@ -172,12 +181,13 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) var useExperimental: Array? by FreezableVar(null) + // NB: we have to keep this flag for some time due to bootstrapping problems @Argument( value = "-Xopt-in", valueDescription = "", description = "Enable usages of API that requires opt-in with an opt-in requirement marker with the given fully qualified name" ) - var optIn: Array? by FreezableVar(null) + var optInDeprecated: Array? by FreezableVar(null) @Argument( value = "-Xproper-ieee754-comparisons", @@ -384,9 +394,17 @@ abstract class CommonCompilerArguments : CommonToolArguments() { } val useExperimentalFqNames = useExperimental?.toList().orEmpty() if (useExperimentalFqNames.isNotEmpty()) { - collector.report(WARNING, "'-Xuse-experimental' is deprecated and will be removed in a future release") + collector.report( + WARNING, "'-Xuse-experimental' is deprecated and will be removed in a future release, please use -opt-in instead" + ) } - put(AnalysisFlags.useExperimental, useExperimentalFqNames + optIn?.toList().orEmpty()) + val optInDeprecatedFqNames = optInDeprecated?.toList().orEmpty() + if (optInDeprecatedFqNames.isNotEmpty()) { + collector.report( + WARNING, "'-Xopt-in' is deprecated and will be removed in a future release, please use -opt-in instead" + ) + } + put(AnalysisFlags.useExperimental, useExperimentalFqNames + optInDeprecatedFqNames + optIn?.toList().orEmpty()) put(AnalysisFlags.expectActualLinker, expectActualLinker) put(AnalysisFlags.explicitApiVersion, apiVersion != null) put(AnalysisFlags.allowResultReturnType, allowResultReturnType) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index 1d6b9960dd9..7bc3639b243 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -596,7 +596,7 @@ class FirDefaultErrorMessages { map.put(EXPERIMENTAL_OVERRIDE, "{1}", TO_STRING, STRING) map.put(EXPERIMENTAL_OVERRIDE_ERROR, "{1}", TO_STRING, STRING) - map.put(EXPERIMENTAL_IS_NOT_ENABLED, "This class can only be used with the compiler argument '-Xopt-in=kotlin.RequiresOptIn'") + map.put(EXPERIMENTAL_IS_NOT_ENABLED, "This class can only be used with the compiler argument '-opt-in=kotlin.RequiresOptIn'") map.put(EXPERIMENTAL_CAN_ONLY_BE_USED_AS_ANNOTATION, "This class can only be used as an annotation") map.put( EXPERIMENTAL_MARKER_CAN_ONLY_BE_USED_AS_ANNOTATION_OR_ARGUMENT_IN_USE_EXPERIMENTAL, diff --git a/compiler/testData/cli/js/jsHelp.out b/compiler/testData/cli/js/jsHelp.out index bd1d1172116..8743f2a583b 100644 --- a/compiler/testData/cli/js/jsHelp.out +++ b/compiler/testData/cli/js/jsHelp.out @@ -21,6 +21,7 @@ where possible options include: -help (-h) Print a synopsis of standard options -kotlin-home Path to the home directory of Kotlin compiler used for discovery of runtime libraries -language-version Provide source compatibility with the specified version of Kotlin + -opt-in Enable usages of API that requires opt-in with an opt-in requirement marker with the given fully qualified name -P plugin::= Pass an option to a plugin -progressive Enable progressive compiler mode. diff --git a/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args b/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args index f613672c9c4..c545ab4b8f0 100644 --- a/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args +++ b/compiler/testData/cli/jvm/experimentalAndUseExperimentalWithSameAnnotation.args @@ -1,6 +1,8 @@ $TESTDATA_DIR$/experimentalAndUseExperimentalWithSameAnnotation.kt -d $TEMP_DIR$ --Xopt-in=kotlin.RequiresOptIn +-opt-in +kotlin.RequiresOptIn +-opt-in +org.test.ExperimentalAPI -Xexperimental=org.test.ExperimentalAPI --Xopt-in=org.test.ExperimentalAPI diff --git a/compiler/testData/cli/jvm/experimentalDeprecated.args b/compiler/testData/cli/jvm/experimentalDeprecated.args index 403c209f09a..cdc79254f58 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecated.args +++ b/compiler/testData/cli/jvm/experimentalDeprecated.args @@ -1,8 +1,11 @@ $TESTDATA_DIR$/experimentalDeprecated.kt -d $TEMP_DIR$ --Xopt-in=kotlin.RequiresOptIn +-opt-in +kotlin.RequiresOptIn -Xexperimental=org.test.Error1 -Xexperimental=org.test.Hidden1 --Xopt-in=org.test.Error2 --Xopt-in=org.test.Hidden2 +-opt-in +org.test.Error2 +-opt-in +org.test.Hidden2 diff --git a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args index 52cd157f3c9..97c26bd17a7 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args +++ b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args @@ -2,6 +2,9 @@ $TESTDATA_DIR$/experimentalDeprecatedWarning.kt -d $TEMP_DIR$ -Xopt-in=kotlin.RequiresOptIn --Xopt-in=org.test.Warning1 +-opt-in +kotlin.RequiresOptIn +-opt-in +org.test.Warning1 -Xexperimental=org.test.Warning2 -Xuse-experimental=org.test.OneMore diff --git a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out index 4b200d596cb..c98cdfea8cd 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out +++ b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.out @@ -1,5 +1,6 @@ warning: '-Xexperimental' is deprecated and will be removed in a future release -warning: '-Xuse-experimental' is deprecated and will be removed in a future release +warning: '-Xuse-experimental' is deprecated and will be removed in a future release, please use -opt-in instead +warning: '-Xopt-in' is deprecated and will be removed in a future release, please use -opt-in instead warning: opt-in requirement marker org.test.Warning2 is deprecated. Warning2 warning: opt-in requirement marker org.test.Warning1 is deprecated. Warning1 OK diff --git a/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args b/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args index 0402de43742..da59f5862de 100644 --- a/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args +++ b/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args @@ -2,4 +2,5 @@ $TESTDATA_DIR$/experimentalIsNotAnnotation.kt -d $TEMP_DIR$ -Xexperimental=org.test.NotAnAnnotation1 --Xopt-in=org.test.NotAnAnnotation2 +-opt-in +org.test.NotAnAnnotation2 diff --git a/compiler/testData/cli/jvm/experimentalIsNotMarker.args b/compiler/testData/cli/jvm/experimentalIsNotMarker.args index e87a4c10781..b674e93e296 100644 --- a/compiler/testData/cli/jvm/experimentalIsNotMarker.args +++ b/compiler/testData/cli/jvm/experimentalIsNotMarker.args @@ -2,4 +2,5 @@ $TESTDATA_DIR$/experimentalIsNotMarker.kt -d $TEMP_DIR$ -Xexperimental=org.test.NotAMarker1 --Xopt-in=org.test.NotAMarker2 +-opt-in +org.test.NotAMarker2 diff --git a/compiler/testData/cli/jvm/experimentalNested.args b/compiler/testData/cli/jvm/experimentalNested.args index 38403dab00e..3ccc12cfde5 100644 --- a/compiler/testData/cli/jvm/experimentalNested.args +++ b/compiler/testData/cli/jvm/experimentalNested.args @@ -1,5 +1,6 @@ $TESTDATA_DIR$/experimentalNested.kt -d $TEMP_DIR$ --Xopt-in=kotlin.RequiresOptIn +-opt-in +kotlin.RequiresOptIn -Xexperimental=org.test.Outer.Nested diff --git a/compiler/testData/cli/jvm/experimentalUnresolved.args b/compiler/testData/cli/jvm/experimentalUnresolved.args index 6738efe980c..aa120426dab 100644 --- a/compiler/testData/cli/jvm/experimentalUnresolved.args +++ b/compiler/testData/cli/jvm/experimentalUnresolved.args @@ -1,6 +1,9 @@ $TESTDATA_DIR$/experimentalUnresolved.kt -d $TEMP_DIR$ --Xopt-in=org.test.Unresolved1 +-opt-in +org.test.Unresolved1 +-opt-in +org.test.Unresolved3 -Xexperimental=org.test.Unresolved2 --Xopt-in=org.test.Unresolved3 + diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index a637d1cf697..d2dadec000d 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -19,6 +19,7 @@ where possible options include: -help (-h) Print a synopsis of standard options -kotlin-home Path to the home directory of Kotlin compiler used for discovery of runtime libraries -language-version Provide source compatibility with the specified version of Kotlin + -opt-in Enable usages of API that requires opt-in with an opt-in requirement marker with the given fully qualified name -P plugin::= Pass an option to a plugin -progressive Enable progressive compiler mode. diff --git a/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutExplicitImportCommandLine.args b/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutExplicitImportCommandLine.args index 809eab58e9b..1a7f661be7a 100644 --- a/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutExplicitImportCommandLine.args +++ b/compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutExplicitImportCommandLine.args @@ -3,4 +3,5 @@ $TESTDATA_DIR$/useDeclarationThatWasExperimentalWithoutMarker.kt $TEMP_DIR$ -language-version 1.3 --Xopt-in=kotlin.ExperimentalStdlibApi \ No newline at end of file +-opt-in +kotlin.ExperimentalStdlibApi \ No newline at end of file diff --git a/compiler/testData/multiplatform/optionalExpectation/common.kt b/compiler/testData/multiplatform/optionalExpectation/common.kt index 48c97a027bd..db35a63ac8e 100644 --- a/compiler/testData/multiplatform/optionalExpectation/common.kt +++ b/compiler/testData/multiplatform/optionalExpectation/common.kt @@ -1,5 +1,5 @@ // WITH_RUNTIME -// ADDITIONAL_COMPILER_ARGUMENTS: -Xopt-in=kotlin.ExperimentalMultiplatform +// ADDITIONAL_COMPILER_ARGUMENTS: -opt-in=kotlin.ExperimentalMultiplatform @OptionalExpectation expect annotation class A() diff --git a/compiler/testData/multiplatform/optionalExpectationIncorrectUse/common.kt b/compiler/testData/multiplatform/optionalExpectationIncorrectUse/common.kt index 709dd725e5f..2209a56aed0 100644 --- a/compiler/testData/multiplatform/optionalExpectationIncorrectUse/common.kt +++ b/compiler/testData/multiplatform/optionalExpectationIncorrectUse/common.kt @@ -1,5 +1,5 @@ // WITH_RUNTIME -// ADDITIONAL_COMPILER_ARGUMENTS: -Xopt-in=kotlin.ExperimentalMultiplatform +// ADDITIONAL_COMPILER_ARGUMENTS: -opt-in=kotlin.ExperimentalMultiplatform @OptionalExpectation expect annotation class A() diff --git a/idea/testData/quickfix/experimental/experimentalUnused.kt b/idea/testData/quickfix/experimental/experimentalUnused.kt index 581100aec6c..7f9454dd4ae 100644 --- a/idea/testData/quickfix/experimental/experimentalUnused.kt +++ b/idea/testData/quickfix/experimental/experimentalUnused.kt @@ -1,5 +1,5 @@ // "Safe delete 'Marker'" "false" -// COMPILER_ARGUMENTS: -Xopt-in=kotlin.RequiresOptIn -Xopt-in=test.Marker +// COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn -opt-in=test.Marker // WITH_RUNTIME // ACTION: Rename file to Marker.kt // TOOL: org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection