FIR JS: Prepare JS/KLib infrastructure for FIR integration
rearrange declarations, abstract things that should be done differently with FIR, etc.
This commit is contained in:
+15
-15
@@ -56,21 +56,6 @@ class KlibMetadataIncrementalSerializer(
|
||||
return serializeDescriptors(fqName, classifierDescriptors, topLevelDescriptors).single()
|
||||
}
|
||||
|
||||
fun serializedMetadata(
|
||||
fragments: Map<String, List<ByteArray>>,
|
||||
header: ByteArray
|
||||
): SerializedMetadata {
|
||||
val fragmentNames = mutableListOf<String>()
|
||||
val fragmentParts = mutableListOf<List<ByteArray>>()
|
||||
|
||||
for ((fqName, fragment) in fragments.entries.sortedBy { it.key }) {
|
||||
fragmentNames += fqName
|
||||
fragmentParts += fragment
|
||||
}
|
||||
|
||||
return SerializedMetadata(header, fragmentParts, fragmentNames)
|
||||
}
|
||||
|
||||
// TODO: For now, in the incremental serializer, we assume
|
||||
// there is only a single package fragment per file.
|
||||
// This is no always the case, actually.
|
||||
@@ -78,4 +63,19 @@ class KlibMetadataIncrementalSerializer(
|
||||
// See monolithic serializer for details.
|
||||
override val TOP_LEVEL_DECLARATION_COUNT_PER_FILE = null
|
||||
override val TOP_LEVEL_CLASS_DECLARATION_COUNT_PER_FILE = null
|
||||
}
|
||||
|
||||
fun makeSerializedKlibMetadata(
|
||||
fragments: Map<String, List<ByteArray>>,
|
||||
header: ByteArray
|
||||
): SerializedMetadata {
|
||||
val fragmentNames = mutableListOf<String>()
|
||||
val fragmentParts = mutableListOf<List<ByteArray>>()
|
||||
|
||||
for ((fqName, fragment) in fragments.entries.sortedBy { it.key }) {
|
||||
fragmentNames += fqName
|
||||
fragmentParts += fragment
|
||||
}
|
||||
|
||||
return SerializedMetadata(header, fragmentParts, fragmentNames)
|
||||
}
|
||||
+25
-16
@@ -253,22 +253,7 @@ abstract class KlibMetadataSerializer(
|
||||
fragmentNames: List<String>,
|
||||
emptyPackages: List<String>
|
||||
): KlibMetadataProtoBuf.Header {
|
||||
val header = KlibMetadataProtoBuf.Header.newBuilder()
|
||||
|
||||
header.moduleName = moduleDescriptor.name.asString()
|
||||
|
||||
if (languageVersionSettings.isPreRelease()) {
|
||||
header.flags = 1
|
||||
}
|
||||
|
||||
fragmentNames.forEach {
|
||||
header.addPackageFragmentName(it)
|
||||
}
|
||||
emptyPackages.forEach {
|
||||
header.addEmptyPackage(it)
|
||||
}
|
||||
|
||||
return header.build()
|
||||
return serializeKlibHeader(languageVersionSettings, moduleDescriptor, fragmentNames, emptyPackages)
|
||||
}
|
||||
|
||||
// For platform libraries we get HUGE files.
|
||||
@@ -278,6 +263,30 @@ abstract class KlibMetadataSerializer(
|
||||
abstract protected val TOP_LEVEL_CLASS_DECLARATION_COUNT_PER_FILE: Int?
|
||||
}
|
||||
|
||||
fun serializeKlibHeader(
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
fragmentNames: List<String>,
|
||||
emptyPackages: List<String>
|
||||
): KlibMetadataProtoBuf.Header {
|
||||
val header = KlibMetadataProtoBuf.Header.newBuilder()
|
||||
|
||||
header.moduleName = moduleDescriptor.name.asString()
|
||||
|
||||
if (languageVersionSettings.isPreRelease()) {
|
||||
header.flags = 1
|
||||
}
|
||||
|
||||
fragmentNames.forEach {
|
||||
header.addPackageFragmentName(it)
|
||||
}
|
||||
emptyPackages.forEach {
|
||||
header.addEmptyPackage(it)
|
||||
}
|
||||
|
||||
return header.build()
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.extractFileId(): Int? = when (this) {
|
||||
is DeserializedClassDescriptor -> classProto.getExtension(KlibMetadataProtoBuf.classFile)
|
||||
is DeserializedSimpleFunctionDescriptor -> proto.getExtension(KlibMetadataProtoBuf.functionFile)
|
||||
|
||||
Reference in New Issue
Block a user