[KLIB] Add extra debug information for Local signatures

This commit is contained in:
Roman Artemev
2021-05-26 20:01:08 +03:00
committed by TeamCityServer
parent b5c28c1912
commit b8e5185b61
18 changed files with 120 additions and 84 deletions
@@ -25,7 +25,8 @@ class RemoteIncrementalResultsConsumer(
strings: ByteArray, strings: ByteArray,
declarations: ByteArray, declarations: ByteArray,
bodies: ByteArray, bodies: ByteArray,
fqn: ByteArray fqn: ByteArray,
debugInfo: ByteArray?
) { ) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
@@ -52,7 +52,7 @@ message CompositeSignature {
message LocalSignature { message LocalSignature {
repeated int32 local_fq_name = 1 [packed=true]; repeated int32 local_fq_name = 1 [packed=true];
optional int64 local_hash = 2; optional int64 local_hash = 2;
optional int32 description = 3; // debug information optional int32 debug_info = 3;
} }
message FileSignature {} message FileSignature {}
@@ -38,10 +38,17 @@ class ICKotlinLibrary(private val icData: List<SerializedIrFile>) : IrLibrary {
return reader.tableItemBytes(index) return reader.tableItemBytes(index)
} }
private inline fun <R : IrArrayReader?> Array<R?>.itemNullableBytes(fileIndex: Int, index: Int, factory: () -> R): ByteArray? {
val reader = this[fileIndex] ?: factory().also { this[fileIndex] = it }
return reader?.tableItemBytes(index)
}
private val indexedDeclarations = arrayOfNulls<DeclarationIrTableMemoryReader>(icData.size) private val indexedDeclarations = arrayOfNulls<DeclarationIrTableMemoryReader>(icData.size)
private val indexedTypes = arrayOfNulls<IrArrayMemoryReader>(icData.size) private val indexedTypes = arrayOfNulls<IrArrayMemoryReader>(icData.size)
private val indexedSignatures = arrayOfNulls<IrArrayMemoryReader>(icData.size) private val indexedSignatures = arrayOfNulls<IrArrayMemoryReader>(icData.size)
private val indexedStrings = arrayOfNulls<IrArrayMemoryReader>(icData.size) private val indexedStrings = arrayOfNulls<IrArrayMemoryReader>(icData.size)
private val indexedDebugInfos = arrayOfNulls<IrArrayMemoryReader?>(icData.size)
private val indexedBodies = arrayOfNulls<IrArrayMemoryReader>(icData.size) private val indexedBodies = arrayOfNulls<IrArrayMemoryReader>(icData.size)
override fun irDeclaration(index: Int, fileIndex: Int): ByteArray = override fun irDeclaration(index: Int, fileIndex: Int): ByteArray =
@@ -69,6 +76,11 @@ class ICKotlinLibrary(private val icData: List<SerializedIrFile>) : IrLibrary {
IrArrayMemoryReader(icData[fileIndex].bodies) IrArrayMemoryReader(icData[fileIndex].bodies)
} }
override fun debugInfo(index: Int, fileIndex: Int): ByteArray? =
indexedDebugInfos.itemNullableBytes(fileIndex, index) {
icData[fileIndex].debugInfo?.let { IrArrayMemoryReader(it) }
}
override fun file(index: Int): ByteArray = icData[index].fileData override fun file(index: Int): ByteArray = icData[index].fileData
override fun fileCount(): Int = icData.size override fun fileCount(): Int = icData.size
@@ -146,17 +146,20 @@ abstract class IrLibraryFile {
abstract fun signature(index: Int): ByteArray abstract fun signature(index: Int): ByteArray
abstract fun string(index: Int): ByteArray abstract fun string(index: Int): ByteArray
abstract fun body(index: Int): ByteArray abstract fun body(index: Int): ByteArray
abstract fun debugInfo(index: Int): ByteArray?
} }
class IrLibraryFileFromKlib(private val klib: IrLibrary, private val fileIndex: Int): IrLibraryFile() { class IrLibraryFileFromKlib(private val klib: IrLibrary, private val fileIndex: Int) : IrLibraryFile() {
override fun irDeclaration(index: Int): ByteArray = klib.irDeclaration(index, fileIndex) override fun irDeclaration(index: Int): ByteArray = klib.irDeclaration(index, fileIndex)
override fun type(index: Int): ByteArray = klib.type(index, fileIndex) override fun type(index: Int): ByteArray = klib.type(index, fileIndex)
override fun signature(index: Int): ByteArray = klib.signature(index, fileIndex) override fun signature(index: Int): ByteArray = klib.signature(index, fileIndex)
override fun string(index: Int): ByteArray = klib.string(index, fileIndex) override fun string(index: Int): ByteArray = klib.string(index, fileIndex)
override fun body(index: Int): ByteArray = klib.body(index, fileIndex) override fun body(index: Int): ByteArray = klib.body(index, fileIndex)
override fun debugInfo(index: Int): ByteArray? = klib.debugInfo(index, fileIndex)
} }
internal fun IrLibraryFile.deserializeString(index: Int): String = WobblyTF8.decode(string(index)) internal fun IrLibraryFile.deserializeString(index: Int): String = WobblyTF8.decode(string(index))
internal fun IrLibraryFile.deserializeDebugInfo(index: Int): String? = debugInfo(index)?.let { WobblyTF8.decode(it) }
internal fun IrLibraryFile.deserializeFqName(fqn: List<Int>): String = internal fun IrLibraryFile.deserializeFqName(fqn: List<Int>): String =
fqn.joinToString(".", transform = ::deserializeString) fqn.joinToString(".", transform = ::deserializeString)
@@ -127,6 +127,7 @@ open class IrFileSerializer(
private val skipMutableState: Boolean = false, private val skipMutableState: Boolean = false,
private val allowNullTypes: Boolean = false, private val allowNullTypes: Boolean = false,
private val allowErrorStatementOrigins: Boolean = false, // TODO: support InlinerExpressionLocationHint private val allowErrorStatementOrigins: Boolean = false, // TODO: support InlinerExpressionLocationHint
private val addDebugInfo: Boolean = true
) { ) {
private val loopIndex = mutableMapOf<IrLoop, Int>() private val loopIndex = mutableMapOf<IrLoop, Int>()
private var currentLoopIndex = 0 private var currentLoopIndex = 0
@@ -150,6 +151,8 @@ open class IrFileSerializer(
private val protoBodyArray = mutableListOf<XStatementOrExpression>() private val protoBodyArray = mutableListOf<XStatementOrExpression>()
private val protoDebugInfoArray = arrayListOf<String>()
sealed class XStatementOrExpression { sealed class XStatementOrExpression {
abstract fun toByteArray(): ByteArray abstract fun toByteArray(): ByteArray
@@ -198,6 +201,11 @@ open class IrFileSerializer(
protoStringArray.size - 1 protoStringArray.size - 1
} }
private fun serializeDebugInfo(value: String): Int {
protoDebugInfoArray.add(value)
return protoDebugInfoArray.size - 1
}
private fun serializeName(name: Name): Int = serializeString(name.toString()) private fun serializeName(name: Name): Int = serializeString(name.toString())
/* ------- IdSignature ------------------------------------------------------ */ /* ------- IdSignature ------------------------------------------------------ */
@@ -235,6 +243,9 @@ open class IrFileSerializer(
proto.container = protoIdSignature(signature.container) proto.container = protoIdSignature(signature.container)
proto.localId = signature.id proto.localId = signature.id
if (addDebugInfo) {
signature.description?.let { proto.debugInfo = serializeDebugInfo(it) }
}
return proto.build() return proto.build()
} }
@@ -259,7 +270,7 @@ open class IrFileSerializer(
proto.addAllLocalFqName(serializeFqName(signature.localFqn)) proto.addAllLocalFqName(serializeFqName(signature.localFqn))
signature.hashSig?.let { proto.localHash = it } signature.hashSig?.let { proto.localHash = it }
if (addDebugInfo) { if (addDebugInfo) {
signature.description?.let { proto.description = serializeDebugInfo(it) } signature.description?.let { proto.debugInfo = serializeDebugInfo(it) }
} }
return proto.build() return proto.build()
@@ -1493,7 +1504,8 @@ open class IrFileSerializer(
IrMemoryArrayWriter(protoIdSignatureArray.map { it.toByteArray() }).writeIntoMemory(), IrMemoryArrayWriter(protoIdSignatureArray.map { it.toByteArray() }).writeIntoMemory(),
IrMemoryArrayWriter(protoStringArray.map { it.toByteArray() }).writeIntoMemory(), IrMemoryArrayWriter(protoStringArray.map { it.toByteArray() }).writeIntoMemory(),
IrMemoryArrayWriter(protoBodyArray.map { it.toByteArray() }).writeIntoMemory(), IrMemoryArrayWriter(protoBodyArray.map { it.toByteArray() }).writeIntoMemory(),
IrMemoryDeclarationWriter(topLevelDeclarations).writeIntoMemory() IrMemoryDeclarationWriter(topLevelDeclarations).writeIntoMemory(),
debugInfo = null
) )
} }
@@ -1555,11 +1567,12 @@ open class IrFileSerializer(
IrMemoryArrayWriter(protoIdSignatureArray.map { it.toByteArray() }).writeIntoMemory(), IrMemoryArrayWriter(protoIdSignatureArray.map { it.toByteArray() }).writeIntoMemory(),
IrMemoryStringWriter(protoStringArray).writeIntoMemory(), IrMemoryStringWriter(protoStringArray).writeIntoMemory(),
IrMemoryArrayWriter(protoBodyArray.map { it.toByteArray() }).writeIntoMemory(), IrMemoryArrayWriter(protoBodyArray.map { it.toByteArray() }).writeIntoMemory(),
IrMemoryDeclarationWriter(topLevelDeclarations).writeIntoMemory() IrMemoryDeclarationWriter(topLevelDeclarations).writeIntoMemory(),
if (addDebugInfo) IrMemoryStringWriter(protoDebugInfoArray).writeIntoMemory() else null
) )
} }
fun serializeExpectActualSubstitutionTable(proto: ProtoFile.Builder) { private fun serializeExpectActualSubstitutionTable(proto: ProtoFile.Builder) {
if (skipExpects) return if (skipExpects) return
expectActualTable.table.forEach next@{ (expect, actualSymbol) -> expectActualTable.table.forEach next@{ (expect, actualSymbol) ->
@@ -22,14 +22,14 @@ import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.protobuf.CodedInputStream import org.jetbrains.kotlin.protobuf.CodedInputStream
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
import org.jetbrains.kotlin.backend.common.serialization.proto.AccessorIdSignature as ProtoAccessorIdSignature import org.jetbrains.kotlin.backend.common.serialization.proto.AccessorIdSignature as ProtoAccessorIdSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.LocalSignature as ProtoLocalSignature import org.jetbrains.kotlin.backend.common.serialization.proto.CommonIdSignature as ProtoCommonIdSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.CompositeSignature as ProtoCompositeSignature import org.jetbrains.kotlin.backend.common.serialization.proto.CompositeSignature as ProtoCompositeSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.FileLocalIdSignature as ProtoFileLocalIdSignature import org.jetbrains.kotlin.backend.common.serialization.proto.FileLocalIdSignature as ProtoFileLocalIdSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.ScopeLocalIdSignature as ProtoScopeLocalIdSignature import org.jetbrains.kotlin.backend.common.serialization.proto.ScopeLocalIdSignature as ProtoScopeLocalIdSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.FileSignature as ProtoFileSignature import org.jetbrains.kotlin.backend.common.serialization.proto.FileSignature as ProtoFileSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.IdSignature as ProtoIdSignature import org.jetbrains.kotlin.backend.common.serialization.proto.IdSignature as ProtoIdSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.LocalSignature as ProtoLocalSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.LoweredIdSignature as ProtoLoweredIdSignature import org.jetbrains.kotlin.backend.common.serialization.proto.LoweredIdSignature as ProtoLoweredIdSignature
import org.jetbrains.kotlin.backend.common.serialization.proto.CommonIdSignature as ProtoCommonIdSignature
class IrSymbolDeserializer( class IrSymbolDeserializer(
val symbolTable: ReferenceSymbolTable, val symbolTable: ReferenceSymbolTable,
@@ -192,7 +192,7 @@ class IrSymbolDeserializer(
private fun deserializeLocalIdSignature(proto: ProtoLocalSignature): IdSignature.LocalSignature { private fun deserializeLocalIdSignature(proto: ProtoLocalSignature): IdSignature.LocalSignature {
val localFqn = fileReader.deserializeFqName(proto.localFqNameList) val localFqn = fileReader.deserializeFqName(proto.localFqNameList)
val localHash = if (proto.hasLocalHash()) proto.localHash else null val localHash = if (proto.hasLocalHash()) proto.localHash else null
val description = if (proto.hasDescription()) fileReader.deserializeDebugInfo(proto.description) else null val description = if (proto.hasDebugInfo()) fileReader.deserializeDebugInfo(proto.debugInfo) else null
return IdSignature.LocalSignature(localFqn, localHash, description) return IdSignature.LocalSignature(localFqn, localHash, description)
} }
@@ -425,4 +425,4 @@ public final class CompositeSignature extends
} }
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.backend.common.serialization.proto.CompositeSignature) // @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.backend.common.serialization.proto.CompositeSignature)
} }
@@ -81,7 +81,7 @@ public final class LocalSignature extends
} }
case 24: { case 24: {
bitField0_ |= 0x00000002; bitField0_ |= 0x00000002;
description_ = input.readInt32(); debugInfo_ = input.readInt32();
break; break;
} }
} }
@@ -159,33 +159,25 @@ public final class LocalSignature extends
return localHash_; return localHash_;
} }
public static final int DESCRIPTION_FIELD_NUMBER = 3; public static final int DEBUG_INFO_FIELD_NUMBER = 3;
private int description_; private int debugInfo_;
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
public boolean hasDescription() { public boolean hasDebugInfo() {
return ((bitField0_ & 0x00000002) == 0x00000002); return ((bitField0_ & 0x00000002) == 0x00000002);
} }
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
public int getDescription() { public int getDebugInfo() {
return description_; return debugInfo_;
} }
private void initFields() { private void initFields() {
localFqName_ = java.util.Collections.emptyList(); localFqName_ = java.util.Collections.emptyList();
localHash_ = 0L; localHash_ = 0L;
description_ = 0; debugInfo_ = 0;
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
public final boolean isInitialized() { public final boolean isInitialized() {
@@ -211,7 +203,7 @@ public final class LocalSignature extends
output.writeInt64(2, localHash_); output.writeInt64(2, localHash_);
} }
if (((bitField0_ & 0x00000002) == 0x00000002)) { if (((bitField0_ & 0x00000002) == 0x00000002)) {
output.writeInt32(3, description_); output.writeInt32(3, debugInfo_);
} }
output.writeRawBytes(unknownFields); output.writeRawBytes(unknownFields);
} }
@@ -242,7 +234,7 @@ public final class LocalSignature extends
} }
if (((bitField0_ & 0x00000002) == 0x00000002)) { if (((bitField0_ & 0x00000002) == 0x00000002)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(3, description_); .computeInt32Size(3, debugInfo_);
} }
size += unknownFields.size(); size += unknownFields.size();
memoizedSerializedSize = size; memoizedSerializedSize = size;
@@ -342,7 +334,7 @@ public final class LocalSignature extends
bitField0_ = (bitField0_ & ~0x00000001); bitField0_ = (bitField0_ & ~0x00000001);
localHash_ = 0L; localHash_ = 0L;
bitField0_ = (bitField0_ & ~0x00000002); bitField0_ = (bitField0_ & ~0x00000002);
description_ = 0; debugInfo_ = 0;
bitField0_ = (bitField0_ & ~0x00000004); bitField0_ = (bitField0_ & ~0x00000004);
return this; return this;
} }
@@ -379,7 +371,7 @@ public final class LocalSignature extends
if (((from_bitField0_ & 0x00000004) == 0x00000004)) { if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
to_bitField0_ |= 0x00000002; to_bitField0_ |= 0x00000002;
} }
result.description_ = description_; result.debugInfo_ = debugInfo_;
result.bitField0_ = to_bitField0_; result.bitField0_ = to_bitField0_;
return result; return result;
} }
@@ -399,8 +391,8 @@ public final class LocalSignature extends
if (other.hasLocalHash()) { if (other.hasLocalHash()) {
setLocalHash(other.getLocalHash()); setLocalHash(other.getLocalHash());
} }
if (other.hasDescription()) { if (other.hasDebugInfo()) {
setDescription(other.getDescription()); setDebugInfo(other.getDebugInfo());
} }
setUnknownFields( setUnknownFields(
getUnknownFields().concat(other.unknownFields)); getUnknownFields().concat(other.unknownFields));
@@ -528,50 +520,34 @@ public final class LocalSignature extends
return this; return this;
} }
private int description_ ; private int debugInfo_ ;
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
public boolean hasDescription() { public boolean hasDebugInfo() {
return ((bitField0_ & 0x00000004) == 0x00000004); return ((bitField0_ & 0x00000004) == 0x00000004);
} }
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
public int getDescription() { public int getDebugInfo() {
return description_; return debugInfo_;
} }
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
public Builder setDescription(int value) { public Builder setDebugInfo(int value) {
bitField0_ |= 0x00000004; bitField0_ |= 0x00000004;
description_ = value; debugInfo_ = value;
return this; return this;
} }
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
public Builder clearDescription() { public Builder clearDebugInfo() {
bitField0_ = (bitField0_ & ~0x00000004); bitField0_ = (bitField0_ & ~0x00000004);
description_ = 0; debugInfo_ = 0;
return this; return this;
} }
@@ -585,4 +561,4 @@ public final class LocalSignature extends
} }
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.backend.common.serialization.proto.LocalSignature) // @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.backend.common.serialization.proto.LocalSignature)
} }
@@ -30,19 +30,11 @@ public interface LocalSignatureOrBuilder extends
long getLocalHash(); long getLocalHash();
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
boolean hasDescription(); boolean hasDebugInfo();
/** /**
* <code>optional int32 description = 3;</code> * <code>optional int32 debug_info = 3;</code>
*
* <pre>
* debug information
* </pre>
*/ */
int getDescription(); int getDebugInfo();
} }
@@ -130,7 +130,7 @@ fun generateKLib(
val irData = compiledIrFiles[f] ?: error("No Ir Data found for file $f") val irData = compiledIrFiles[f] ?: error("No Ir Data found for file $f")
val metaFile = compiledMetaFiles[f] ?: error("No Meta Data found for file $f") val metaFile = compiledMetaFiles[f] ?: error("No Meta Data found for file $f")
val irFile = with(irData) { val irFile = with(irData) {
SerializedIrFile(fileData, String(fqn), f.path.replace('\\', '/'), types, signatures, strings, bodies, declarations) SerializedIrFile(fileData, String(fqn), f.path.replace('\\', '/'), types, signatures, strings, bodies, declarations, debugInfo)
} }
storage.add(KotlinFileSerializedData(metaFile.metadata, irFile)) storage.add(KotlinFileSerializedData(metaFile.metadata, irFile))
} }
@@ -523,7 +523,7 @@ fun serializeModuleIntoKlib(
incrementalResultsConsumer?.run { incrementalResultsConsumer?.run {
processPackagePart(ioFile, compiledFile.metadata, empty, empty) processPackagePart(ioFile, compiledFile.metadata, empty, empty)
with(compiledFile.irData) { with(compiledFile.irData) {
processIrFile(ioFile, fileData, types, signatures, strings, declarations, bodies, fqName.toByteArray()) processIrFile(ioFile, fileData, types, signatures, strings, declarations, bodies, fqName.toByteArray(), debugInfo)
} }
} }
} }
@@ -64,6 +64,7 @@ interface IrLibrary {
fun signature(index: Int, fileIndex: Int): ByteArray fun signature(index: Int, fileIndex: Int): ByteArray
fun string(index: Int, fileIndex: Int): ByteArray fun string(index: Int, fileIndex: Int): ByteArray
fun body(index: Int, fileIndex: Int): ByteArray fun body(index: Int, fileIndex: Int): ByteArray
fun debugInfo(index: Int, fileIndex: Int): ByteArray?
fun file(index: Int): ByteArray fun file(index: Int): ByteArray
fun fileCount(): Int fun fileCount(): Int
} }
@@ -70,11 +70,14 @@ interface IrKotlinLibraryLayout : KotlinLibraryLayout {
get() = File(irDir, "files.knf") get() = File(irDir, "files.knf")
val dataFlowGraphFile val dataFlowGraphFile
get() = File(irDir, "module_data_flow_graph") get() = File(irDir, "module_data_flow_graph")
val irDebugInfo
get() = File(irDir, "debugInfo.knd")
fun irDeclarations(file: File): File = File(file, "irCombined.knd") fun irDeclarations(file: File): File = File(file, "irDeclarations.knd")
fun irTypes(file: File): File = File(file, "types.knt") fun irTypes(file: File): File = File(file, "types.knt")
fun irSignatures(file: File): File = File(file, "signatures.knt") fun irSignatures(file: File): File = File(file, "signatures.knt")
fun irStrings(file: File): File = File(file, "strings.knt") fun irStrings(file: File): File = File(file, "strings.knt")
fun irBodies(file: File): File = File(file, "body.knb") fun irBodies(file: File): File = File(file, "body.knb")
fun irFile(file: File): File = File(file, "file.knf") fun irFile(file: File): File = File(file, "file.knf")
fun irDebugInfo(file: File): File = File(file, "debugInfo.knd")
} }
@@ -60,7 +60,8 @@ class SerializedIrFile(
val signatures: ByteArray, val signatures: ByteArray,
val strings: ByteArray, val strings: ByteArray,
val bodies: ByteArray, val bodies: ByteArray,
val declarations: ByteArray val declarations: ByteArray,
val debugInfo: ByteArray?
) )
class SerializedIrModule(val files: Collection<SerializedIrFile>) class SerializedIrModule(val files: Collection<SerializedIrFile>)
@@ -5,7 +5,10 @@
package org.jetbrains.kotlin.library.impl package org.jetbrains.kotlin.library.impl
import org.jetbrains.kotlin.library.* import org.jetbrains.kotlin.library.IrKotlinLibraryLayout
import org.jetbrains.kotlin.library.IrWriter
import org.jetbrains.kotlin.library.SerializedIrFile
import org.jetbrains.kotlin.library.SerializedIrModule
abstract class IrWriterImpl(val irLayout: IrKotlinLibraryLayout) : IrWriter { abstract class IrWriterImpl(val irLayout: IrKotlinLibraryLayout) : IrWriter {
override fun addDataFlowGraph(dataFlowGraph: ByteArray) { override fun addDataFlowGraph(dataFlowGraph: ByteArray) {
@@ -25,6 +28,7 @@ class IrMonoliticWriterImpl(_irLayout: IrKotlinLibraryLayout) : IrWriterImpl(_ir
IrArrayWriter(map { it.signatures }).writeIntoFile(irLayout.irSignatures.absolutePath) IrArrayWriter(map { it.signatures }).writeIntoFile(irLayout.irSignatures.absolutePath)
IrArrayWriter(map { it.strings }).writeIntoFile(irLayout.irStrings.absolutePath) IrArrayWriter(map { it.strings }).writeIntoFile(irLayout.irStrings.absolutePath)
IrArrayWriter(map { it.bodies }).writeIntoFile(irLayout.irBodies.absolutePath) IrArrayWriter(map { it.bodies }).writeIntoFile(irLayout.irBodies.absolutePath)
IrArrayWriter(mapNotNull { it.debugInfo }).writeIntoFile(irLayout.irDebugInfo.absolutePath)
} }
} }
} }
@@ -108,6 +108,8 @@ class IrMonoliticLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) :
override fun body(index: Int, fileIndex: Int) = bodies.tableItemBytes(fileIndex, index) override fun body(index: Int, fileIndex: Int) = bodies.tableItemBytes(fileIndex, index)
override fun debugInfo(index: Int, fileIndex: Int) = debugInfos?.tableItemBytes(fileIndex, index)
override fun file(index: Int) = files.tableItemBytes(index) override fun file(index: Int) = files.tableItemBytes(index)
private fun loadIrDeclaration(index: Int, fileIndex: Int) = private fun loadIrDeclaration(index: Int, fileIndex: Int) =
@@ -143,6 +145,12 @@ class IrMonoliticLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) :
}) })
} }
private val debugInfos: IrMultiArrayFileReader? by lazy {
access.realFiles {
it.irDebugInfo.let { diFile -> if (diFile.exists) IrMultiArrayFileReader(diFile) else null }
}
}
private val files: IrArrayFileReader by lazy { private val files: IrArrayFileReader by lazy {
IrArrayFileReader(access.realFiles { IrArrayFileReader(access.realFiles {
it.irFiles it.irFiles
@@ -212,6 +220,23 @@ class IrPerFileLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) : Ir
return dataReader.tableItemBytes(index) return dataReader.tableItemBytes(index)
} }
private val fileToDebugInfoMap = mutableMapOf<Int, IrArrayFileReader?>()
override fun debugInfo(index: Int, fileIndex: Int): ByteArray? {
val dataReader = fileToDebugInfoMap.getOrPut(fileIndex) {
val fileDirectory = directories[fileIndex]
access.realFiles {
it.irDebugInfo(fileDirectory).let { diFile ->
if (diFile.exists) {
IrArrayFileReader(diFile)
} else null
}
}
}
return dataReader?.tableItemBytes(index)
}
override fun file(index: Int): ByteArray { override fun file(index: Int): ByteArray {
return access.realFiles { return access.realFiles {
it.irFile(directories[index]).readBytes() it.irFile(directories[index]).readBytes()
@@ -150,6 +150,8 @@ class ExtractingIrLibraryImpl(val zipped: IrLibraryLayoutImpl) :
override val irBodies: File by lazy { zipped.extract(zipped.irBodies) } override val irBodies: File by lazy { zipped.extract(zipped.irBodies) }
override val irFiles: File by lazy { zipped.extract(zipped.irFiles) } override val irFiles: File by lazy { zipped.extract(zipped.irFiles) }
override val irDebugInfo: File by lazy { zipped.extract(zipped.irDebugInfo) }
} }
internal fun zippedKotlinLibraryChecks(klibFile: File) { internal fun zippedKotlinLibraryChecks(klibFile: File) {
@@ -49,7 +49,8 @@ interface IncrementalResultsConsumer {
strings: ByteArray, strings: ByteArray,
declarations: ByteArray, declarations: ByteArray,
bodies: ByteArray, bodies: ByteArray,
fqn: ByteArray fqn: ByteArray,
debugInfo: ByteArray?
) )
} }
@@ -134,9 +135,10 @@ open class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
strings: ByteArray, strings: ByteArray,
declarations: ByteArray, declarations: ByteArray,
bodies: ByteArray, bodies: ByteArray,
fqn: ByteArray fqn: ByteArray,
debugInfo: ByteArray?
) { ) {
_irFileData[sourceFile] = IrTranslationResultValue(fileData, types, signatures, strings, declarations, bodies, fqn) _irFileData[sourceFile] = IrTranslationResultValue(fileData, types, signatures, strings, declarations, bodies, fqn, debugInfo)
} }
} }
@@ -26,5 +26,6 @@ data class IrTranslationResultValue(
val strings: ByteArray, val strings: ByteArray,
val declarations: ByteArray, val declarations: ByteArray,
val bodies: ByteArray, val bodies: ByteArray,
val fqn: ByteArray val fqn: ByteArray,
val debugInfo: ByteArray?
) )