[IR SERIALIZATION] Get rid of UniqId proto message
- encode locality flag in major bit of uniqid (1 - global, 0 - local)
This commit is contained in:
@@ -35,7 +35,7 @@ interface MetadataLibrary {
|
||||
|
||||
interface IrLibrary {
|
||||
val dataFlowGraph: ByteArray?
|
||||
fun irDeclaration(index: Long, isLocal: Boolean, fileIndex: Int): ByteArray
|
||||
fun irDeclaration(index: Long, fileIndex: Int): ByteArray
|
||||
fun symbol(index: Int, fileIndex: Int): ByteArray
|
||||
fun type(index: Int, fileIndex: Int): ByteArray
|
||||
fun string(index: Int, fileIndex: Int): ByteArray
|
||||
|
||||
@@ -169,7 +169,7 @@ abstract class IrTableReader<K>(file: File, keyReader: ByteBuffer.() -> K) {
|
||||
|
||||
class IndexIrTableReader(file: File) : IrTableReader<Long>(file, { long })
|
||||
|
||||
data class DeclarationId(val id: Long, val isLocal: Boolean)
|
||||
data class DeclarationId(val id: Long)
|
||||
|
||||
class DeclarationIrTableReader(file: File) : IrTableReader<DeclarationId>(file, { DeclarationId(long, int != 0) })
|
||||
class DeclarationIrMultiTableReader(file: File) : IrMultiTableReader<DeclarationId>(file, { DeclarationId(long, int != 0) })
|
||||
class DeclarationIrTableReader(file: File) : IrTableReader<DeclarationId>(file, { DeclarationId(long) })
|
||||
class DeclarationIrMultiTableReader(file: File) : IrMultiTableReader<DeclarationId>(file, { DeclarationId(long) })
|
||||
@@ -76,7 +76,7 @@ class IrTableWriter(private val data: List<Pair<Long, ByteArray>>) : IrFileWrite
|
||||
override fun writeData(dataOutput: DataOutput) {
|
||||
dataOutput.writeInt(data.size)
|
||||
|
||||
var dataOffset = 4 + data.size * (8 + 4 + 4)
|
||||
var dataOffset = Int.SIZE_BYTES + data.size * (Long.SIZE_BYTES + 2 * Int.SIZE_BYTES)
|
||||
|
||||
data.forEach {
|
||||
dataOutput.writeLong(it.first)
|
||||
@@ -91,8 +91,8 @@ class IrTableWriter(private val data: List<Pair<Long, ByteArray>>) : IrFileWrite
|
||||
|
||||
class IrDeclarationWriter(private val declarations: List<SerializedDeclaration>) : IrFileWriter() {
|
||||
|
||||
private val SINGLE_INDEX_RECORD_SIZE = 20 // sizeof(Long) + 3 * sizeof(Int).
|
||||
private val INDEX_HEADER_SIZE = 4 // sizeof(Int).
|
||||
private val SINGLE_INDEX_RECORD_SIZE = Long.SIZE_BYTES + 2 * Int.SIZE_BYTES
|
||||
private val INDEX_HEADER_SIZE = Int.SIZE_BYTES
|
||||
|
||||
override fun writeData(dataOutput: DataOutput) {
|
||||
dataOutput.writeInt(declarations.size)
|
||||
@@ -101,7 +101,6 @@ class IrDeclarationWriter(private val declarations: List<SerializedDeclaration>)
|
||||
|
||||
for (d in declarations) {
|
||||
dataOutput.writeLong(d.id)
|
||||
dataOutput.writeInt(d.local)
|
||||
dataOutput.writeInt(dataOffset)
|
||||
dataOutput.writeInt(d.size)
|
||||
dataOffset += d.size
|
||||
@@ -116,8 +115,8 @@ class IrDeclarationWriter(private val declarations: List<SerializedDeclaration>)
|
||||
|
||||
class IrMemoryDeclarationWriter(private val declarations: List<SerializedDeclaration>) : IrMemoryWriter() {
|
||||
|
||||
private val SINGLE_INDEX_RECORD_SIZE = 20 // sizeof(Long) + 3 * sizeof(Int).
|
||||
private val INDEX_HEADER_SIZE = 4 // sizeof(Int).
|
||||
private val SINGLE_INDEX_RECORD_SIZE = Long.SIZE_BYTES + 2 * Int.SIZE_BYTES
|
||||
private val INDEX_HEADER_SIZE = Int.SIZE_BYTES
|
||||
|
||||
override fun writeData(dataOutput: DataOutput) {
|
||||
dataOutput.writeInt(declarations.size)
|
||||
@@ -126,7 +125,6 @@ class IrMemoryDeclarationWriter(private val declarations: List<SerializedDeclara
|
||||
|
||||
for (d in declarations) {
|
||||
dataOutput.writeLong(d.id)
|
||||
dataOutput.writeInt(d.local)
|
||||
dataOutput.writeInt(dataOffset)
|
||||
dataOutput.writeInt(d.size)
|
||||
dataOffset += d.size
|
||||
|
||||
@@ -84,7 +84,7 @@ abstract class IrLibraryImpl(
|
||||
class IrMonoliticLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) : IrLibraryImpl(_access) {
|
||||
override fun fileCount(): Int = files.entryCount()
|
||||
|
||||
override fun irDeclaration(index: Long, isLocal: Boolean, fileIndex: Int) = loadIrDeclaration(index, isLocal, fileIndex)
|
||||
override fun irDeclaration(index: Long, fileIndex: Int) = loadIrDeclaration(index, fileIndex)
|
||||
|
||||
override fun symbol(index: Int, fileIndex: Int) = symbols.tableItemBytes(fileIndex, index)
|
||||
|
||||
@@ -96,8 +96,8 @@ class IrMonoliticLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) :
|
||||
|
||||
override fun file(index: Int) = files.tableItemBytes(index)
|
||||
|
||||
private fun loadIrDeclaration(index: Long, isLocal: Boolean, fileIndex: Int) =
|
||||
combinedDeclarations.tableItemBytes(fileIndex, DeclarationId(index, isLocal))
|
||||
private fun loadIrDeclaration(index: Long, fileIndex: Int) =
|
||||
combinedDeclarations.tableItemBytes(fileIndex, DeclarationId(index))
|
||||
|
||||
private val combinedDeclarations: DeclarationIrMultiTableReader by lazy {
|
||||
DeclarationIrMultiTableReader(access.realFiles {
|
||||
@@ -145,14 +145,14 @@ class IrPerFileLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) : Ir
|
||||
}
|
||||
|
||||
private val fileToDeclarationMap = mutableMapOf<Int, DeclarationIrTableReader>()
|
||||
override fun irDeclaration(index: Long, isLocal: Boolean, fileIndex: Int): ByteArray {
|
||||
override fun irDeclaration(index: Long, fileIndex: Int): ByteArray {
|
||||
val dataReader = fileToDeclarationMap.getOrPut(fileIndex) {
|
||||
val fileDirectory = directories[fileIndex]
|
||||
DeclarationIrTableReader(access.realFiles {
|
||||
it.irDeclarations(fileDirectory)
|
||||
})
|
||||
}
|
||||
return dataReader.tableItemBytes(DeclarationId(index, isLocal))
|
||||
return dataReader.tableItemBytes(DeclarationId(index))
|
||||
}
|
||||
|
||||
private val fileToSymbolMap = mutableMapOf<Int, IrArrayReader>()
|
||||
|
||||
Reference in New Issue
Block a user