From 38a67f3d301dd8420571ad782b569e9e6030f79d Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Fri, 15 Sep 2023 19:29:44 +0200 Subject: [PATCH] [KLIB] Use `-Xmetadata-klib` to produce metadata KLIBs With this change a new `-Xmetadata-klib` CLI flag becomes the preferable way to instruct K2MetadataCompiler to produce metadata KLIBs. The old `-Xexpect-actual-linker` flag still works for K2MetadataCompiler, but that would last just for a short transition period until the necessary changes are made in the Gradle plugin. The K2NativeCompiler does not work anymore with `-Xexpect-actual-linker` and respects only the `-Xmetadata-klib` flag. This is not an issue since the Gradle plugin anyway supplies both flags for Native metadata compilations. ^KT-61136 --- .../common/arguments/CommonCompilerArguments.kt | 2 +- .../kotlin/cli/metadata/K2MetadataCompiler.kt | 6 ++++-- ...stractCompileKotlinAgainstCustomBinariesTest.kt | 4 ++-- .../backend/konan/driver/phases/Serializer.kt | 14 ++++++++------ 4 files changed, 15 insertions(+), 11 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 706f16506f4..ddbf13375bb 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 @@ -818,7 +818,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) } put(AnalysisFlags.optIn, useExperimentalFqNames + optIn?.toList().orEmpty()) - put(AnalysisFlags.skipExpectedActualDeclarationChecker, expectActualLinker) + put(AnalysisFlags.skipExpectedActualDeclarationChecker, expectActualLinker || metadataKlib) // TODO (KT-61136): drop `expectActualLinker` later, after the appropriate changes in the Gradle plugin 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/metadata/K2MetadataCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt index 2b4f5f02be1..03d5f76980c 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt @@ -101,7 +101,8 @@ class K2MetadataCompiler : CLICompiler() { val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.METADATA_CONFIG_FILES) - val mode = if(arguments.expectActualLinker) "KLib" else "metadata" + // 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 sourceFiles = environment.getSourceFiles() performanceManager.notifyCompilerInitialized(sourceFiles.size, environment.countLinesOfCode(sourceFiles), "$mode mode for $moduleName module") @@ -120,7 +121,8 @@ class K2MetadataCompiler : CLICompiler() { val useFir = configuration.getBoolean(CommonConfigurationKeys.USE_FIR) val metadataSerializer = when { useFir -> FirMetadataSerializer(configuration, environment) - arguments.expectActualLinker -> K2MetadataKlibSerializer(configuration, environment) + // TODO (KT-61136): drop `expectActualLinker` later, after the appropriate changes in the Gradle plugin + arguments.expectActualLinker || arguments.metadataKlib -> K2MetadataKlibSerializer(configuration, environment) else -> MetadataSerializer(configuration, environment, dependOnOldBuiltIns = true) } metadataSerializer.analyzeAndSerialize() diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt index e7a09cb9ecb..33c67bfb140 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt @@ -686,14 +686,14 @@ abstract class AbstractCompileKotlinAgainstCustomBinariesTest : AbstractKotlinCo fun testAnonymousObjectTypeMetadataKlib() { val klibLibrary = compileCommonLibrary( libraryName = "library", - listOf("-Xexpect-actual-linker"), + listOf("-Xmetadata-klib"), ) compileKotlin( "anonymousObjectTypeMetadata.kt", tmpdir, listOf(klibLibrary), K2MetadataCompiler(), - listOf("-Xexpect-actual-linker") + listOf("-Xmetadata-klib") ) } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt index 02ac7da4634..ac9089cd554 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt @@ -36,7 +36,6 @@ internal val SerializerPhase = createSimpleNamedCompilerPhase SerializerOutput(null, null, null, emptyList()) } ) { context: PhaseContext, input: SerializerInput -> val config = context.config - val expectActualLinker = config.configuration.get(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER) ?: false val messageLogger = config.configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None val relativePathBase = config.configuration.get(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES) ?: emptyList() val normalizeAbsolutePaths = config.configuration.get(CommonConfigurationKeys.KLIB_NORMALIZE_ABSOLUTE_PATH) ?: false @@ -55,11 +54,14 @@ internal val SerializerPhase = createSimpleNamedCompilerPhase