Provide better explanation message if interpreter fails
This commit is contained in:
+18
-6
@@ -7,7 +7,10 @@ package org.jetbrains.kotlin.ir.interpreter.checker
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationBase
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
|
||||||
@@ -15,6 +18,7 @@ import org.jetbrains.kotlin.ir.interpreter.IrInterpreter
|
|||||||
import org.jetbrains.kotlin.ir.interpreter.isPrimitiveArray
|
import org.jetbrains.kotlin.ir.interpreter.isPrimitiveArray
|
||||||
import org.jetbrains.kotlin.ir.interpreter.toIrConst
|
import org.jetbrains.kotlin.ir.interpreter.toIrConst
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
|
import org.jetbrains.kotlin.ir.util.dump
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
|
|
||||||
class IrConstTransformer(
|
class IrConstTransformer(
|
||||||
@@ -44,9 +48,19 @@ class IrConstTransformer(
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun IrExpression.interpret(failAsError: Boolean): IrExpression {
|
||||||
|
val result = try {
|
||||||
|
interpreter.interpret(this, irFile)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
throw AssertionError("Error occurred while optimizing an expression:\n${this.dump()}", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (failAsError) result.reportIfError(this) else result.warningIfError(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
if (expression.accept(IrCompileTimeChecker(mode = mode), null)) {
|
if (expression.accept(IrCompileTimeChecker(mode = mode), null)) {
|
||||||
return interpreter.interpret(expression, irFile).warningIfError(expression)
|
return expression.interpret(failAsError = false)
|
||||||
}
|
}
|
||||||
return super.visitCall(expression)
|
return super.visitCall(expression)
|
||||||
}
|
}
|
||||||
@@ -59,8 +73,7 @@ class IrConstTransformer(
|
|||||||
if (expression is IrConst<*>) return declaration
|
if (expression is IrConst<*>) return declaration
|
||||||
val isConst = declaration.correspondingPropertySymbol?.owner?.isConst == true
|
val isConst = declaration.correspondingPropertySymbol?.owner?.isConst == true
|
||||||
if (isConst && expression.accept(IrCompileTimeChecker(declaration, mode), null)) {
|
if (isConst && expression.accept(IrCompileTimeChecker(declaration, mode), null)) {
|
||||||
val result = interpreter.interpret(expression, irFile)
|
initializer.expression = expression.interpret(failAsError = true)
|
||||||
initializer.expression = result.reportIfError(expression)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.visitField(declaration)
|
return super.visitField(declaration)
|
||||||
@@ -106,8 +119,7 @@ class IrConstTransformer(
|
|||||||
|
|
||||||
private fun IrExpression.transformSingleArg(expectedType: IrType): IrExpression {
|
private fun IrExpression.transformSingleArg(expectedType: IrType): IrExpression {
|
||||||
if (this.accept(IrCompileTimeChecker(mode = mode), null)) {
|
if (this.accept(IrCompileTimeChecker(mode = mode), null)) {
|
||||||
val const = interpreter.interpret(this, irFile).reportIfError(this)
|
return this.interpret(failAsError = true).convertToConstIfPossible(expectedType)
|
||||||
return const.convertToConstIfPossible(expectedType)
|
|
||||||
} else if (this is IrConstructorCall) {
|
} else if (this is IrConstructorCall) {
|
||||||
transformAnnotation(this)
|
transformAnnotation(this)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user