Allow libraries to have empty ir/ component.
This commit is contained in:
committed by
alexander-gorshenev
parent
2736876919
commit
8067ab7034
+3
-3
@@ -81,7 +81,7 @@ fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironme
|
||||
if (library == null) {
|
||||
return@map null
|
||||
}
|
||||
deserializer.deserializeIrModule(it, library.irHeader)
|
||||
library.irHeader?.let { header -> deserializer.deserializeIrModule(it, header) }
|
||||
}.filterNotNull()
|
||||
|
||||
val symbols = KonanSymbols(context, generatorContext.symbolTable, generatorContext.symbolTable.lazyWrapper)
|
||||
@@ -117,11 +117,11 @@ fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironme
|
||||
|
||||
phaser.phase(KonanPhase.SERIALIZER) {
|
||||
val declarationTable = DeclarationTable(context.irModule!!.irBuiltins, DescriptorTable())
|
||||
val serializedIr = IrModuleSerializer(context, declarationTable/*, onlyForInlines = false*/).serializedIrModule(context.irModule!!)
|
||||
val serializedIr = IrModuleSerializer(context, declarationTable).serializedIrModule(context.irModule!!)
|
||||
|
||||
val serializer = KonanSerializationUtil(context, context.config.configuration.get(CommonConfigurationKeys.METADATA_VERSION)!!, declarationTable)
|
||||
context.serializedLinkData =
|
||||
serializer.serializeModule(context.moduleDescriptor, serializedIr)
|
||||
serializer.serializeModule(context.moduleDescriptor, if (!context.config.isInteropStubs) serializedIr else null)
|
||||
}
|
||||
phaser.phase(KonanPhase.BACKEND) {
|
||||
phaser.phase(KonanPhase.LOWER) {
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@ internal class MetadataWriterImpl(libraryLayout: KonanLibraryLayout): KonanLibra
|
||||
|
||||
fun addLinkData(linkData: LinkData) {
|
||||
moduleHeaderFile.writeBytes(linkData.module)
|
||||
wholeIrFile.writeBytes(linkData.ir!!.module)
|
||||
linkData.ir?.let { irHeader.writeBytes(it.module) }
|
||||
linkData.fragments.forEachIndexed { index, it ->
|
||||
val packageFqName = linkData.fragmentNames[index]
|
||||
val shortName = packageFqName.substringAfterLast(".")
|
||||
@@ -33,7 +33,7 @@ internal class MetadataWriterImpl(libraryLayout: KonanLibraryLayout): KonanLibra
|
||||
visibleDeclarationFile(index)
|
||||
file.writeBytes(it.value)
|
||||
}
|
||||
val lines = linkData.ir?.debugIndex.map { entry -> "${entry.key}: ${entry.value}" }
|
||||
irIndex.writeLines(lines)
|
||||
val lines = linkData.ir?.debugIndex?.map { entry -> "${entry.key}: ${entry.value}" }
|
||||
if (lines != null) irIndex.writeLines(lines)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -675,7 +675,7 @@ internal class InteropLoweringPart1(val context: Context) : IrBuildingTransforme
|
||||
val companionObject = classDescriptor.companionObjectDescriptor ?:
|
||||
error("native variable class $classDescriptor must have the companion object")
|
||||
|
||||
builder.at(expression).irGetObject(symbolTable.referenceClass(companionObject))
|
||||
builder.at(expression).irGetObject(symbolTable.lazyWrapper.referenceClass(companionObject))
|
||||
}
|
||||
}
|
||||
else -> expression
|
||||
|
||||
+12
-9
@@ -210,24 +210,27 @@ class KonanIrModuleDeserializer(
|
||||
val uniqId = UniqId(descriptorUniqId.index, isLocal = false)
|
||||
val topLevelKey = UniqIdKey(topLevelDescriptor.module, uniqId)
|
||||
|
||||
// This top level descriptor doesn't have a serialized IR declaration.
|
||||
if (topLevelKey.moduleOfOrigin == null) return null
|
||||
|
||||
reachableTopLevels.add(topLevelKey)
|
||||
|
||||
do {
|
||||
val key = reachableTopLevels.first()
|
||||
|
||||
if (deserializedSymbols[key]?.isBound == true) {
|
||||
if (deserializedSymbols[key]?.isBound == true ||
|
||||
// The key.moduleOrigin is null for uniqIds that we haven't seen in any of the library headers.
|
||||
// Just skip it for now and handle it elsewhere.
|
||||
key.moduleOfOrigin == null) {
|
||||
|
||||
reachableTopLevels.remove(key)
|
||||
deserializedTopLevels.add(key)
|
||||
continue
|
||||
}
|
||||
|
||||
if (key.moduleOfOrigin != null) {
|
||||
deserializedModuleDescriptor = key.moduleOfOrigin
|
||||
val reachable = deserializeTopLevelDeclaration(key)
|
||||
reversedFileIndex[key]!!.declarations.add(reachable)
|
||||
} else {
|
||||
// The key.moduleOrigin is null for uniqIds that we haven't seen in any of the library headers.
|
||||
// Just skip it for now and handle it elsewhere.
|
||||
}
|
||||
deserializedModuleDescriptor = key.moduleOfOrigin
|
||||
val reachable = deserializeTopLevelDeclaration(key)
|
||||
reversedFileIndex[key]!!.declarations.add(reachable)
|
||||
|
||||
reachableTopLevels.remove(key)
|
||||
deserializedTopLevels.add(key)
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ internal class KonanSerializationUtil(val context: Context, val metadataVersion:
|
||||
.build()
|
||||
}
|
||||
|
||||
internal fun serializeModule(moduleDescriptor: ModuleDescriptor, serializedIr: SerializedIr): LinkData {
|
||||
internal fun serializeModule(moduleDescriptor: ModuleDescriptor, serializedIr: SerializedIr?): LinkData {
|
||||
val libraryProto = KonanProtoBuf.LinkDataLibrary.newBuilder()
|
||||
libraryProto.moduleName = moduleDescriptor.name.asString()
|
||||
val fragments = mutableListOf<List<ByteArray>>()
|
||||
|
||||
@@ -43,7 +43,7 @@ interface KonanLibrary {
|
||||
fun packageMetadataParts(fqName: String): Set<String>
|
||||
fun packageMetadata(fqName: String, partName: String): ByteArray
|
||||
|
||||
val irHeader: ByteArray
|
||||
val irHeader: ByteArray?
|
||||
fun irDeclaration(index: Long, isLocal: Boolean): ByteArray
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ interface KonanLibraryLayout {
|
||||
= File(irDir, "hidden_$declarationId.knd")
|
||||
fun visibleDeclarationFile(declarationId: String)
|
||||
= File(irDir, "visible_$declarationId.knd")
|
||||
val wholeIrFile
|
||||
val irHeader
|
||||
get() = File(irDir, "irHeaders.kni")
|
||||
val irIndex: File
|
||||
get() = File(irDir, "uniqIdTableDump.txt")
|
||||
|
||||
@@ -3,6 +3,6 @@ package org.jetbrains.kotlin.konan.library
|
||||
interface MetadataReader {
|
||||
fun loadSerializedModule(libraryLayout: KonanLibraryLayout): ByteArray
|
||||
fun loadSerializedPackageFragment(libraryLayout: KonanLibraryLayout, fqName: String, partName: String): ByteArray
|
||||
fun loadWholeIr(libraryLayout: KonanLibraryLayout): ByteArray
|
||||
fun loadIrHeader(libraryLayout: KonanLibraryLayout): ByteArray
|
||||
fun loadIrDeclaraton(libraryLayout: KonanLibraryLayout, index: Long, isLocal: Boolean): ByteArray
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@ internal object DefaultMetadataReaderImpl : MetadataReader {
|
||||
override fun loadSerializedPackageFragment(libraryLayout: KonanLibraryLayout, fqName: String, partName: String): ByteArray =
|
||||
libraryLayout.packageFragmentFile(fqName, partName).readBytes()
|
||||
|
||||
override fun loadWholeIr(libraryLayout: KonanLibraryLayout): ByteArray =
|
||||
libraryLayout.wholeIrFile.readBytes()
|
||||
override fun loadIrHeader(libraryLayout: KonanLibraryLayout): ByteArray =
|
||||
libraryLayout.irHeader.readBytes()
|
||||
|
||||
override fun loadIrDeclaraton(libraryLayout: KonanLibraryLayout, index: Long, isLocal: Boolean): ByteArray {
|
||||
val name = index.toULong().toString(16)
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ class KonanLibraryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override val irHeader: ByteArray by lazy { layout.inPlace { metadataReader.loadWholeIr(it) }}
|
||||
override val irHeader: ByteArray? by lazy { layout.inPlace { library -> library.irHeader.let { if (it.exists) metadataReader.loadIrHeader(library) else null }}}
|
||||
|
||||
override fun irDeclaration(index: Long, isLocal: Boolean) = layout.inPlace { metadataReader.loadIrDeclaraton(it, index, isLocal) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user