[KLIB] Pass containsErrorCode flag from library/IC cache into deserializer
- Make deserializer track whether error node are allowed.
This commit is contained in:
+1
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.library.IrLibrary
|
||||
import org.jetbrains.kotlin.library.SerializedIrFile
|
||||
import org.jetbrains.kotlin.library.impl.*
|
||||
|
||||
class ICData(val icData: List<SerializedIrFile>, val containsErrorCode: Boolean)
|
||||
|
||||
class ICKotlinLibrary(private val icData: List<SerializedIrFile>) : IrLibrary {
|
||||
override val dataFlowGraph: ByteArray? = null
|
||||
|
||||
+10
-1
@@ -114,7 +114,8 @@ abstract class IrFileDeserializer(
|
||||
val symbolTable: SymbolTable,
|
||||
protected var deserializeBodies: Boolean,
|
||||
private val deserializeFakeOverrides: Boolean,
|
||||
private val fakeOverrideQueue: MutableList<IrClass>
|
||||
private val fakeOverrideQueue: MutableList<IrClass>,
|
||||
private val allowErrorNodes: Boolean
|
||||
) {
|
||||
protected val irFactory: IrFactory get() = symbolTable.irFactory
|
||||
|
||||
@@ -202,6 +203,7 @@ abstract class IrFileDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeErrorType(proto: ProtoErrorType): IrErrorType {
|
||||
require(allowErrorNodes) { "IrErrorType found but error code is not allowed" }
|
||||
val annotations = deserializeAnnotations(proto.annotationList)
|
||||
return IrErrorTypeImpl(null, annotations, Variance.INVARIANT)
|
||||
}
|
||||
@@ -468,6 +470,9 @@ abstract class IrFileDeserializer(
|
||||
proto: ProtoErrorExpression,
|
||||
start: Int, end: Int, type: IrType
|
||||
): IrErrorExpression {
|
||||
require(allowErrorNodes) {
|
||||
"IrErrorExpression($start, $end, \"${deserializeString(proto.description)}\") found but error code is not allowed"
|
||||
}
|
||||
return IrErrorExpressionImpl(start, end, type, deserializeString(proto.description))
|
||||
}
|
||||
|
||||
@@ -475,6 +480,9 @@ abstract class IrFileDeserializer(
|
||||
proto: ProtoErrorCallExpression,
|
||||
start: Int, end: Int, type: IrType
|
||||
): IrErrorCallExpression {
|
||||
require(allowErrorNodes) {
|
||||
"IrErrorCallExpressionImpl($start, $end, \"${deserializeString(proto.description)}\") found but error code is not allowed"
|
||||
}
|
||||
return IrErrorCallExpressionImpl(start, end, type, deserializeString(proto.description)).apply {
|
||||
if (proto.hasReceiver()) {
|
||||
explicitReceiver = deserializeExpression(proto.receiver)
|
||||
@@ -1110,6 +1118,7 @@ abstract class IrFileDeserializer(
|
||||
}
|
||||
|
||||
private fun deserializeErrorDeclaration(proto: ProtoErrorDeclaration): IrErrorDeclaration {
|
||||
require(allowErrorNodes) { "IrErrorDeclaration found but error code is not allowed" }
|
||||
val coordinates = BinaryCoordinates.decode(proto.coordinates)
|
||||
val descriptor = WrappedErrorDescriptor()
|
||||
return irFactory.createErrorDeclaration(coordinates.startOffset, coordinates.endOffset, descriptor).also {
|
||||
|
||||
+15
-12
@@ -77,7 +77,7 @@ abstract class KotlinIrLinker(
|
||||
|
||||
private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>
|
||||
|
||||
abstract inner class BasicIrModuleDeserializer(moduleDescriptor: ModuleDescriptor, override val klib: IrLibrary, override val strategy: DeserializationStrategy) :
|
||||
abstract inner class BasicIrModuleDeserializer(moduleDescriptor: ModuleDescriptor, override val klib: IrLibrary, override val strategy: DeserializationStrategy, private val containsErrorCode: Boolean = false) :
|
||||
IrModuleDeserializer(moduleDescriptor) {
|
||||
|
||||
private val fileToDeserializerMap = mutableMapOf<IrFile, IrDeserializerForFile>()
|
||||
@@ -122,7 +122,7 @@ abstract class KotlinIrLinker(
|
||||
|
||||
for (i in 0 until fileCount) {
|
||||
val fileStream = klib.file(i).codedInputStream
|
||||
files.add(deserializeIrFile(ProtoFile.parseFrom(fileStream, newInstance()), i, delegate))
|
||||
files.add(deserializeIrFile(ProtoFile.parseFrom(fileStream, newInstance()), i, delegate, containsErrorCode))
|
||||
}
|
||||
|
||||
moduleFragment.files.addAll(files)
|
||||
@@ -155,20 +155,22 @@ abstract class KotlinIrLinker(
|
||||
|
||||
override val moduleFragment: IrModuleFragment = IrModuleFragmentImpl(moduleDescriptor, builtIns, emptyList())
|
||||
|
||||
private fun deserializeIrFile(fileProto: ProtoFile, fileIndex: Int, moduleDeserializer: IrModuleDeserializer): IrFile {
|
||||
private fun deserializeIrFile(fileProto: ProtoFile, fileIndex: Int, moduleDeserializer: IrModuleDeserializer, allowErrorNodes: Boolean): IrFile {
|
||||
|
||||
val fileName = fileProto.fileEntry.name
|
||||
|
||||
val fileEntry = NaiveSourceBasedFileEntryImpl(fileName, fileProto.fileEntry.lineStartOffsetsList.toIntArray())
|
||||
|
||||
val fileDeserializer =
|
||||
IrDeserializerForFile(fileProto.annotationList,
|
||||
fileProto.actualsList,
|
||||
fileIndex,
|
||||
!strategy.needBodies,
|
||||
strategy.inlineBodies,
|
||||
deserializeFakeOverrides,
|
||||
moduleDeserializer).apply {
|
||||
IrDeserializerForFile(
|
||||
fileProto.annotationList,
|
||||
fileProto.actualsList,
|
||||
fileIndex,
|
||||
!strategy.needBodies,
|
||||
strategy.inlineBodies,
|
||||
deserializeFakeOverrides,
|
||||
moduleDeserializer, allowErrorNodes
|
||||
).apply {
|
||||
|
||||
// Explicitly exported declarations (e.g. top-level initializers) must be deserialized before all other declarations.
|
||||
// Thus we schedule their deserialization in deserializer's constructor.
|
||||
@@ -230,8 +232,9 @@ abstract class KotlinIrLinker(
|
||||
onlyHeaders: Boolean,
|
||||
inlineBodies: Boolean,
|
||||
deserializeFakeOverrides: Boolean,
|
||||
private val moduleDeserializer: IrModuleDeserializer
|
||||
) : IrFileDeserializer(logger, builtIns, symbolTable, !onlyHeaders, deserializeFakeOverrides, fakeOverrideClassQueue) {
|
||||
private val moduleDeserializer: IrModuleDeserializer,
|
||||
allowErrorNodes: Boolean
|
||||
) : IrFileDeserializer(logger, builtIns, symbolTable, !onlyHeaders, deserializeFakeOverrides, fakeOverrideClassQueue, allowErrorNodes) {
|
||||
|
||||
private var fileLoops = mutableMapOf<Int, IrLoop>()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user