[Interop][Serialization] Skip files with C enums and structs

We don't need to serialize these files since stubs for enums and structs
will be generated anew.
This commit is contained in:
Sergey Bogolepov
2020-02-28 15:43:06 +07:00
committed by Sergey Bogolepov
parent e79b055c81
commit ac5fd80cb4
2 changed files with 15 additions and 1 deletions
@@ -116,9 +116,13 @@ internal class IrProviderForCEnumAndCStructStubs(
private fun irParentFor(descriptor: ClassDescriptor): IrDeclarationContainer {
val packageFragmentDescriptor = descriptor.findPackage()
return filesMap.getOrPut(packageFragmentDescriptor) {
IrFileImpl(NaiveSourceBasedFileEntryImpl("CTypeDefinitions"), packageFragmentDescriptor).also {
IrFileImpl(NaiveSourceBasedFileEntryImpl(cTypeDefinitionsFileName), packageFragmentDescriptor).also {
this@IrProviderForCEnumAndCStructStubs.module?.files?.add(it)
}
}
}
companion object {
const val cTypeDefinitionsFileName = "CTypeDefinitions"
}
}
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.backend.konan.serialization
import org.jetbrains.kotlin.backend.common.LoggingContext
import org.jetbrains.kotlin.backend.common.serialization.*
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
import org.jetbrains.kotlin.backend.konan.ir.interop.IrProviderForCEnumAndCStructStubs
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
@@ -18,6 +19,15 @@ class KonanIrModuleSerializer(
private val signaturer = IdSignatureSerializer(KonanManglerIr)
private val globalDeclarationTable = KonanGlobalDeclarationTable(signaturer, irBuiltIns)
// We skip files with IR for C structs and enums because they should be
// generated anew.
//
// See [IrProviderForCEnumAndCStructStubs.kt#L31] on why we generate IR.
// We may switch from IR generation to LazyIR later (at least for structs; enums are tricky)
// without changing kotlin libraries that depend on interop libraries.
override fun backendSpecificFileFilter(file: IrFile): Boolean =
file.fileEntry.name != IrProviderForCEnumAndCStructStubs.cTypeDefinitionsFileName
override fun createSerializerForFile(file: IrFile): KonanIrFileSerializer =
KonanIrFileSerializer(logger, DeclarationTable(globalDeclarationTable), expectDescriptorToSymbol, skipExpects = skipExpects)
}