[KLIB] Add extra debug information for Local signatures
This commit is contained in:
committed by
TeamCityServer
parent
b5c28c1912
commit
b8e5185b61
@@ -52,7 +52,7 @@ message CompositeSignature {
|
||||
message LocalSignature {
|
||||
repeated int32 local_fq_name = 1 [packed=true];
|
||||
optional int64 local_hash = 2;
|
||||
optional int32 description = 3; // debug information
|
||||
optional int32 debug_info = 3;
|
||||
}
|
||||
|
||||
message FileSignature {}
|
||||
|
||||
+12
@@ -38,10 +38,17 @@ class ICKotlinLibrary(private val icData: List<SerializedIrFile>) : IrLibrary {
|
||||
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 indexedTypes = arrayOfNulls<IrArrayMemoryReader>(icData.size)
|
||||
private val indexedSignatures = 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)
|
||||
|
||||
override fun irDeclaration(index: Int, fileIndex: Int): ByteArray =
|
||||
@@ -69,6 +76,11 @@ class ICKotlinLibrary(private val icData: List<SerializedIrFile>) : IrLibrary {
|
||||
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 fileCount(): Int = icData.size
|
||||
|
||||
+4
-1
@@ -146,17 +146,20 @@ abstract class IrLibraryFile {
|
||||
abstract fun signature(index: Int): ByteArray
|
||||
abstract fun string(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 type(index: Int): ByteArray = klib.type(index, fileIndex)
|
||||
override fun signature(index: Int): ByteArray = klib.signature(index, fileIndex)
|
||||
override fun string(index: Int): ByteArray = klib.string(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.deserializeDebugInfo(index: Int): String? = debugInfo(index)?.let { WobblyTF8.decode(it) }
|
||||
|
||||
internal fun IrLibraryFile.deserializeFqName(fqn: List<Int>): String =
|
||||
fqn.joinToString(".", transform = ::deserializeString)
|
||||
|
||||
+17
-4
@@ -127,6 +127,7 @@ open class IrFileSerializer(
|
||||
private val skipMutableState: Boolean = false,
|
||||
private val allowNullTypes: Boolean = false,
|
||||
private val allowErrorStatementOrigins: Boolean = false, // TODO: support InlinerExpressionLocationHint
|
||||
private val addDebugInfo: Boolean = true
|
||||
) {
|
||||
private val loopIndex = mutableMapOf<IrLoop, Int>()
|
||||
private var currentLoopIndex = 0
|
||||
@@ -150,6 +151,8 @@ open class IrFileSerializer(
|
||||
|
||||
private val protoBodyArray = mutableListOf<XStatementOrExpression>()
|
||||
|
||||
private val protoDebugInfoArray = arrayListOf<String>()
|
||||
|
||||
sealed class XStatementOrExpression {
|
||||
abstract fun toByteArray(): ByteArray
|
||||
|
||||
@@ -198,6 +201,11 @@ open class IrFileSerializer(
|
||||
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())
|
||||
|
||||
/* ------- IdSignature ------------------------------------------------------ */
|
||||
@@ -235,6 +243,9 @@ open class IrFileSerializer(
|
||||
|
||||
proto.container = protoIdSignature(signature.container)
|
||||
proto.localId = signature.id
|
||||
if (addDebugInfo) {
|
||||
signature.description?.let { proto.debugInfo = serializeDebugInfo(it) }
|
||||
}
|
||||
|
||||
return proto.build()
|
||||
}
|
||||
@@ -259,7 +270,7 @@ open class IrFileSerializer(
|
||||
proto.addAllLocalFqName(serializeFqName(signature.localFqn))
|
||||
signature.hashSig?.let { proto.localHash = it }
|
||||
if (addDebugInfo) {
|
||||
signature.description?.let { proto.description = serializeDebugInfo(it) }
|
||||
signature.description?.let { proto.debugInfo = serializeDebugInfo(it) }
|
||||
}
|
||||
|
||||
return proto.build()
|
||||
@@ -1493,7 +1504,8 @@ open class IrFileSerializer(
|
||||
IrMemoryArrayWriter(protoIdSignatureArray.map { it.toByteArray() }).writeIntoMemory(),
|
||||
IrMemoryArrayWriter(protoStringArray.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(),
|
||||
IrMemoryStringWriter(protoStringArray).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
|
||||
|
||||
expectActualTable.table.forEach next@{ (expect, actualSymbol) ->
|
||||
|
||||
+3
-3
@@ -22,14 +22,14 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.protobuf.CodedInputStream
|
||||
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.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.FileLocalIdSignature as ProtoFileLocalIdSignature
|
||||
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.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.CommonIdSignature as ProtoCommonIdSignature
|
||||
|
||||
class IrSymbolDeserializer(
|
||||
val symbolTable: ReferenceSymbolTable,
|
||||
@@ -192,7 +192,7 @@ class IrSymbolDeserializer(
|
||||
private fun deserializeLocalIdSignature(proto: ProtoLocalSignature): IdSignature.LocalSignature {
|
||||
val localFqn = fileReader.deserializeFqName(proto.localFqNameList)
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -425,4 +425,4 @@ public final class CompositeSignature extends
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.backend.common.serialization.proto.CompositeSignature)
|
||||
}
|
||||
}
|
||||
+28
-52
@@ -81,7 +81,7 @@ public final class LocalSignature extends
|
||||
}
|
||||
case 24: {
|
||||
bitField0_ |= 0x00000002;
|
||||
description_ = input.readInt32();
|
||||
debugInfo_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -159,33 +159,25 @@ public final class LocalSignature extends
|
||||
return localHash_;
|
||||
}
|
||||
|
||||
public static final int DESCRIPTION_FIELD_NUMBER = 3;
|
||||
private int description_;
|
||||
public static final int DEBUG_INFO_FIELD_NUMBER = 3;
|
||||
private int debugInfo_;
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
public boolean hasDescription() {
|
||||
public boolean hasDebugInfo() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
public int getDescription() {
|
||||
return description_;
|
||||
public int getDebugInfo() {
|
||||
return debugInfo_;
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
localFqName_ = java.util.Collections.emptyList();
|
||||
localHash_ = 0L;
|
||||
description_ = 0;
|
||||
debugInfo_ = 0;
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
@@ -211,7 +203,7 @@ public final class LocalSignature extends
|
||||
output.writeInt64(2, localHash_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
output.writeInt32(3, description_);
|
||||
output.writeInt32(3, debugInfo_);
|
||||
}
|
||||
output.writeRawBytes(unknownFields);
|
||||
}
|
||||
@@ -242,7 +234,7 @@ public final class LocalSignature extends
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeInt32Size(3, description_);
|
||||
.computeInt32Size(3, debugInfo_);
|
||||
}
|
||||
size += unknownFields.size();
|
||||
memoizedSerializedSize = size;
|
||||
@@ -342,7 +334,7 @@ public final class LocalSignature extends
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
localHash_ = 0L;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
description_ = 0;
|
||||
debugInfo_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
return this;
|
||||
}
|
||||
@@ -379,7 +371,7 @@ public final class LocalSignature extends
|
||||
if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
|
||||
to_bitField0_ |= 0x00000002;
|
||||
}
|
||||
result.description_ = description_;
|
||||
result.debugInfo_ = debugInfo_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
return result;
|
||||
}
|
||||
@@ -399,8 +391,8 @@ public final class LocalSignature extends
|
||||
if (other.hasLocalHash()) {
|
||||
setLocalHash(other.getLocalHash());
|
||||
}
|
||||
if (other.hasDescription()) {
|
||||
setDescription(other.getDescription());
|
||||
if (other.hasDebugInfo()) {
|
||||
setDebugInfo(other.getDebugInfo());
|
||||
}
|
||||
setUnknownFields(
|
||||
getUnknownFields().concat(other.unknownFields));
|
||||
@@ -528,50 +520,34 @@ public final class LocalSignature extends
|
||||
return this;
|
||||
}
|
||||
|
||||
private int description_ ;
|
||||
private int debugInfo_ ;
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
public boolean hasDescription() {
|
||||
public boolean hasDebugInfo() {
|
||||
return ((bitField0_ & 0x00000004) == 0x00000004);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
public int getDescription() {
|
||||
return description_;
|
||||
public int getDebugInfo() {
|
||||
return debugInfo_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
public Builder setDescription(int value) {
|
||||
public Builder setDebugInfo(int value) {
|
||||
bitField0_ |= 0x00000004;
|
||||
description_ = value;
|
||||
debugInfo_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
public Builder clearDescription() {
|
||||
public Builder clearDebugInfo() {
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
description_ = 0;
|
||||
debugInfo_ = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -585,4 +561,4 @@ public final class LocalSignature extends
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.backend.common.serialization.proto.LocalSignature)
|
||||
}
|
||||
}
|
||||
+4
-12
@@ -30,19 +30,11 @@ public interface LocalSignatureOrBuilder extends
|
||||
long getLocalHash();
|
||||
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
boolean hasDescription();
|
||||
boolean hasDebugInfo();
|
||||
/**
|
||||
* <code>optional int32 description = 3;</code>
|
||||
*
|
||||
* <pre>
|
||||
* debug information
|
||||
* </pre>
|
||||
* <code>optional int32 debug_info = 3;</code>
|
||||
*/
|
||||
int getDescription();
|
||||
int getDebugInfo();
|
||||
}
|
||||
Reference in New Issue
Block a user