[FIR2IR] Replace 'throw AssertionError()' with error() / assert() {...}

This commit is contained in:
Mikhail Glukhikh
2020-06-29 13:42:04 +03:00
parent 69ec8f2d89
commit 6cb3687d5d
16 changed files with 33 additions and 37 deletions
@@ -80,11 +80,11 @@ open class FirJvmMangleComputer(
}
if (parentClassId != null && !parentClassId.isLocal) {
val parentClassLike = session.firSymbolProvider.getClassLikeSymbolByFqName(parentClassId)?.fir
?: throw AssertionError("Attempt to find parent ($parentClassId) for probably-local declaration!")
?: error("Attempt to find parent ($parentClassId) for probably-local declaration!")
if (parentClassLike is FirRegularClass || parentClassLike is FirTypeAlias) {
parentClassLike.accept(this@FirJvmMangleComputer, false)
} else {
throw AssertionError("Strange class-like declaration: ${parentClassLike.render()}")
error("Strange class-like declaration: ${parentClassLike.render()}")
}
} else if (parentClassId == null && !parentPackageFqName.isRoot) {
builder.appendName(parentPackageFqName.asString())
@@ -106,7 +106,7 @@ fun FirClassifierSymbol<*>.toSymbol(
is FirClassSymbol -> {
classifierStorage.getIrClassSymbol(this)
}
else -> throw AssertionError("Should not be here: $this")
else -> error("Unknown symbol: $this")
}
}
@@ -127,7 +127,7 @@ fun FirReference.toSymbol(
resolvedSymbol.toSymbol(session, classifierStorage)
}
else -> {
throw AssertionError("Unknown symbol: $resolvedSymbol")
error("Unknown symbol: $resolvedSymbol")
}
}
}
@@ -451,6 +451,6 @@ class Fir2IrClassifierStorage(
typeContext: ConversionTypeContext
): IrTypeParameterSymbol {
return getCachedIrTypeParameter(firTypeParameterSymbol.fir, typeContext = typeContext)?.symbol
?: throw AssertionError("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
?: error("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
}
}
@@ -158,7 +158,7 @@ class Fir2IrConverter(
null
}
else -> {
throw AssertionError("Unexpected member: ${declaration::class}")
error("Unexpected member: ${declaration::class}")
}
}
}
@@ -201,7 +201,7 @@ class Fir2IrDeclarationStorage(
val containerFile = when (firBasedSymbol) {
is FirCallableSymbol -> firProvider.getFirCallableContainerFile(firBasedSymbol)
is FirClassLikeSymbol -> firProvider.getFirClassifierContainerFileIfAny(firBasedSymbol)
else -> throw AssertionError("Unexpected: $firBasedSymbol")
else -> error("Unknown symbol: $firBasedSymbol")
}
when {
@@ -302,8 +302,7 @@ class Fir2IrDeclarationStorage(
if (function !is FirAnonymousFunction && containingClass != null && !isStatic) {
dispatchReceiverParameter = declareThisReceiverParameter(
symbolTable,
thisType = containingClass.thisReceiver?.type
?: throw AssertionError(),
thisType = containingClass.thisReceiver?.type ?: error("No this receiver"),
thisOrigin = thisOrigin
)
}
@@ -831,8 +830,8 @@ class Fir2IrDeclarationStorage(
constructorCache[firConstructor] = irFunction
return irConstructorSymbol
}
if (parentOrigin == IrDeclarationOrigin.DEFINED) {
throw AssertionError()
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
"Should not have reference to public API uncached constructor from source code"
}
val symbol = Fir2IrConstructorSymbol(signature)
val irConstructor = firConstructor.convertWithOffsets { startOffset, endOffset ->
@@ -870,8 +869,8 @@ class Fir2IrDeclarationStorage(
}
// TODO: package fragment members (?)
if (firDeclaration is FirSimpleFunction && irParent is Fir2IrLazyClass) {
if (parentOrigin == IrDeclarationOrigin.DEFINED) {
throw AssertionError()
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
"Should not have reference to public API uncached simple function from source code"
}
val symbol = Fir2IrSimpleFunctionSymbol(signature, firDeclaration.containerSource)
val irFunction = firDeclaration.convertWithOffsets { startOffset, endOffset ->
@@ -899,7 +898,7 @@ class Fir2IrDeclarationStorage(
is FirConstructor -> {
getIrConstructorSymbol(firDeclaration.symbol)
}
else -> throw AssertionError("Should not be here: ${firDeclaration::class.java}: ${firDeclaration.render()}")
else -> error("Unknown kind of function: ${firDeclaration::class.java}: ${firDeclaration.render()}")
}
}
@@ -918,8 +917,8 @@ class Fir2IrDeclarationStorage(
}
// TODO: package fragment members (?)
if (irParent is Fir2IrLazyClass) {
if (parentOrigin == IrDeclarationOrigin.DEFINED) {
throw AssertionError()
assert(parentOrigin != IrDeclarationOrigin.DEFINED) {
"Should not have reference to public API uncached property from source code"
}
val symbol = Fir2IrPropertySymbol(signature, fir.containerSource)
val irProperty = fir.convertWithOffsets { startOffset, endOffset ->
@@ -124,8 +124,7 @@ class Fir2IrTypeConverter(
private fun getArrayClassSymbol(classId: ClassId?): IrClassSymbol? {
val primitiveId = StandardClassIds.elementTypeByPrimitiveArrayType[classId] ?: return null
val irType = classIdToTypeMap[primitiveId]
return irBuiltIns.primitiveArrayForType[irType]
?: throw AssertionError("Strange primitiveId $primitiveId from array: $classId")
return irBuiltIns.primitiveArrayForType[irType] ?: error("Strange primitiveId $primitiveId from array: $classId")
}
private fun getBuiltInClassSymbol(classId: ClassId?): IrClassSymbol? {
@@ -241,7 +241,7 @@ class Fir2IrVisitor(
when (irTarget) {
is IrConstructor -> irTarget.symbol
is IrSimpleFunction -> irTarget.symbol
else -> throw AssertionError("Should not be here: $irTarget")
else -> error("Unknown return target: $irTarget")
},
convertToIrExpression(result)
)
@@ -47,7 +47,7 @@ private fun leastCommonPrimitiveNumericType(t1: ConeClassLikeType, t2: ConeClass
pt1.isFloat() || pt2.isFloat() -> PrimitiveTypes.Float
pt1.isLong() || pt2.isLong() -> PrimitiveTypes.Long
pt1.isInt() || pt2.isInt() -> PrimitiveTypes.Int
else -> throw AssertionError("Unexpected types: t1=$t1, t2=$t2")
else -> error("Unexpected types: t1=$t1, t2=$t2")
}
}
@@ -55,7 +55,7 @@ private fun ConeClassLikeType.promoteIntegerTypeToIntIfRequired(): ConeClassLike
when (lookupTag.classId) {
StandardClassIds.Byte, StandardClassIds.Short -> PrimitiveTypes.Int
StandardClassIds.Long, StandardClassIds.Int, StandardClassIds.Float, StandardClassIds.Double, StandardClassIds.Char -> this
else -> throw AssertionError("Primitive number type expected: $this")
else -> error("Primitive number type expected: $this")
}
private fun ConeKotlinType.getPrimitiveTypeOrSupertype(): ConeClassLikeType? =
@@ -485,9 +485,7 @@ class CallAndReferenceGenerator(
?: run {
if (this is FirCallableReferenceAccess) return null
val name = if (isDispatch) "Dispatch" else "Extension"
throw AssertionError(
"$name receiver expected: ${render()} to ${calleeReference.render()}"
)
error("$name receiver expected: ${render()} to ${calleeReference.render()}")
}
}
@@ -250,7 +250,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
components.irBuiltIns.booleanType -> FirImplicitBooleanTypeRef(null)
components.irBuiltIns.intType -> FirImplicitIntTypeRef(null)
components.irBuiltIns.stringType -> FirImplicitStringTypeRef(null)
else -> throw AssertionError("Should not be here")
else -> error("Unexpected synthetic data class function return type: $returnType")
}
if (irValueParameter != null) {
this.valueParameters.add(
@@ -145,14 +145,14 @@ internal class OperatorExpressionGenerator(
targetType: ConeClassLikeType?
): IrExpression {
if (targetType == null) return this
if (operandType == null) throw AssertionError("operandType should be non-null")
if (operandType == null) error("operandType should be non-null if targetType is non-null")
val operandClassId = operandType.lookupTag.classId
val targetClassId = targetType.lookupTag.classId
if (operandClassId == targetClassId) return this
val conversionFunction =
typeConverter.classIdToSymbolMap[operandClassId]?.getSimpleFunction("to${targetType.lookupTag.classId.shortClassName.asString()}")
?: throw AssertionError("No conversion function for $operandType ~> $targetType")
?: error("No conversion function for $operandType ~> $targetType")
val dispatchReceiver = this@asComparisonOperand
val unsafeIrCall = IrCallImpl(
@@ -56,19 +56,19 @@ class Fir2IrLazyClass(
override var visibility: Visibility
get() = fir.visibility
set(_) {
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
error("Mutating Fir2Ir lazy elements is not possible")
}
override var modality: Modality
get() = fir.modality!!
set(_) {
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
error("Mutating Fir2Ir lazy elements is not possible")
}
override var attributeOwnerId: IrAttributeContainer
get() = this
set(_) {
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
error("Mutating Fir2Ir lazy elements is not possible")
}
override val kind: ClassKind
@@ -160,9 +160,10 @@ class Fir2IrLazyClass(
with(fakeOverrideGenerator) {
result += getFakeOverrides(fir, processedNames)
}
// TODO: remove this check to save time
for (declaration in result) {
if (declaration.parent != this) {
throw AssertionError()
throw AssertionError("Unmatched parent for lazy class member")
}
}
result
@@ -68,7 +68,7 @@ class Fir2IrLazyConstructor(
override var visibility: Visibility
get() = fir.visibility
set(_) {
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
error("Mutating Fir2Ir lazy elements is not possible")
}
override var returnType: IrType by lazyVar {
@@ -93,7 +93,7 @@ class Fir2IrLazyConstructor(
override var extensionReceiverParameter: IrValueParameter?
get() = null
set(_) {
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
error("Mutating Fir2Ir lazy elements is not possible")
}
override var valueParameters: List<IrValueParameter> by lazyVar {
@@ -74,7 +74,7 @@ class Fir2IrLazyProperty(
override var visibility: Visibility
get() = fir.visibility
set(_) {
throw AssertionError("Mutating Fir2Ir lazy elements is not possible")
error("Mutating Fir2Ir lazy elements is not possible")
}
override val modality: Modality
@@ -92,8 +92,7 @@ class Fir2IrLazySimpleFunction(
declarationStorage.enterScope(this)
declareThisReceiverParameter(
symbolTable,
thisType = containingClass.thisReceiver?.type
?: throw AssertionError(),
thisType = containingClass.thisReceiver?.type ?: error("No this receiver for containing class"),
thisOrigin = origin
).apply {
declarationStorage.leaveScope(this@Fir2IrLazySimpleFunction)
@@ -91,7 +91,7 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
callableId.packageName.asString(), callableId.relativeCallableName.asString(), builder.hashId, builder.mask
)
}
else -> throw AssertionError("Unsupported FIR declaration in signature composer: ${declaration.render()}")
else -> error("Unsupported FIR declaration in signature composer: ${declaration.render()}")
}
}