Assume deserialization failure if we could not deserialize a KotlinType.

Various exceptions for IR deserialization.
This commit is contained in:
Alexander Gorshenev
2017-03-31 14:25:28 +03:00
committed by alexander-gorshenev
parent a7b6d1e8ea
commit 9b4a1f1569
4 changed files with 17 additions and 9 deletions
@@ -20,3 +20,9 @@ package org.jetbrains.kotlin.backend.konan
* Represents a compilation error caused by mistakes in an input file, e.g. undefined reference. * Represents a compilation error caused by mistakes in an input file, e.g. undefined reference.
*/ */
class KonanCompilationException(message: String = "", cause: Throwable? = null) : Exception(message, cause) {} class KonanCompilationException(message: String = "", cause: Throwable? = null) : Exception(message, cause) {}
/**
* Internal compiler error: could not deserialize IR for inline function body.
*/
class KonanIrDeserializationException(message: String = "", cause: Throwable? = null) : Exception(message, cause)
@@ -87,6 +87,7 @@ internal class IrDescriptorDeserializer(val context: Context,
val text = proto.getDebugText() val text = proto.getDebugText()
val typeProto = localDeserializer.typeTable[index] val typeProto = localDeserializer.typeTable[index]
val type = localDeserializer.deserializeInlineType(typeProto) val type = localDeserializer.deserializeInlineType(typeProto)
if (type.isError) throw KonanIrDeserializationException("Could not deserialize KotlinType: $text $type")
context.log("### deserialized Kotlin Type index=$index, text=$text:\t$type") context.log("### deserialized Kotlin Type index=$index, text=$text:\t$type")
return type return type
@@ -111,7 +112,7 @@ internal class IrDescriptorDeserializer(val context: Context,
} }
// TODO // TODO
// proto.hasClazz() -> // proto.hasClazz() ->
else -> error("Unexpected descriptor kind") else -> TODO("Unexpected descriptor kind")
} }
} }
@@ -272,7 +273,7 @@ internal class IrDescriptorDeserializer(val context: Context,
newPropertyDescriptor.getter newPropertyDescriptor.getter
is PropertySetterDescriptor -> is PropertySetterDescriptor ->
newPropertyDescriptor.setter newPropertyDescriptor.setter
else -> error("Unexpected accessor kind") else -> TODO("Unexpected accessor kind")
} }
descriptorIndex.put(proto.index, newDescriptor!!) descriptorIndex.put(proto.index, newDescriptor!!)
@@ -312,7 +313,7 @@ internal class IrDescriptorDeserializer(val context: Context,
is ClassDescriptor -> parent.getUnsubstitutedMemberScope() is ClassDescriptor -> parent.getUnsubstitutedMemberScope()
is PackageFragmentDescriptor -> parent.getMemberScope() is PackageFragmentDescriptor -> parent.getMemberScope()
is PackageViewDescriptor -> parent.memberScope is PackageViewDescriptor -> parent.memberScope
else -> error("could not get a member scope") else -> TODO("could not get a member scope")
} }
} }
@@ -450,7 +451,7 @@ internal class IrDescriptorDeserializer(val context: Context,
// class descriptors here? // class descriptors here?
//substituteClass(proto, originalDescriptor) //substituteClass(proto, originalDescriptor)
originalDescriptor originalDescriptor
else -> error("unexpected type of public function") else -> TODO("unexpected type of public function")
} }
} }
@@ -72,7 +72,7 @@ class LocalDeclarationDeserializer(val rootFunction: FunctionDescriptor, val mod
return module.findClassAcrossModuleDependencies(nameResolver.getClassId(fqNameIndex))!! return module.findClassAcrossModuleDependencies(nameResolver.getClassId(fqNameIndex))!!
QualifiedName.Kind.PACKAGE -> QualifiedName.Kind.PACKAGE ->
return module.getPackage(packageName) return module.getPackage(packageName)
else -> error("Unexpected descriptor kind.") else -> TODO("Unexpected descriptor kind.")
} }
} }
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.backend.konan.Context
import org.jetbrains.kotlin.backend.konan.descriptors.getMemberScope import org.jetbrains.kotlin.backend.konan.descriptors.getMemberScope
import org.jetbrains.kotlin.backend.konan.ir.ir2string import org.jetbrains.kotlin.backend.konan.ir.ir2string
import org.jetbrains.kotlin.backend.konan.ir.ir2stringWhole import org.jetbrains.kotlin.backend.konan.ir.ir2stringWhole
import org.jetbrains.kotlin.backend.konan.KonanIrDeserializationException
import org.jetbrains.kotlin.backend.konan.llvm.base64Decode import org.jetbrains.kotlin.backend.konan.llvm.base64Decode
import org.jetbrains.kotlin.backend.konan.llvm.base64Encode import org.jetbrains.kotlin.backend.konan.llvm.base64Encode
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
@@ -313,7 +314,7 @@ internal class IrSerializer(val context: Context,
-> return KonanIr.IrTypeOperator.INSTANCEOF -> return KonanIr.IrTypeOperator.INSTANCEOF
IrTypeOperator.NOT_INSTANCEOF IrTypeOperator.NOT_INSTANCEOF
-> return KonanIr.IrTypeOperator.NOT_INSTANCEOF -> return KonanIr.IrTypeOperator.NOT_INSTANCEOF
else -> error("Unknown type operator") else -> TODO("Unknown type operator")
} }
} }
@@ -689,7 +690,7 @@ internal class IrDeserializer(val context: Context,
IrUnaryPrimitiveImpl(start, end, null, descriptor) IrUnaryPrimitiveImpl(start, end, null, descriptor)
KonanIr.IrCall.Primitive.BINARY -> KonanIr.IrCall.Primitive.BINARY ->
IrBinaryPrimitiveImpl(start, end, null, descriptor) IrBinaryPrimitiveImpl(start, end, null, descriptor)
else -> error("Unexpected primitive IrCall.") else -> TODO("Unexpected primitive IrCall.")
} }
deserializeMemberAccessCommon(call, proto.memberAccess) deserializeMemberAccessCommon(call, proto.memberAccess)
return call return call
@@ -802,7 +803,7 @@ internal class IrDeserializer(val context: Context,
-> return IrTypeOperator.INSTANCEOF -> return IrTypeOperator.INSTANCEOF
KonanIr.IrTypeOperator.NOT_INSTANCEOF KonanIr.IrTypeOperator.NOT_INSTANCEOF
-> return IrTypeOperator.NOT_INSTANCEOF -> return IrTypeOperator.NOT_INSTANCEOF
else -> error("Unknown type operator") else -> TODO("Unknown type operator")
} }
} }
@@ -1037,7 +1038,7 @@ internal class IrDeserializer(val context: Context,
val proto = (rootFunction as DeserializedSimpleFunctionDescriptor).proto val proto = (rootFunction as DeserializedSimpleFunctionDescriptor).proto
if (!proto.hasExtension(KonanLinkData.inlineIrBody)) { if (!proto.hasExtension(KonanLinkData.inlineIrBody)) {
error("$rootFunction doesn't have ir serialized.") throw KonanIrDeserializationException("$rootFunction doesn't have ir serialized.")
} }
val inlineProto = proto.getExtension(KonanLinkData.inlineIrBody) val inlineProto = proto.getExtension(KonanLinkData.inlineIrBody)