From 78a962f6d252317e60b7a61079cb33808b5644dc Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Fri, 15 Sep 2023 19:56:00 +0200 Subject: [PATCH] [KLIB] Deprecate `-Xexpect-actual-linker` CLI argument This argument has been finally superseded by `-Xmetadata-klib`. ^KT-61136 --- .../CommonCompilerArgumentsCopyGenerated.kt | 1 - .../arguments/CommonCompilerArguments.kt | 16 +- .../jetbrains/kotlin/cli/common/arguments.kt | 1 - .../kotlin/cli/metadata/K2MetadataCompiler.kt | 6 +- .../kotlin/config/CommonConfigurationKeys.kt | 3 - compiler/testData/cli/js/jsExtraHelp.out | 1 - compiler/testData/cli/jvm/extraHelp.out | 1 - .../anonymousObjectTypeMetadata.kt | 13 ++ .../library/privateObjects.kt | 154 ++++++++++++++++++ .../output.fir.txt | 11 ++ .../output.txt | 11 ++ ...tCompileKotlinAgainstCustomBinariesTest.kt | 39 +++-- .../CompilerArgumentsContentProspectorTest.kt | 1 - 13 files changed, 218 insertions(+), 40 deletions(-) create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/library/privateObjects.kt create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.fir.txt create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.txt diff --git a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt index 649099dc45d..2719ee3ed61 100644 --- a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt +++ b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt @@ -32,7 +32,6 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile to.enableBuilderInference = from.enableBuilderInference to.enableSignatureClashChecks = from.enableSignatureClashChecks to.expectActualClasses = from.expectActualClasses - to.expectActualLinker = from.expectActualLinker to.experimental = from.experimental?.copyOf() to.explicitApi = from.explicitApi to.extendedCompilerChecks = from.extendedCompilerChecks 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 ddbf13375bb..8534390b5b9 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 @@ -574,7 +574,8 @@ abstract class CommonCompilerArguments : CommonToolArguments() { @Argument( value = "-Xmetadata-klib", - description = "Produce a klib that only contains the declarations metadata" + description = "Produce a klib that only contains the declarations metadata", + deprecatedName = "-Xexpect-actual-linker" ) var metadataKlib: Boolean = false set(value) { @@ -582,17 +583,6 @@ abstract class CommonCompilerArguments : CommonToolArguments() { field = value } - /** TODO: replace by [metadataKlib] */ - @Argument( - value = "-Xexpect-actual-linker", - description = "Enable experimental expect/actual linker" - ) - var expectActualLinker = false - set(value) { - checkFrozen() - field = value - } - @Argument(value = "-Xdisable-default-scripting-plugin", description = "Do not enable scripting plugin by default") var disableDefaultScriptingPlugin = false set(value) { @@ -818,7 +808,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) } put(AnalysisFlags.optIn, useExperimentalFqNames + optIn?.toList().orEmpty()) - put(AnalysisFlags.skipExpectedActualDeclarationChecker, expectActualLinker || metadataKlib) // TODO (KT-61136): drop `expectActualLinker` later, after the appropriate changes in the Gradle plugin + put(AnalysisFlags.skipExpectedActualDeclarationChecker, metadataKlib) put(AnalysisFlags.explicitApiVersion, apiVersion != null) put(AnalysisFlags.allowResultReturnType, allowResultReturnType) ExplicitApiMode.fromString(explicitApi)?.also { put(AnalysisFlags.explicitApiMode, it) } ?: collector.report( diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt index 07020f2dcac..dec77177b26 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt @@ -28,7 +28,6 @@ fun CompilerConfiguration.setupCommonArguments( put(CommonConfigurationKeys.DISABLE_INLINE, arguments.noInline) put(CommonConfigurationKeys.USE_FIR_EXTENDED_CHECKERS, arguments.useFirExtendedCheckers) - put(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER, arguments.expectActualLinker) put(CommonConfigurationKeys.METADATA_KLIB, arguments.metadataKlib) putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot) put(CommonConfigurationKeys.REPORT_OUTPUT_FILES, arguments.reportOutputFiles) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt index 03d5f76980c..7314f49394e 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt @@ -101,8 +101,7 @@ class K2MetadataCompiler : CLICompiler() { val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.METADATA_CONFIG_FILES) - // TODO (KT-61136): drop `expectActualLinker` later, after the appropriate changes in the Gradle plugin - val mode = if (arguments.expectActualLinker || arguments.metadataKlib) "KLib" else "metadata" + val mode = if (arguments.metadataKlib) "KLib" else "metadata" val sourceFiles = environment.getSourceFiles() performanceManager.notifyCompilerInitialized(sourceFiles.size, environment.countLinesOfCode(sourceFiles), "$mode mode for $moduleName module") @@ -121,8 +120,7 @@ class K2MetadataCompiler : CLICompiler() { val useFir = configuration.getBoolean(CommonConfigurationKeys.USE_FIR) val metadataSerializer = when { useFir -> FirMetadataSerializer(configuration, environment) - // TODO (KT-61136): drop `expectActualLinker` later, after the appropriate changes in the Gradle plugin - arguments.expectActualLinker || arguments.metadataKlib -> K2MetadataKlibSerializer(configuration, environment) + arguments.metadataKlib -> K2MetadataKlibSerializer(configuration, environment) else -> MetadataSerializer(configuration, environment, dependOnOldBuiltIns = true) } metadataSerializer.analyzeAndSerialize() diff --git a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt index ad4f30d07e2..f3fbbee2604 100644 --- a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt +++ b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt @@ -60,9 +60,6 @@ object CommonConfigurationKeys { @JvmField val HMPP_MODULE_STRUCTURE = CompilerConfigurationKey.create("HMPP module structure") - @JvmField - val EXPECT_ACTUAL_LINKER = CompilerConfigurationKey.create("Experimental expect/actual linker") - @JvmField val METADATA_KLIB = CompilerConfigurationKey.create("Produce metadata klib") diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index 5708eab688c..cef43930617 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -89,7 +89,6 @@ where advanced options include: Enable the checks on uniqueness of signatures -Xexpect-actual-classes 'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. Kotlin reports a warning every time you use them. You can use this flag to mute the warning. - -Xexpect-actual-linker Enable experimental expect/actual linker -Xexplicit-api={strict|warning|disable} Force compiler to report errors on all public API declarations without explicit visibility or return type. Use 'warning' level to issue warnings instead of errors. diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index de96118afa4..62324eda18e 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -180,7 +180,6 @@ where advanced options include: Enable the checks on uniqueness of signatures -Xexpect-actual-classes 'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. Kotlin reports a warning every time you use them. You can use this flag to mute the warning. - -Xexpect-actual-linker Enable experimental expect/actual linker -Xexplicit-api={strict|warning|disable} Force compiler to report errors on all public API declarations without explicit visibility or return type. Use 'warning' level to issue warnings instead of errors. diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt new file mode 100644 index 00000000000..67f75708502 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt @@ -0,0 +1,13 @@ +package test + +import lib.* + +val w = W() +val v1 = fn() +val v2 = O.o() +val v3 = w.w() + +// private +val e1 = o3 +val e2 = w.o7 +val e3 = O.o10 diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/library/privateObjects.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/library/privateObjects.kt new file mode 100644 index 00000000000..55d262d7c5b --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/library/privateObjects.kt @@ -0,0 +1,154 @@ +package lib + +interface I1 { + fun i1() {} +} + +interface I2 { + fun i2() {} +} + +interface I3 : I2, I1 + +open class C { + fun c() {} +} + +open class G { + fun g() {} +} + +private val o1 = object { fun foo() {} } +private val o2 = object : I1 {} +private val o3 = object : I1, I2 {} +private val o4 = object : I3 {} +private val o5 = object : C() {} +private val o6 = object : C(), I1, I2 {} +private val o7 = object : C(), I3 {} +private val o8 = object : G() {} +private val o9 = object : G(), I1, I2 {} +private val o10 = object : G(), I3 {} + +private val o11 = object { + inner class D { + fun df() {} + } + fun d(): D = D() +}.d() + +private val o12 = { + class L { + fun l() {} + } + L() +}() + +private val o13 = { + class L { + inner class L1 { + inner class L2 { + fun l2() {} + } + } + } + + L().L1().L2() +}() + +fun fn() { + o1.foo() + o2.i1() + o3.i1() + o3.i2() + o4.i1() + o4.i2() + o5.c() + o6.c() + o6.i1() + o6.i2() + o7.c() + o7.i1() + o7.i2() + o8.g() + o9.g() + o9.i1() + o9.i2() + o10.g() + o10.i1() + o10.i2() + o11.df() + o12.l() + o13.l2() +} + +class W { + private val o1 = object { fun foo() {} } + private val o2 = object : I1 {} + private val o3 = object : I1, I2 {} + private val o4 = object : I3 {} + private val o5 = object : C() {} + private val o6 = object : C(), I1, I2 {} + private val o7 = object : C(), I3 {} + private val o8 = object : G() {} + private val o9 = object : G(), I1, I2 {} + private val o10 = object : G(), I3 {} + + fun w() { + o1.foo() + o2.i1() + o3.i1() + o3.i2() + o4.i1() + o4.i2() + o5.c() + o6.c() + o6.i1() + o6.i2() + o7.c() + o7.i1() + o7.i2() + o8.g() + o9.g() + o9.i1() + o9.i2() + o10.g() + o10.i1() + o10.i2() + } +} + +object O { + private val o1 = object { fun foo() {} } + private val o2 = object : I1 {} + private val o3 = object : I1, I2 {} + private val o4 = object : I3 {} + private val o5 = object : C() {} + private val o6 = object : C(), I1, I2 {} + private val o7 = object : C(), I3 {} + private val o8 = object : G() {} + private val o9 = object : G(), I1, I2 {} + private val o10 = object : G(), I3 {} + + fun o() { + o1.foo() + o2.i1() + o3.i1() + o3.i2() + o4.i1() + o4.i2() + o5.c() + o6.c() + o6.i1() + o6.i2() + o7.c() + o7.i1() + o7.i2() + o8.g() + o9.g() + o9.i1() + o9.i2() + o10.g() + o10.i1() + o10.i2() + } +} diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.fir.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.fir.txt new file mode 100644 index 00000000000..6d7cef86af6 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.fir.txt @@ -0,0 +1,11 @@ +warning: argument -Xexpect-actual-linker is deprecated. Please use -Xmetadata-klib instead +compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt:11:10: error: cannot access 'val o3: Any': it is private in file. +val e1 = o3 + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt:12:12: error: cannot access 'val o7: Any': it is private in 'lib/W'. +val e2 = w.o7 + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt:13:12: error: cannot access 'val o10: Any': it is private in 'lib/O'. +val e3 = O.o10 + ^ +COMPILATION_ERROR diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.txt new file mode 100644 index 00000000000..e4651e8e662 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/output.txt @@ -0,0 +1,11 @@ +warning: argument -Xexpect-actual-linker is deprecated. Please use -Xmetadata-klib instead +compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt:11:10: error: cannot access 'o3': it is private in file +val e1 = o3 + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt:12:12: error: cannot access 'o7': it is private in 'W' +val e2 = w.o7 + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/anonymousObjectTypeMetadataKlibWithOldCLIKey/anonymousObjectTypeMetadata.kt:13:12: error: cannot access 'o10': it is private in 'O' +val e3 = O.o10 + ^ +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt index 6165fed7759..023ef4fcafb 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt @@ -706,29 +706,38 @@ abstract class AbstractCompileKotlinAgainstCustomBinariesTest : AbstractKotlinCo assertEquals("Output:\n$output", ExitCode.COMPILATION_ERROR, exitCode) } - fun testAnonymousObjectTypeMetadata() { + fun testAnonymousObjectTypeMetadata() = doTestAnonymousObjectTypeMetadata() + + fun testAnonymousObjectTypeMetadataKlib() = doTestAnonymousObjectTypeMetadata(listOf("-Xmetadata-klib")) + + /** + * This test does exactly the same as [testAnonymousObjectTypeMetadataKlib] but using the old (now deprecated) + * CLI argument `-Xexpect-actual-linker` instead of its successor `-Xmetadata-klib`. + * + * The test is needed only to check that the old CLI argument still works as needed. + */ + fun testAnonymousObjectTypeMetadataKlibWithOldCLIKey() = doTestAnonymousObjectTypeMetadata(listOf("-Xexpect-actual-linker")) { output -> + output.lines().filterNot { "argument -Xexpect-actual-linker is deprecated" in it }.joinToString("\n") + } + + private fun doTestAnonymousObjectTypeMetadata( + extraCommandLineArguments: List = emptyList(), + filterOutput: (String) -> String = { output -> output } + ) { val library = compileCommonLibrary( libraryName = "library", + additionalOptions = extraCommandLineArguments, + checkKotlinOutput = { output -> + assertEquals(normalizeOutput("" to ExitCode.OK), filterOutput(output)) + } ) + compileKotlin( "anonymousObjectTypeMetadata.kt", tmpdir, listOf(library), K2MetadataCompiler(), - ) - } - - fun testAnonymousObjectTypeMetadataKlib() { - val klibLibrary = compileCommonLibrary( - libraryName = "library", - listOf("-Xmetadata-klib"), - ) - compileKotlin( - "anonymousObjectTypeMetadata.kt", - tmpdir, - listOf(klibLibrary), - K2MetadataCompiler(), - listOf("-Xmetadata-klib") + additionalOptions = extraCommandLineArguments ) } diff --git a/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt b/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt index cdec92d17ef..72c85453557 100644 --- a/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt +++ b/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt @@ -103,7 +103,6 @@ class CompilerArgumentsContentProspectorTest { CommonCompilerArguments::disableUltraLightClasses, CommonCompilerArguments::useMixedNamedArguments, CommonCompilerArguments::metadataKlib, - CommonCompilerArguments::expectActualLinker, CommonCompilerArguments::extendedCompilerChecks, CommonCompilerArguments::disableDefaultScriptingPlugin, CommonCompilerArguments::inferenceCompatibility,