From 848c88b1a5cbb8ba85619e6dd2ddd6a0a04c2ac3 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Fri, 15 Sep 2023 18:53:28 +0200 Subject: [PATCH] [KLIB] Lift up `-Xmetadata-klib` CLI key from Native to Common args This is a precondition for obsoleting and finally removing `-Xexpect-actual-linker` CLI key, which became useless since the removal of ExpectActualTable. ^KT-61136 --- .../arguments/CommonCompilerArgumentsCopyGenerated.kt | 1 + .../K2NativeCompilerArgumentsCopyGenerated.kt | 1 - .../cli/common/arguments/CommonCompilerArguments.kt | 11 +++++++++++ .../cli/common/arguments/K2NativeCompilerArguments.kt | 3 --- .../src/org/jetbrains/kotlin/cli/common/arguments.kt | 1 + .../kotlin/config/CommonConfigurationKeys.kt | 3 +++ compiler/testData/cli/js/jsExtraHelp.out | 1 + compiler/testData/cli/jvm/extraHelp.out | 1 + .../test/CompilerArgumentsContentProspectorTest.kt | 1 + .../org/jetbrains/kotlin/backend/konan/FirFrontend.kt | 2 +- .../org/jetbrains/kotlin/backend/konan/KonanConfig.kt | 2 +- .../kotlin/backend/konan/KonanConfigurationKeys.kt | 2 -- .../kotlin/backend/konan/SetupConfiguration.kt | 1 - .../backend/konan/driver/DynamicCompilerDriver.kt | 7 ++++--- 14 files changed, 25 insertions(+), 12 deletions(-) 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 2fbc1f857d8..649099dc45d 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 @@ -48,6 +48,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile to.languageVersion = from.languageVersion to.legacySmartCastAfterTry = from.legacySmartCastAfterTry to.listPhases = from.listPhases + to.metadataKlib = from.metadataKlib to.metadataVersion = from.metadataVersion to.multiPlatform = from.multiPlatform to.newInference = from.newInference diff --git a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArgumentsCopyGenerated.kt b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArgumentsCopyGenerated.kt index 0a402a96c4c..032f64559e9 100644 --- a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArgumentsCopyGenerated.kt +++ b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArgumentsCopyGenerated.kt @@ -63,7 +63,6 @@ fun copyK2NativeCompilerArguments(from: K2NativeCompilerArguments, to: K2NativeC to.makePerFileCache = from.makePerFileCache to.manifestFile = from.manifestFile to.memoryModel = from.memoryModel - to.metadataKlib = from.metadataKlib to.moduleName = from.moduleName to.nativeLibraries = from.nativeLibraries?.copyOf() to.noObjcGenerics = from.noObjcGenerics 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 7cf50cd757e..706f16506f4 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 @@ -572,6 +572,17 @@ abstract class CommonCompilerArguments : CommonToolArguments() { field = value } + @Argument( + value = "-Xmetadata-klib", + description = "Produce a klib that only contains the declarations metadata" + ) + var metadataKlib: Boolean = false + set(value) { + checkFrozen() + field = value + } + + /** TODO: replace by [metadataKlib] */ @Argument( value = "-Xexpect-actual-linker", description = "Enable experimental expect/actual linker" diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt index e52bc25caa7..a76f8734951 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt @@ -369,9 +369,6 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { @Argument(value="-Xallocator", valueDescription = "std | mimalloc | custom", description = "Allocator used in runtime") var allocator: String? = null - @Argument(value = "-Xmetadata-klib", description = "Produce a klib that only contains the declarations metadata") - var metadataKlib: Boolean = false - @Argument( value = "-Xheader-klib-path", description = "Save a klib that only contains the public abi to the given path" 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 6761142ad92..07020f2dcac 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt @@ -29,6 +29,7 @@ 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) put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, incrementalCompilationIsEnabled(arguments)) diff --git a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt index 1f733996752..ad4f30d07e2 100644 --- a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt +++ b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt @@ -63,6 +63,9 @@ object CommonConfigurationKeys { @JvmField val EXPECT_ACTUAL_LINKER = CompilerConfigurationKey.create("Experimental expect/actual linker") + @JvmField + val METADATA_KLIB = CompilerConfigurationKey.create("Produce metadata klib") + @JvmField val USE_FIR_EXTENDED_CHECKERS = CompilerConfigurationKey.create("fir extended checkers") diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index c92cfefef80..5708eab688c 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -109,6 +109,7 @@ where advanced options include: -Xintellij-plugin-root= Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found -Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block -Xlist-phases List backend phases + -Xmetadata-klib Produce a klib that only contains the declarations metadata -Xmetadata-version Change metadata version of the generated binary files -Xmulti-platform Enable experimental language support for multi-platform projects -Xnew-inference Enable new experimental generic type inference algorithm diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index cc9a9fea9cc..de96118afa4 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -200,6 +200,7 @@ where advanced options include: -Xintellij-plugin-root= Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found -Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block -Xlist-phases List backend phases + -Xmetadata-klib Produce a klib that only contains the declarations metadata -Xmetadata-version Change metadata version of the generated binary files -Xmulti-platform Enable experimental language support for multi-platform projects -Xnew-inference Enable new experimental generic type inference algorithm diff --git a/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt b/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt index 95231863888..cdec92d17ef 100644 --- a/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt +++ b/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt @@ -102,6 +102,7 @@ class CompilerArgumentsContentProspectorTest { CommonCompilerArguments::useFirExtendedCheckers, CommonCompilerArguments::disableUltraLightClasses, CommonCompilerArguments::useMixedNamedArguments, + CommonCompilerArguments::metadataKlib, CommonCompilerArguments::expectActualLinker, CommonCompilerArguments::extendedCompilerChecks, CommonCompilerArguments::disableDefaultScriptingPlugin, diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt index 2802e3fe032..1d3965da87b 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt @@ -68,7 +68,7 @@ internal inline fun PhaseContext.firFrontend( resolvedLibraries, dependencyList, extensionRegistrars, - metadataCompilationMode = configuration.get(KonanConfigKeys.METADATA_KLIB) ?: false, + metadataCompilationMode = config.metadataKlib, isCommonSource = isCommonSource, fileBelongsToModule = fileBelongsToModule, registerExtraComponents = { diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt index fe844dcd146..07cc43613d2 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt @@ -224,7 +224,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration internal val produce get() = configuration.get(KonanConfigKeys.PRODUCE)!! - internal val metadataKlib get() = configuration.get(KonanConfigKeys.METADATA_KLIB)!! + internal val metadataKlib get() = configuration.getBoolean(CommonConfigurationKeys.METADATA_KLIB) internal val headerKlibPath get() = configuration.get(KonanConfigKeys.HEADER_KLIB) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt index 651f71aad7d..0d2e52a638e 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt @@ -73,8 +73,6 @@ class KonanConfigKeys { = CompilerConfigurationKey.create("list available targets") val MANIFEST_FILE: CompilerConfigurationKey = CompilerConfigurationKey.create("provide manifest addend file") - val METADATA_KLIB: CompilerConfigurationKey - = CompilerConfigurationKey.create("metadata klib") val HEADER_KLIB: CompilerConfigurationKey = CompilerConfigurationKey.create("path to file where header klib should be produced") val MODULE_NAME: CompilerConfigurationKey diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/SetupConfiguration.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/SetupConfiguration.kt index 27781077654..53bc3d12694 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/SetupConfiguration.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/SetupConfiguration.kt @@ -55,7 +55,6 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument val outputKind = CompilerOutputKind.valueOf( (arguments.produce ?: "program").uppercase()) put(PRODUCE, outputKind) - put(METADATA_KLIB, arguments.metadataKlib) putIfNotNull(HEADER_KLIB, arguments.headerKlibPath) arguments.libraryVersion?.let { put(LIBRARY_VERSION, it) } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/DynamicCompilerDriver.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/DynamicCompilerDriver.kt index f9f6aaa694f..6a89955b19e 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/DynamicCompilerDriver.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/DynamicCompilerDriver.kt @@ -90,7 +90,7 @@ internal class DynamicCompilerDriver : CompilerDriver() { private fun produceKlib(engine: PhaseEngine, config: KonanConfig, environment: KotlinCoreEnvironment) { val serializerOutput = if (environment.configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) - serializeKLibK2(engine, environment) + serializeKLibK2(engine, config, environment) else serializeKlibK1(engine, config, environment) serializerOutput?.let { engine.writeKlib(it) } @@ -98,18 +98,19 @@ internal class DynamicCompilerDriver : CompilerDriver() { private fun serializeKLibK2( engine: PhaseEngine, + config: KonanConfig, environment: KotlinCoreEnvironment ): SerializerOutput? { val frontendOutput = engine.runFirFrontend(environment) if (frontendOutput is FirOutput.ShouldNotGenerateCode) return null require(frontendOutput is FirOutput.Full) - return if (environment.configuration.getBoolean(KonanConfigKeys.METADATA_KLIB)) { + return if (config.metadataKlib) { engine.runFirSerializer(frontendOutput) } else { val fir2IrOutput = engine.runFir2Ir(frontendOutput) - val headerKlibPath = environment.configuration.get(KonanConfigKeys.HEADER_KLIB) + val headerKlibPath = config.headerKlibPath if (!headerKlibPath.isNullOrEmpty()) { val headerKlib = engine.runFir2IrSerializer(FirSerializerInput(fir2IrOutput, produceHeaderKlib = true)) engine.writeKlib(headerKlib, headerKlibPath)