Skip to content

Commit e7bd6c1

Browse files
committed
mc: add some more nice error messages
1 parent 423e785 commit e7bd6c1

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

src/ast/symbol.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ impl Symbol {
2323
}
2424
}
2525

26+
impl PartialEq<str> for Symbol {
27+
fn eq(&self, other: &str) -> bool {
28+
let interned = INTERNED_STRINGS.lock().unwrap();
29+
interned.resolve(self.0).unwrap() == other
30+
}
31+
}
32+
2633
impl fmt::Debug for Symbol {
2734
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2835
let interned = INTERNED_STRINGS.lock().unwrap();

src/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl SourceUnitName {
9696
res
9797
}
9898

99-
/// Create a filne name for this source unit with the given file extension.
99+
/// Create a file name for this source unit with the given file extension.
100100
///
101101
/// This is used to create e.g. SMT-LIB output files for debugging. It is
102102
/// not necessarily related to the actual file name of the source unit.

src/intrinsic/annotations.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ pub struct Calculus {
151151
}
152152

153153
#[derive(Debug, Clone, Copy, PartialEq)]
154-
155154
pub enum CalculusType {
156155
Wp,
157156
Wlp,

src/mc/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use jani::{
1818
types::{BasicType, BoundedType, BoundedTypeBase, Type},
1919
Identifier,
2020
};
21+
use lsp_types::NumberOrString;
2122

2223
use crate::{
2324
ast::{
@@ -45,10 +46,12 @@ pub enum JaniConversionError {
4546
UnsupportedPre(Expr),
4647
UnsupportedAssume(Expr),
4748
UnsupportedAssert(Expr),
49+
UnsupportedHavoc { stmt: Stmt, can_eliminate: bool },
4850
UnsupportedInftyPost(Expr),
4951
NondetSelection(Span),
5052
MismatchedDirection(Span),
5153
UnsupportedCall(Span, Ident),
54+
UnsupportedCalculus { proc: Ident, calculus: Ident },
5255
}
5356

5457
impl JaniConversionError {
@@ -85,6 +88,16 @@ impl JaniConversionError {
8588
.with_message("JANI: Assertion must be a Boolean expression")
8689
.with_label(Label::new(expr.span).with_message("expected ?(b) here"))
8790
}
91+
JaniConversionError::UnsupportedHavoc {stmt, can_eliminate} => {
92+
let diagnostic = Diagnostic::new(ReportKind::Error, stmt.span)
93+
.with_message("JANI: Havoc is not supported")
94+
.with_label(Label::new(stmt.span).with_message("here"));
95+
if *can_eliminate {
96+
diagnostic.with_note("You can replace the havoc with a re-declaration of its variables.")
97+
} else {
98+
diagnostic
99+
}
100+
}
88101
JaniConversionError::UnsupportedInftyPost(expr) => {
89102
Diagnostic::new(ReportKind::Error, expr.span)
90103
.with_message("JANI: Post that evaluates to ∞ is not supported")
@@ -103,7 +116,11 @@ impl JaniConversionError {
103116
.with_message(format!("JANI: Cannot call '{}'", ident.name))
104117
.with_label(Label::new(*span).with_message("must be a func with a body"))
105118
}
119+
JaniConversionError::UnsupportedCalculus { proc, calculus }=> Diagnostic::new(ReportKind::Error, proc.span)
120+
.with_message(format!("JANI: Calculus '{}' is not supported", calculus))
121+
.with_label(Label::new(proc.span).with_message("here")),
106122
}
123+
.with_code(NumberOrString::String("model checking".to_owned()))
107124
}
108125
}
109126

@@ -112,6 +129,8 @@ pub fn proc_to_model(
112129
tcx: &TyCtx,
113130
proc: &ProcDecl,
114131
) -> Result<Model, JaniConversionError> {
132+
check_calculus_annotation(proc)?;
133+
115134
let expr_translator = ExprTranslator::new(tcx);
116135

117136
// initialize the spec automaton
@@ -197,6 +216,20 @@ pub fn proc_to_model(
197216
Ok(model)
198217
}
199218

219+
fn check_calculus_annotation(proc: &ProcDecl) -> Result<(), JaniConversionError> {
220+
if let Some(calculus) = proc.calculus {
221+
if &calculus.name != "wp" || &calculus.name != "ert"
222+
// yeah that's ugly
223+
{
224+
return Err(JaniConversionError::UnsupportedCalculus {
225+
proc: proc.name,
226+
calculus,
227+
});
228+
}
229+
}
230+
Ok(())
231+
}
232+
200233
/// Translate variable declarations, including local variable declarations, as
201234
/// well as input and output parameters.
202235
fn translate_var_decls(

src/mc/opsem.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ fn translate_stmt(
142142

143143
Ok(start)
144144
}
145-
StmtKind::Havoc(_, _)
146-
| StmtKind::Compare(_, _)
147-
| StmtKind::Negate(_)
148-
| StmtKind::Validate(_) => {
145+
StmtKind::Havoc(dir, _) => Err(JaniConversionError::UnsupportedHavoc {
146+
stmt: stmt.clone(),
147+
can_eliminate: automaton.spec_part.direction == *dir,
148+
}),
149+
StmtKind::Compare(_, _) | StmtKind::Negate(_) | StmtKind::Validate(_) => {
149150
Err(JaniConversionError::UnsupportedStmt(Box::new(stmt.clone())))
150151
}
151152
StmtKind::Tick(expr) => translate_assign(

0 commit comments

Comments
 (0)