[codegen] make generated reified inline function's bodies throwing k.IllegalStateException

This commit is contained in:
Vasily Levchenko
2019-09-18 15:45:37 +03:00
parent c8252693d6
commit 26bd3bfe6b
3 changed files with 15 additions and 2 deletions
@@ -229,6 +229,7 @@ internal class KonanSymbols(
val throwInvalidReceiverTypeException = internalFunction("ThrowInvalidReceiverTypeException") val throwInvalidReceiverTypeException = internalFunction("ThrowInvalidReceiverTypeException")
val throwIllegalStateException = internalFunction("ThrowIllegalStateException") val throwIllegalStateException = internalFunction("ThrowIllegalStateException")
val throwIllegalStateExceptionWithMessage = internalFunction("ThrowIllegalStateExceptionWithMessage")
override val ThrowUninitializedPropertyAccessException = internalFunction("ThrowUninitializedPropertyAccessException") override val ThrowUninitializedPropertyAccessException = internalFunction("ThrowUninitializedPropertyAccessException")
@@ -675,8 +675,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
if ((declaration as? IrSimpleFunction)?.modality == Modality.ABSTRACT if ((declaration as? IrSimpleFunction)?.modality == Modality.ABSTRACT
|| declaration.isExternal || declaration.isExternal
|| body == null || body == null)
|| declaration.isReifiedInline)
return return
generateFunction(codegen, declaration, generateFunction(codegen, declaration,
@@ -687,6 +686,13 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
using(parameterScope) { using(parameterScope) {
using(VariableScope()) { using(VariableScope()) {
recordCoverage(body) recordCoverage(body)
if (declaration.isReifiedInline) {
callDirect(context.ir.symbols.throwIllegalStateExceptionWithMessage.owner,
listOf(context.llvm.staticData.kotlinStringLiteral(
"unsupported call of reified inlined function `${declaration.fqNameForIrSerialization}`").llvm),
Lifetime.IRRELEVANT)
return@using
}
when (body) { when (body) {
is IrBlockBody -> body.statements.forEach { generateStatement(it) } is IrBlockBody -> body.statements.forEach { generateStatement(it) }
is IrExpressionBody -> generateStatement(body.expression) is IrExpressionBody -> generateStatement(body.expression)
@@ -66,6 +66,12 @@ internal fun ThrowIllegalStateException() : Nothing {
throw IllegalStateException() throw IllegalStateException()
} }
@ExportForCppRuntime
internal fun ThrowIllegalStateExceptionWithMessage(message:String) : Nothing {
throw IllegalStateException(message)
}
@ExportForCppRuntime @ExportForCppRuntime
internal fun ThrowNotImplementedError(): Nothing { internal fun ThrowNotImplementedError(): Nothing {
throw NotImplementedError("An operation is not implemented.") throw NotImplementedError("An operation is not implemented.")