[IR, Native] Add compiler flag for partial linkage mode

^KT-50775
This commit is contained in:
Dmitriy Dolovov
2021-12-24 14:14:11 +03:00
parent 9971ae4ffd
commit cc37934d6f
5 changed files with 27 additions and 18 deletions
@@ -386,6 +386,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
putIfNotNull(RUNTIME_LOGS, arguments.runtimeLogs)
putIfNotNull(BUNDLE_ID, parseBundleId(arguments, outputKind, configuration))
put(MEANINGFUL_BRIDGE_NAMES, arguments.meaningfulBridgeNames)
put(PARTIAL_LINKAGE, arguments.partialLinkage)
}
}
}
@@ -364,6 +364,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
@Argument(value = "-Xlazy-ir-for-caches", valueDescription = "{disable|enable}", description = "Use lazy IR for cached libraries")
var lazyIrForCaches: String? = null
@Argument(value = "-Xpartial-linkage", description = "Allow unlinked symbols")
var partialLinkage: Boolean = false
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> =
super.configureAnalysisFlags(collector, languageVersion).also {
val optInList = it[AnalysisFlags.optIn] as List<*>
@@ -6,8 +6,8 @@
package org.jetbrains.kotlin.backend.konan
import org.jetbrains.kotlin.config.CompilerConfigurationKey
import org.jetbrains.kotlin.serialization.js.ModuleKind
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.serialization.js.ModuleKind
class KonanConfigKeys {
companion object {
@@ -171,6 +171,7 @@ class KonanConfigKeys {
val RUNTIME_LOGS: CompilerConfigurationKey<String> = CompilerConfigurationKey.create("enable runtime logging")
val LAZY_IR_FOR_CACHES: CompilerConfigurationKey<Boolean> = CompilerConfigurationKey.create("use lazy IR for cached libraries")
val MEANINGFUL_BRIDGE_NAMES: CompilerConfigurationKey<Boolean> = CompilerConfigurationKey.create("enable meaningful bridge names")
val PARTIAL_LINKAGE: CompilerConfigurationKey<Boolean> = CompilerConfigurationKey.create("allows some symbols in klibs be missed")
}
}
@@ -39,10 +39,12 @@ internal fun Context.psiToIr(
useLinkerWhenProducingLibrary: Boolean
) {
// Translate AST to high level IR.
val expectActualLinker = config.configuration.get(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER)?:false
val messageLogger = config.configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None
val expectActualLinker = config.configuration[CommonConfigurationKeys.EXPECT_ACTUAL_LINKER] ?: false
val messageLogger = config.configuration[IrMessageLogger.IR_MESSAGE_LOGGER] ?: IrMessageLogger.None
val translator = Psi2IrTranslator(config.configuration.languageVersionSettings, Psi2IrConfiguration(false))
val allowUnboundSymbols = config.configuration[KonanConfigKeys.PARTIAL_LINKAGE] ?: false
val translator = Psi2IrTranslator(config.configuration.languageVersionSettings, Psi2IrConfiguration(ignoreErrors = false, allowUnboundSymbols = allowUnboundSymbols))
val generatorContext = translator.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable)
val pluginExtensions = IrGenerationExtension.getInstances(config.project)
@@ -105,19 +107,20 @@ internal fun Context.psiToIr(
).associateWith { friendModules }
KonanIrLinker(
moduleDescriptor,
translationContext,
messageLogger,
generatorContext.irBuiltIns,
symbolTable,
friendModulesMap,
forwardDeclarationsModuleDescriptor,
stubGenerator,
irProviderForCEnumsAndCStructs,
exportedDependencies,
config.cachedLibraries,
config.lazyIrForCaches,
config.userVisibleIrModulesSupport
currentModule = moduleDescriptor,
translationPluginContext = translationContext,
messageLogger = messageLogger,
builtIns = generatorContext.irBuiltIns,
symbolTable = symbolTable,
friendModules = friendModulesMap,
forwardModuleDescriptor = forwardDeclarationsModuleDescriptor,
stubGenerator = stubGenerator,
cenumsProvider = irProviderForCEnumsAndCStructs,
exportedDependencies = exportedDependencies,
cachedLibraries = config.cachedLibraries,
lazyIrForCaches = config.lazyIrForCaches,
userVisibleIrModulesSupport = config.userVisibleIrModulesSupport,
allowUnboundSymbols = allowUnboundSymbols
).also { linker ->
// context.config.librariesWithDependencies could change at each iteration.
@@ -322,7 +322,8 @@ internal class KonanIrLinker(
private val cachedLibraries: CachedLibraries,
private val lazyIrForCaches: Boolean,
override val userVisibleIrModulesSupport: UserVisibleIrModulesSupport,
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies) {
allowUnboundSymbols: Boolean
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies, allowUnboundSymbols) {
companion object {
private val C_NAMES_NAME = Name.identifier("cnames")