[IR] Partial linkage: Enable it by just passing a boolean flag to IR linker constructor

This commit is contained in:
Dmitriy Dolovov
2022-10-13 17:07:13 +02:00
committed by Space Team
parent a0fdf08b56
commit 15635482aa
16 changed files with 45 additions and 57 deletions
@@ -49,7 +49,7 @@ internal class JsIrLinkerLoader(
val moduleDescriptor = loadedModules.keys.last() val moduleDescriptor = loadedModules.keys.last()
val typeTranslator = TypeTranslatorImpl(symbolTable, compilerConfiguration.languageVersionSettings, moduleDescriptor) val typeTranslator = TypeTranslatorImpl(symbolTable, compilerConfiguration.languageVersionSettings, moduleDescriptor)
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable) val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
return JsIrLinker(null, compilerConfiguration.irMessageLogger, irBuiltIns, symbolTable, null) return JsIrLinker(null, compilerConfiguration.irMessageLogger, irBuiltIns, symbolTable, partialLinkageEnabled = false, null)
} }
private fun loadModules(): Map<ModuleDescriptor, KotlinLibrary> { private fun loadModules(): Map<ModuleDescriptor, KotlinLibrary> {
@@ -120,7 +120,7 @@ open class JvmIrCodegenFactory(
input.languageVersionSettings, input.languageVersionSettings,
Psi2IrConfiguration( Psi2IrConfiguration(
input.ignoreErrors, input.ignoreErrors,
allowUnboundSymbols = false, partialLinkageEnabled = false,
input.skipBodies input.skipBodies
), ),
messageLogger::checkNoUnboundSymbols messageLogger::checkNoUnboundSymbols
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.psi2ir
class Psi2IrConfiguration( class Psi2IrConfiguration(
val ignoreErrors: Boolean = false, val ignoreErrors: Boolean = false,
val allowUnboundSymbols: Boolean = false, val partialLinkageEnabled: Boolean = false,
val skipBodies: Boolean = false, val skipBodies: Boolean = false,
) { ) {
val generateBodies: Boolean val generateBodies: Boolean
@@ -113,7 +113,7 @@ class Psi2IrTranslator(
} }
private fun GeneratorContext.checkNoUnboundSymbols(whenDetected: () -> String) { private fun GeneratorContext.checkNoUnboundSymbols(whenDetected: () -> String) {
if (!configuration.allowUnboundSymbols) if (!configuration.partialLinkageEnabled)
checkNoUnboundSymbols(symbolTable, whenDetected()) checkNoUnboundSymbols(symbolTable, whenDetected())
} }
} }
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.overrides.FileLocalAwareLinker
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
import org.jetbrains.kotlin.backend.common.serialization.linkerissues.* import org.jetbrains.kotlin.backend.common.serialization.linkerissues.*
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupportImpl
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -30,6 +31,7 @@ abstract class KotlinIrLinker(
val builtIns: IrBuiltIns, val builtIns: IrBuiltIns,
val symbolTable: SymbolTable, val symbolTable: SymbolTable,
private val exportedDependencies: List<ModuleDescriptor>, private val exportedDependencies: List<ModuleDescriptor>,
partialLinkageEnabled: Boolean,
val symbolProcessor: IrSymbolDeserializer.(IrSymbol, IdSignature) -> IrSymbol = { s, _ -> s }, val symbolProcessor: IrSymbolDeserializer.(IrSymbol, IdSignature) -> IrSymbol = { s, _ -> s },
) : IrDeserializer, FileLocalAwareLinker { ) : IrDeserializer, FileLocalAwareLinker {
@@ -51,7 +53,11 @@ abstract class KotlinIrLinker(
private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension> private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>
open val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport get() = UnlinkedDeclarationsSupport.DISABLED val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport = if (partialLinkageEnabled)
UnlinkedDeclarationsSupportImpl(builtIns)
else
UnlinkedDeclarationsSupport.DISABLED
protected open val userVisibleIrModulesSupport: UserVisibleIrModulesSupport get() = UserVisibleIrModulesSupport.DEFAULT protected open val userVisibleIrModulesSupport: UserVisibleIrModulesSupport get() = UserVisibleIrModulesSupport.DEFAULT
fun deserializeOrReturnUnboundIrSymbolIfPartialLinkageEnabled( fun deserializeOrReturnUnboundIrSymbolIfPartialLinkageEnabled(
@@ -72,7 +78,7 @@ abstract class KotlinIrLinker(
val symbol: IrSymbol? = actualModuleDeserializer?.tryDeserializeIrSymbol(idSignature, symbolKind) val symbol: IrSymbol? = actualModuleDeserializer?.tryDeserializeIrSymbol(idSignature, symbolKind)
return symbol ?: run { return symbol ?: run {
if (unlinkedDeclarationsSupport.allowUnboundSymbols) if (unlinkedDeclarationsSupport.partialLinkageEnabled)
referenceDeserializedSymbol(symbolTable, null, symbolKind, idSignature) referenceDeserializedSymbol(symbolTable, null, symbolKind, idSignature)
else else
SignatureIdNotFoundInModuleWithDependencies( SignatureIdNotFoundInModuleWithDependencies(
@@ -164,7 +170,7 @@ abstract class KotlinIrLinker(
?: tryResolveCustomDeclaration(symbol) ?: tryResolveCustomDeclaration(symbol)
?: return null ?: return null
} catch (e: IrSymbolTypeMismatchException) { } catch (e: IrSymbolTypeMismatchException) {
if (!unlinkedDeclarationsSupport.allowUnboundSymbols) { if (!unlinkedDeclarationsSupport.partialLinkageEnabled) {
SymbolTypeMismatch(e, deserializersForModules.values, userVisibleIrModulesSupport).raiseIssue(messageLogger) SymbolTypeMismatch(e, deserializersForModules.values, userVisibleIrModulesSupport).raiseIssue(messageLogger)
} }
} }
@@ -35,7 +35,7 @@ internal inline fun <reified T : IrAnnotationContainer> checkErrorNodesAllowed(e
// N.B. Checks for absence of unbound symbols only when unbound symbols are not allowed. // N.B. Checks for absence of unbound symbols only when unbound symbols are not allowed.
fun KotlinIrLinker.checkNoUnboundSymbols(symbolTable: SymbolTable, whenDetected: String) { fun KotlinIrLinker.checkNoUnboundSymbols(symbolTable: SymbolTable, whenDetected: String) {
if (!unlinkedDeclarationsSupport.allowUnboundSymbols) if (!unlinkedDeclarationsSupport.partialLinkageEnabled)
messageLogger.checkNoUnboundSymbols(symbolTable, whenDetected) messageLogger.checkNoUnboundSymbols(symbolTable, whenDetected)
} }
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.IrMessageLogger import org.jetbrains.kotlin.ir.util.IrMessageLogger
interface UnlinkedDeclarationsSupport { interface UnlinkedDeclarationsSupport {
val allowUnboundSymbols: Boolean val partialLinkageEnabled: Boolean
/** For general use in IR linker. */ /** For general use in IR linker. */
fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder) fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder)
@@ -29,7 +29,7 @@ interface UnlinkedDeclarationsSupport {
companion object { companion object {
val DISABLED = object : UnlinkedDeclarationsSupport { val DISABLED = object : UnlinkedDeclarationsSupport {
override val allowUnboundSymbols get() = false override val partialLinkageEnabled get() = false
override fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder) = Unit override fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder) = Unit
override fun markUsedClassifiersInInlineLazyIrFunction(function: IrFunction) = Unit override fun markUsedClassifiersInInlineLazyIrFunction(function: IrFunction) = Unit
override fun processUnlinkedDeclarations(messageLogger: IrMessageLogger, lazyRoots: () -> List<IrElement>) = Unit override fun processUnlinkedDeclarations(messageLogger: IrMessageLogger, lazyRoots: () -> List<IrElement>) = Unit
@@ -28,10 +28,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
class UnlinkedDeclarationsSupportImpl( class UnlinkedDeclarationsSupportImpl(private val builtIns: IrBuiltIns) : UnlinkedDeclarationsSupport {
private val builtIns: IrBuiltIns,
override val allowUnboundSymbols: Boolean
) : UnlinkedDeclarationsSupport {
private val handler = object : UnlinkedMarkerTypeHandler { private val handler = object : UnlinkedMarkerTypeHandler {
override val unlinkedMarkerType = IrSimpleTypeImpl( override val unlinkedMarkerType = IrSimpleTypeImpl(
classifier = builtIns.anyClass, classifier = builtIns.anyClass,
@@ -45,9 +42,9 @@ class UnlinkedDeclarationsSupportImpl(
private val usedClassifierSymbols = UsedClassifierSymbols() private val usedClassifierSymbols = UsedClassifierSymbols()
override fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder) { override val partialLinkageEnabled get() = true
if (!allowUnboundSymbols) return
override fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder) {
val entries = fakeOverrideBuilder.fakeOverrideCandidates val entries = fakeOverrideBuilder.fakeOverrideCandidates
if (entries.isEmpty()) return if (entries.isEmpty()) return
@@ -114,8 +111,6 @@ class UnlinkedDeclarationsSupportImpl(
} }
override fun markUsedClassifiersInInlineLazyIrFunction(function: IrFunction) { override fun markUsedClassifiersInInlineLazyIrFunction(function: IrFunction) {
if (!allowUnboundSymbols) return
function.acceptChildrenVoid(object : IrElementVisitorVoid { function.acceptChildrenVoid(object : IrElementVisitorVoid {
override fun visitElement(element: IrElement) { override fun visitElement(element: IrElement) {
element.acceptChildrenVoid(this) element.acceptChildrenVoid(this)
@@ -173,8 +168,6 @@ class UnlinkedDeclarationsSupportImpl(
} }
override fun processUnlinkedDeclarations(messageLogger: IrMessageLogger, lazyRoots: () -> List<IrElement>) { override fun processUnlinkedDeclarations(messageLogger: IrMessageLogger, lazyRoots: () -> List<IrElement>) {
if (!allowUnboundSymbols) return
val processor = UnlinkedDeclarationsProcessor(builtIns, usedClassifierSymbols, handler, messageLogger) val processor = UnlinkedDeclarationsProcessor(builtIns, usedClassifierSymbols, handler, messageLogger)
processor.addLinkageErrorIntoUnlinkedClasses() processor.addLinkageErrorIntoUnlinkedClasses()
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.backend.common.serialization.metadata.DynamicTypeDes
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataIncrementalSerializer import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataIncrementalSerializer
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupportImpl
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
@@ -121,7 +120,7 @@ fun generateIrForKlibSerialization(
val incrementalDataProvider = configuration.get(JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER) val incrementalDataProvider = configuration.get(JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER)
val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT
val messageLogger = configuration.irMessageLogger val messageLogger = configuration.irMessageLogger
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false val partialLinkageEnabled = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
val serializedIrFiles = mutableListOf<SerializedIrFile>() val serializedIrFiles = mutableListOf<SerializedIrFile>()
@@ -152,7 +151,7 @@ fun generateIrForKlibSerialization(
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory) val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory)
val psi2Ir = Psi2IrTranslator( val psi2Ir = Psi2IrTranslator(
configuration.languageVersionSettings, configuration.languageVersionSettings,
Psi2IrConfiguration(errorPolicy.allowErrors, allowUnboundSymbols), Psi2IrConfiguration(errorPolicy.allowErrors, partialLinkageEnabled),
messageLogger::checkNoUnboundSymbols messageLogger::checkNoUnboundSymbols
) )
val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable)
@@ -172,6 +171,7 @@ fun generateIrForKlibSerialization(
messageLogger, messageLogger,
psi2IrContext.irBuiltIns, psi2IrContext.irBuiltIns,
psi2IrContext.symbolTable, psi2IrContext.symbolTable,
partialLinkageEnabled = false,
feContext, feContext,
ICData(serializedIrFiles, errorPolicy.allowErrors), ICData(serializedIrFiles, errorPolicy.allowErrors),
stubGenerator = stubGenerator stubGenerator = stubGenerator
@@ -313,7 +313,7 @@ fun loadIr(
val allDependencies = depsDescriptors.allDependencies.map { it.library } val allDependencies = depsDescriptors.allDependencies.map { it.library }
val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT
val messageLogger = configuration.irMessageLogger val messageLogger = configuration.irMessageLogger
val allowUnboundSymbol = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false val partialLinkageEnabled = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
val signaturer = IdSignatureDescriptor(JsManglerDesc) val signaturer = IdSignatureDescriptor(JsManglerDesc)
val symbolTable = SymbolTable(signaturer, irFactory) val symbolTable = SymbolTable(signaturer, irFactory)
@@ -321,7 +321,7 @@ fun loadIr(
when (mainModule) { when (mainModule) {
is MainModule.SourceFiles -> { is MainModule.SourceFiles -> {
assert(filesToLoad == null) assert(filesToLoad == null)
val psi2IrContext = preparePsi2Ir(depsDescriptors, errorPolicy, symbolTable, allowUnboundSymbol) val psi2IrContext = preparePsi2Ir(depsDescriptors, errorPolicy, symbolTable, partialLinkageEnabled)
val friendModules = val friendModules =
mapOf(psi2IrContext.moduleDescriptor.name.asString() to depsDescriptors.friendDependencies.map { it.library.uniqueName }) mapOf(psi2IrContext.moduleDescriptor.name.asString() to depsDescriptors.friendDependencies.map { it.library.uniqueName })
@@ -376,18 +376,17 @@ fun getIrModuleInfoForKlib(
val typeTranslator = TypeTranslatorImpl(symbolTable, configuration.languageVersionSettings, moduleDescriptor) val typeTranslator = TypeTranslatorImpl(symbolTable, configuration.languageVersionSettings, moduleDescriptor)
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable) val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false val partialLinkageEnabled = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
val unlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(irBuiltIns, allowUnboundSymbols)
val irLinker = JsIrLinker( val irLinker = JsIrLinker(
currentModule = null, currentModule = null,
messageLogger = messageLogger, messageLogger = messageLogger,
builtIns = irBuiltIns, builtIns = irBuiltIns,
symbolTable = symbolTable, symbolTable = symbolTable,
partialLinkageEnabled = partialLinkageEnabled,
translationPluginContext = null, translationPluginContext = null,
icData = null, icData = null,
friendModules = friendModules, friendModules = friendModules
unlinkedDeclarationsSupport = unlinkedDeclarationsSupport
) )
val deserializedModuleFragmentsToLib = deserializeDependencies(sortedDependencies, irLinker, mainModuleLib, filesToLoad, mapping) val deserializedModuleFragmentsToLib = deserializeDependencies(sortedDependencies, irLinker, mainModuleLib, filesToLoad, mapping)
@@ -435,18 +434,17 @@ fun getIrModuleInfoForSourceFiles(
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns) JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
} }
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false val partialLinkageEnabled = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
val unlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(irBuiltIns, allowUnboundSymbols)
val irLinker = JsIrLinker( val irLinker = JsIrLinker(
currentModule = psi2IrContext.moduleDescriptor, currentModule = psi2IrContext.moduleDescriptor,
messageLogger = messageLogger, messageLogger = messageLogger,
builtIns = irBuiltIns, builtIns = irBuiltIns,
symbolTable = symbolTable, symbolTable = symbolTable,
partialLinkageEnabled = partialLinkageEnabled,
translationPluginContext = feContext, translationPluginContext = feContext,
icData = null, icData = null,
friendModules = friendModules, friendModules = friendModules,
unlinkedDeclarationsSupport = unlinkedDeclarationsSupport
) )
val deserializedModuleFragmentsToLib = deserializeDependencies(allSortedDependencies, irLinker, null,null, mapping) val deserializedModuleFragmentsToLib = deserializeDependencies(allSortedDependencies, irLinker, null,null, mapping)
val deserializedModuleFragments = deserializedModuleFragmentsToLib.keys.toList() val deserializedModuleFragments = deserializedModuleFragmentsToLib.keys.toList()
@@ -506,12 +504,12 @@ private fun preparePsi2Ir(
depsDescriptors: ModulesStructure, depsDescriptors: ModulesStructure,
errorIgnorancePolicy: ErrorTolerancePolicy, errorIgnorancePolicy: ErrorTolerancePolicy,
symbolTable: SymbolTable, symbolTable: SymbolTable,
allowUnboundSymbols: Boolean partialLinkageEnabled: Boolean
): GeneratorContext { ): GeneratorContext {
val analysisResult = depsDescriptors.jsFrontEndResult val analysisResult = depsDescriptors.jsFrontEndResult
val psi2Ir = Psi2IrTranslator( val psi2Ir = Psi2IrTranslator(
depsDescriptors.compilerConfiguration.languageVersionSettings, depsDescriptors.compilerConfiguration.languageVersionSettings,
Psi2IrConfiguration(errorIgnorancePolicy.allowErrors, allowUnboundSymbols), Psi2IrConfiguration(errorIgnorancePolicy.allowErrors, partialLinkageEnabled),
depsDescriptors.compilerConfiguration::checkNoUnboundSymbols depsDescriptors.compilerConfiguration::checkNoUnboundSymbols
) )
return psi2Ir.createGeneratorContext( return psi2Ir.createGeneratorContext(
@@ -7,8 +7,6 @@ package org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
import org.jetbrains.kotlin.backend.common.serialization.* import org.jetbrains.kotlin.backend.common.serialization.*
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupportImpl
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrBuiltIns import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
@@ -22,13 +20,10 @@ import org.jetbrains.kotlin.library.containsErrorCode
class JsIrLinker( class JsIrLinker(
private val currentModule: ModuleDescriptor?, messageLogger: IrMessageLogger, builtIns: IrBuiltIns, symbolTable: SymbolTable, private val currentModule: ModuleDescriptor?, messageLogger: IrMessageLogger, builtIns: IrBuiltIns, symbolTable: SymbolTable,
partialLinkageEnabled: Boolean,
override val translationPluginContext: TranslationPluginContext?, override val translationPluginContext: TranslationPluginContext?,
private val icData: ICData? = null, private val icData: ICData? = null,
friendModules: Map<String, Collection<String>> = emptyMap(), friendModules: Map<String, Collection<String>> = emptyMap(),
override val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(
builtIns,
allowUnboundSymbols = false
),
private val stubGenerator: DeclarationStubGenerator? = null private val stubGenerator: DeclarationStubGenerator? = null
) : KotlinIrLinker( ) : KotlinIrLinker(
currentModule = currentModule, currentModule = currentModule,
@@ -36,6 +31,7 @@ class JsIrLinker(
builtIns = builtIns, builtIns = builtIns,
symbolTable = symbolTable, symbolTable = symbolTable,
exportedDependencies = emptyList(), exportedDependencies = emptyList(),
partialLinkageEnabled = partialLinkageEnabled,
symbolProcessor = { symbol, idSig -> symbolProcessor = { symbol, idSig ->
if (idSig.isLocal) { if (idSig.isLocal) {
symbol.privateSignature = IdSignature.CompositeSignature(IdSignature.FileSignature(fileSymbol), idSig) symbol.privateSignature = IdSignature.CompositeSignature(IdSignature.FileSignature(fileSymbol), idSig)
@@ -41,7 +41,7 @@ class JvmIrLinker(
private val stubGenerator: DeclarationStubGenerator, private val stubGenerator: DeclarationStubGenerator,
private val manglerDesc: JvmDescriptorMangler, private val manglerDesc: JvmDescriptorMangler,
private val enableIdSignatures: Boolean, private val enableIdSignatures: Boolean,
) : KotlinIrLinker(currentModule, messageLogger, typeSystem.irBuiltIns, symbolTable, emptyList()) { ) : KotlinIrLinker(currentModule, messageLogger, typeSystem.irBuiltIns, symbolTable, emptyList(), partialLinkageEnabled = false) {
// TODO: provide friend modules // TODO: provide friend modules
override val fakeOverrideBuilder = FakeOverrideBuilder(this, symbolTable, JvmIrMangler, typeSystem, emptyMap()) override val fakeOverrideBuilder = FakeOverrideBuilder(this, symbolTable, JvmIrMangler, typeSystem, emptyMap())
@@ -224,7 +224,7 @@ abstract class AbstractKlibTextTestCase : CodegenTestCase() {
val typeTranslator = val typeTranslator =
TypeTranslatorImpl(symbolTable, myEnvironment.configuration.languageVersionSettings, testDescriptor) TypeTranslatorImpl(symbolTable, myEnvironment.configuration.languageVersionSettings, testDescriptor)
val irBuiltIns = IrBuiltInsOverDescriptors(testDescriptor.builtIns, typeTranslator, symbolTable) val irBuiltIns = IrBuiltInsOverDescriptors(testDescriptor.builtIns, typeTranslator, symbolTable)
val irLinker = JsIrLinker(null, IrMessageLogger.None, irBuiltIns, symbolTable, null) val irLinker = JsIrLinker(null, IrMessageLogger.None, irBuiltIns, symbolTable, partialLinkageEnabled = false, null)
irLinker.deserializeIrModuleHeader(stdlibDescriptor, stdlib) irLinker.deserializeIrModuleHeader(stdlibDescriptor, stdlib)
val testModule = irLinker.deserializeIrModuleHeader(testDescriptor, klib, { DeserializationStrategy.ALL }) val testModule = irLinker.deserializeIrModuleHeader(testDescriptor, klib, { DeserializationStrategy.ALL })
irLinker.init(null, emptyList()) irLinker.init(null, emptyList())
@@ -290,7 +290,7 @@ abstract class AbstractKlibTextTestCase : CodegenTestCase() {
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl, NameProvider.DEFAULT) val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl, NameProvider.DEFAULT)
val context = psi2Ir.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable) val context = psi2Ir.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable)
val irBuiltIns = context.irBuiltIns val irBuiltIns = context.irBuiltIns
val irLinker = JsIrLinker(moduleDescriptor, messageLogger, irBuiltIns, symbolTable, null) val irLinker = JsIrLinker(moduleDescriptor, messageLogger, irBuiltIns, symbolTable, partialLinkageEnabled = false, null)
irLinker.deserializeIrModuleHeader(stdlibDescriptor, stdlib) irLinker.deserializeIrModuleHeader(stdlibDescriptor, stdlib)
return psi2Ir.generateModuleFragment(context, ktFiles, listOf(irLinker), emptyList(), expectActualSymbols) to bindingContext return psi2Ir.generateModuleFragment(context, ktFiles, listOf(irLinker), emptyList(), expectActualSymbols) to bindingContext
@@ -473,6 +473,7 @@ class GenerateIrRuntime {
messageLogger, messageLogger,
psi2IrContext.irBuiltIns, psi2IrContext.irBuiltIns,
psi2IrContext.symbolTable, psi2IrContext.symbolTable,
partialLinkageEnabled = false,
null null
) )
@@ -548,7 +549,7 @@ class GenerateIrRuntime {
val typeTranslator = TypeTranslatorImpl(symbolTable, languageVersionSettings, moduleDescriptor) val typeTranslator = TypeTranslatorImpl(symbolTable, languageVersionSettings, moduleDescriptor)
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable) val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
val jsLinker = JsIrLinker(moduleDescriptor, IrMessageLogger.None, irBuiltIns, symbolTable, null) val jsLinker = JsIrLinker(moduleDescriptor, IrMessageLogger.None, irBuiltIns, symbolTable, partialLinkageEnabled = false, null)
val moduleFragment = jsLinker.deserializeFullModule(moduleDescriptor, moduleDescriptor.kotlinLibrary) val moduleFragment = jsLinker.deserializeFullModule(moduleDescriptor, moduleDescriptor.kotlinLibrary)
jsLinker.init(null, emptyList()) jsLinker.init(null, emptyList())
@@ -573,7 +574,7 @@ class GenerateIrRuntime {
val typeTranslator = TypeTranslatorImpl(symbolTable, languageVersionSettings, moduleDescriptor) val typeTranslator = TypeTranslatorImpl(symbolTable, languageVersionSettings, moduleDescriptor)
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable) val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
val jsLinker = JsIrLinker(moduleDescriptor, IrMessageLogger.None, irBuiltIns, symbolTable, null) val jsLinker = JsIrLinker(moduleDescriptor, IrMessageLogger.None, irBuiltIns, symbolTable, partialLinkageEnabled = false, null)
val moduleFragment = jsLinker.deserializeFullModule(moduleDescriptor, moduleDescriptor.kotlinLibrary) val moduleFragment = jsLinker.deserializeFullModule(moduleDescriptor, moduleDescriptor.kotlinLibrary)
// Create stubs // Create stubs
@@ -7,7 +7,6 @@ import org.jetbrains.kotlin.backend.common.serialization.DescriptorByIdSignature
import org.jetbrains.kotlin.backend.common.serialization.linkerissues.checkNoUnboundSymbols import org.jetbrains.kotlin.backend.common.serialization.linkerissues.checkNoUnboundSymbols
import org.jetbrains.kotlin.backend.common.serialization.mangle.ManglerChecker import org.jetbrains.kotlin.backend.common.serialization.mangle.ManglerChecker
import org.jetbrains.kotlin.backend.common.serialization.mangle.descriptor.Ir2DescriptorManglerAdapter import org.jetbrains.kotlin.backend.common.serialization.mangle.descriptor.Ir2DescriptorManglerAdapter
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupportImpl
import org.jetbrains.kotlin.backend.konan.descriptors.isForwardDeclarationModule import org.jetbrains.kotlin.backend.konan.descriptors.isForwardDeclarationModule
import org.jetbrains.kotlin.backend.konan.descriptors.isFromInteropLibrary import org.jetbrains.kotlin.backend.konan.descriptors.isFromInteropLibrary
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
@@ -52,11 +51,11 @@ internal fun Context.psiToIr(
val expectActualLinker = config.configuration[CommonConfigurationKeys.EXPECT_ACTUAL_LINKER] ?: false val expectActualLinker = config.configuration[CommonConfigurationKeys.EXPECT_ACTUAL_LINKER] ?: false
val messageLogger = config.configuration[IrMessageLogger.IR_MESSAGE_LOGGER] ?: IrMessageLogger.None val messageLogger = config.configuration[IrMessageLogger.IR_MESSAGE_LOGGER] ?: IrMessageLogger.None
val allowUnboundSymbols = config.configuration[KonanConfigKeys.PARTIAL_LINKAGE] ?: false val partialLinkageEnabled = config.configuration[KonanConfigKeys.PARTIAL_LINKAGE] ?: false
val translator = Psi2IrTranslator( val translator = Psi2IrTranslator(
config.configuration.languageVersionSettings, config.configuration.languageVersionSettings,
Psi2IrConfiguration(ignoreErrors = false, allowUnboundSymbols = allowUnboundSymbols), Psi2IrConfiguration(ignoreErrors = false, partialLinkageEnabled),
messageLogger::checkNoUnboundSymbols messageLogger::checkNoUnboundSymbols
) )
val generatorContext = translator.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable) val generatorContext = translator.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable)
@@ -123,8 +122,6 @@ internal fun Context.psiToIr(
config.resolve.includedLibraries.map { it.uniqueName } config.resolve.includedLibraries.map { it.uniqueName }
).associateWith { friendModules } ).associateWith { friendModules }
val unlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(generatorContext.irBuiltIns, allowUnboundSymbols)
KonanIrLinker( KonanIrLinker(
currentModule = moduleDescriptor, currentModule = moduleDescriptor,
translationPluginContext = translationContext, translationPluginContext = translationContext,
@@ -136,10 +133,10 @@ internal fun Context.psiToIr(
stubGenerator = stubGenerator, stubGenerator = stubGenerator,
cenumsProvider = irProviderForCEnumsAndCStructs, cenumsProvider = irProviderForCEnumsAndCStructs,
exportedDependencies = exportedDependencies, exportedDependencies = exportedDependencies,
partialLinkageEnabled = partialLinkageEnabled,
cachedLibraries = config.cachedLibraries, cachedLibraries = config.cachedLibraries,
lazyIrForCaches = config.lazyIrForCaches, lazyIrForCaches = config.lazyIrForCaches,
libraryBeingCached = config.libraryToCache, libraryBeingCached = config.libraryToCache,
unlinkedDeclarationsSupport = unlinkedDeclarationsSupport,
userVisibleIrModulesSupport = config.userVisibleIrModulesSupport userVisibleIrModulesSupport = config.userVisibleIrModulesSupport
).also { linker -> ).also { linker ->
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.backend.common.serialization.encodings.BinaryNameAnd
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
import org.jetbrains.kotlin.backend.common.serialization.encodings.FunctionFlags import org.jetbrains.kotlin.backend.common.serialization.encodings.FunctionFlags
import org.jetbrains.kotlin.backend.common.serialization.linkerissues.UserVisibleIrModulesSupport import org.jetbrains.kotlin.backend.common.serialization.linkerissues.UserVisibleIrModulesSupport
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport
import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.*
import org.jetbrains.kotlin.backend.konan.descriptors.ClassLayoutBuilder import org.jetbrains.kotlin.backend.konan.descriptors.ClassLayoutBuilder
import org.jetbrains.kotlin.backend.konan.descriptors.findPackage import org.jetbrains.kotlin.backend.konan.descriptors.findPackage
@@ -42,8 +41,6 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyClass import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyClass
import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrPublicSymbolBase import org.jetbrains.kotlin.ir.symbols.impl.IrPublicSymbolBase
import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.*
@@ -320,12 +317,12 @@ internal class KonanIrLinker(
private val stubGenerator: DeclarationStubGenerator, private val stubGenerator: DeclarationStubGenerator,
private val cenumsProvider: IrProviderForCEnumAndCStructStubs, private val cenumsProvider: IrProviderForCEnumAndCStructStubs,
exportedDependencies: List<ModuleDescriptor>, exportedDependencies: List<ModuleDescriptor>,
partialLinkageEnabled: Boolean,
private val cachedLibraries: CachedLibraries, private val cachedLibraries: CachedLibraries,
private val lazyIrForCaches: Boolean, private val lazyIrForCaches: Boolean,
private val libraryBeingCached: PartialCacheInfo?, private val libraryBeingCached: PartialCacheInfo?,
override val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport,
override val userVisibleIrModulesSupport: UserVisibleIrModulesSupport override val userVisibleIrModulesSupport: UserVisibleIrModulesSupport
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies) { ) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies, partialLinkageEnabled) {
companion object { companion object {
private val C_NAMES_NAME = Name.identifier("cnames") private val C_NAMES_NAME = Name.identifier("cnames")
@@ -45,7 +45,7 @@ class JsScriptDependencyCompiler(
val typeTranslator = TypeTranslatorImpl(symbolTable, languageVersionSettings, moduleDescriptor) val typeTranslator = TypeTranslatorImpl(symbolTable, languageVersionSettings, moduleDescriptor)
val irBuiltIns = IrBuiltInsOverDescriptors(builtIns, typeTranslator, symbolTable) val irBuiltIns = IrBuiltInsOverDescriptors(builtIns, typeTranslator, symbolTable)
val jsLinker = JsIrLinker(null, messageLogger, irBuiltIns, symbolTable, null) val jsLinker = JsIrLinker(null, messageLogger, irBuiltIns, symbolTable, partialLinkageEnabled = false, null)
val irDependencies = dependencies.map { jsLinker.deserializeFullModule(it, it.kotlinLibrary) } val irDependencies = dependencies.map { jsLinker.deserializeFullModule(it, it.kotlinLibrary) }
val moduleFragment = irDependencies.last() val moduleFragment = irDependencies.last()