-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print evaluator type and values of free variable of assertion failure predicate #1084
base: scala-2
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
package stainless | ||
package evaluators | ||
|
||
|
||
trait RecursiveEvaluator extends inox.evaluators.RecursiveEvaluator { | ||
val program: Program | ||
|
||
|
@@ -11,6 +12,8 @@ trait RecursiveEvaluator extends inox.evaluators.RecursiveEvaluator { | |
import program.trees._ | ||
import program.symbols._ | ||
|
||
import inox.utils.Position | ||
|
||
override def e(expr: Expr)(implicit rctx: RC, gctx: GC): Expr = expr match { | ||
case Require(pred, body) => | ||
if (!ignoreContracts && e(pred) != BooleanLiteral(true)) | ||
|
@@ -24,9 +27,20 @@ trait RecursiveEvaluator extends inox.evaluators.RecursiveEvaluator { | |
e(body) | ||
|
||
case Assert(pred, err, body) => | ||
if (!ignoreContracts && e(pred) != BooleanLiteral(true)) | ||
throw RuntimeError(err.getOrElse("Assertion failed @" + expr.getPos)) | ||
e(body) | ||
if (!ignoreContracts && e(pred) != BooleanLiteral(true)) { | ||
val msg = (err match { | ||
case Some(m) => m.toString + ": " | ||
case None => "" | ||
}) + pred.toString | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We generally use |
||
reporter.info(s"${Position.smartPos(pred.getPos)} assertion failure of ${msg}") | ||
reporter.info("Relevant variables at assertion failure point:") | ||
val m = rctx.mappings | ||
val fvs = exprOps.variablesOf(pred) | ||
val fvDump: String = fvs.map(v => v.id.toString + " -> " + m.get(v.toVal).getOrElse("?").toString) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced toString with asString in two places. |
||
.mkString("\n") | ||
reporter.info(fvDump) | ||
throw RuntimeError(err.getOrElse("Assertion failed @" + pred.getPos)) | ||
} else e(body) | ||
|
||
case MatchExpr(scrut, cases) => | ||
val rscrut = e(scrut) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we include the names into the evaluators instead of using the global variable
kind
? I'm afraid this requires changing Inox though to add a name field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did not want to chage Inox this time. Maybe later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of storing this in a global var, you could also compute the evaluator name to output inside the
EvaluatorComponent
based onctx.options.findOptionOrDefault(optCodeGen)
(especially since the property isn't really global).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like checking the option since it's not telling me what the evaluator actually is, but what it should have been set to and there is complex initialization logic that determines that. Unfortunately I cannot use reflection and print dynamic class name e.g.with
.getClass.getSimpleName()
because somewhere in the code an anonymous class is created and the actual class name is lost.Another question: how do I make
--check-models
benefit from this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reflection should work, I think there's something like
getClass.getSimpleName
which isn't too mangled.Model checking currently takes place in Inox. The easiest way to get it to benefit from the new behavior would be to always disable
optCheckModels
in Inox (like here) and check models inside Stainless. The logic on the Inox side is here. Model checking in Stainless could actually be more powerful because we have access to the type checker, but you might need to be careful about running into loops.