[Linker][Interop] Emit Lazy IR for cached structs and enums
We don't need to create IrClass declarations for structs and enums from cached interop libraries, because these declarations are stored in caches already.
This commit is contained in:
committed by
Sergey Bogolepov
parent
ea7117d9ab
commit
9ea3ee9ad2
+2
-1
@@ -72,7 +72,8 @@ internal fun Context.psiToIr(symbolTable: SymbolTable) {
|
||||
stubGenerator,
|
||||
irProviderForCEnumsAndCStructs,
|
||||
exportedDependencies,
|
||||
deserializeFakeOverrides
|
||||
deserializeFakeOverrides,
|
||||
config.cachedLibraries
|
||||
)
|
||||
|
||||
translator.addPostprocessingStep { module ->
|
||||
|
||||
+13
-8
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.backend.common.overrides.PlatformFakeOverrideClassFi
|
||||
import org.jetbrains.kotlin.backend.common.serialization.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
||||
import org.jetbrains.kotlin.backend.konan.CachedLibraries
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.konanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.IrProviderForCEnumAndCStructStubs
|
||||
@@ -73,7 +74,8 @@ internal class KonanIrLinker(
|
||||
private val stubGenerator: DeclarationStubGenerator,
|
||||
private val cenumsProvider: IrProviderForCEnumAndCStructStubs,
|
||||
exportedDependencies: List<ModuleDescriptor>,
|
||||
deserializeFakeOverrides: Boolean
|
||||
deserializeFakeOverrides: Boolean,
|
||||
private val cachedLibraries: CachedLibraries
|
||||
) : KotlinIrLinker(currentModule, logger, builtIns, symbolTable, exportedDependencies, deserializeFakeOverrides) {
|
||||
|
||||
companion object {
|
||||
@@ -91,7 +93,7 @@ internal class KonanIrLinker(
|
||||
override val translationPluginContext: TranslationPluginContext?
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
private val forwardDeclarationDeserializer = forwardModuleDescriptor?.let { KonanForwardDeclarationModuleDeserialier(it) }
|
||||
private val forwardDeclarationDeserializer = forwardModuleDescriptor?.let { KonanForwardDeclarationModuleDeserializer(it) }
|
||||
|
||||
override fun createModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary?, strategy: DeserializationStrategy): IrModuleDeserializer {
|
||||
if (moduleDescriptor === forwardModuleDescriptor) {
|
||||
@@ -99,7 +101,8 @@ internal class KonanIrLinker(
|
||||
}
|
||||
|
||||
if (klib is KotlinLibrary && klib.isInteropLibrary()) {
|
||||
return KonanInteropModuleDeserializer(moduleDescriptor)
|
||||
val isCached = cachedLibraries.isLibraryCached(klib)
|
||||
return KonanInteropModuleDeserializer(moduleDescriptor, isCached)
|
||||
}
|
||||
|
||||
return KonanModuleDeserializer(moduleDescriptor, klib ?: error("Expecting kotlin library"), strategy)
|
||||
@@ -108,7 +111,10 @@ internal class KonanIrLinker(
|
||||
private inner class KonanModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary, strategy: DeserializationStrategy):
|
||||
KotlinIrLinker.BasicIrModuleDeserializer(moduleDescriptor, klib, strategy)
|
||||
|
||||
private inner class KonanInteropModuleDeserializer(moduleDescriptor: ModuleDescriptor) : IrModuleDeserializer(moduleDescriptor) {
|
||||
private inner class KonanInteropModuleDeserializer(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
private val isLibraryCached: Boolean
|
||||
) : IrModuleDeserializer(moduleDescriptor) {
|
||||
init {
|
||||
assert(moduleDescriptor.kotlinLibrary.isInteropLibrary())
|
||||
}
|
||||
@@ -120,7 +126,6 @@ internal class KonanIrLinker(
|
||||
private fun IdSignature.isInteropSignature(): Boolean = IdSignature.Flags.IS_NATIVE_INTEROP_LIBRARY.test()
|
||||
|
||||
override fun contains(idSig: IdSignature): Boolean {
|
||||
|
||||
if (idSig.isPublic) {
|
||||
if (idSig.isInteropSignature()) {
|
||||
// TODO: add descriptor cache??
|
||||
@@ -148,8 +153,8 @@ internal class KonanIrLinker(
|
||||
|
||||
override fun deserializeIrSymbol(idSig: IdSignature, symbolKind: BinarySymbolData.SymbolKind): IrSymbol {
|
||||
val descriptor = descriptorByIdSignatureFinder.findDescriptorBySignature(idSig) ?: error("Expecting descriptor for $idSig")
|
||||
|
||||
if (descriptor.isCEnumsOrCStruct()) return resolveCEnumsOrStruct(descriptor, idSig, symbolKind)
|
||||
// If library is cached we don't need to create an IrClass for struct or enum.
|
||||
if (!isLibraryCached && descriptor.isCEnumsOrCStruct()) return resolveCEnumsOrStruct(descriptor, idSig, symbolKind)
|
||||
|
||||
val symbolOwner = stubGenerator.generateMemberStub(descriptor) as IrSymbolOwner
|
||||
|
||||
@@ -160,7 +165,7 @@ internal class KonanIrLinker(
|
||||
override val moduleDependencies: Collection<IrModuleDeserializer> = listOfNotNull(forwardDeclarationDeserializer)
|
||||
}
|
||||
|
||||
private inner class KonanForwardDeclarationModuleDeserialier(moduleDescriptor: ModuleDescriptor) : IrModuleDeserializer(moduleDescriptor) {
|
||||
private inner class KonanForwardDeclarationModuleDeserializer(moduleDescriptor: ModuleDescriptor) : IrModuleDeserializer(moduleDescriptor) {
|
||||
init {
|
||||
assert(moduleDescriptor.isForwardDeclarationModule)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user