Skip to content

Commit 47c6981

Browse files
committed
quality error messages for judgment failures
as well as utility functions for ensurin best practice
1 parent 0578362 commit 47c6981

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1305
-721
lines changed

Cargo.lock

Lines changed: 35 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pretty_assertions = "1.3.0"
1818
expect-test = "1.4.0"
1919
formality-macros = { version = "0.1.0", path = "crates/formality-macros" }
2020
formality-core = { version = "0.1.0", path = "crates/formality-core" }
21+
tracing = "0.1.40"
2122

2223

2324
[dependencies]

crates/formality-check/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl Check<'_> {
9999
assert!(env.encloses((&assumptions, &goal)));
100100

101101
let cs = formality_prove::prove(self.decls, env, &assumptions, &goal);
102+
let cs = cs.into_set()?;
102103
if cs.iter().any(|c| c.unconditionally_true()) {
103104
return Ok(());
104105
}
@@ -145,10 +146,10 @@ impl Check<'_> {
145146
&existential_goal,
146147
);
147148

148-
if cs.is_empty() {
149+
if !cs.is_proven() {
149150
return Ok(());
150151
}
151152

152-
bail!("failed to disprove\n {goal:?}\ngiven\n {assumptions:?}\ngot\n{cs:#?}")
153+
bail!("failed to disprove\n {goal:?}\ngiven\n {assumptions:?}\ngot\n{cs:?}")
153154
}
154155
}

crates/formality-core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ contracts = "0.6.3"
2323
final_fn = "0.1.0"
2424
itertools = "0.12.0"
2525
either = "1.9.0"
26+
expect-test = "1.4.1"
27+
regex = "1.10.2"
2628

2729
[dev-dependencies]
2830
expect-test = "1.4.1"

crates/formality-core/src/judgment.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ macro_rules! push_rules {
235235

236236
(@match $conclusion_name:ident inputs() patterns() args(@body ($judgment_name:ident; $n:literal; $v:expr; $output:expr); $inputs:tt; $($m:tt)*)) => {
237237
tracing::trace_span!("matched rule", rule = $n, judgment = stringify!($judgment_name)).in_scope(|| {
238-
let mut step_index = 0;
239-
$crate::push_rules!(@body ($judgment_name, $n, $v, $output); $inputs; step_index; $($m)*);
238+
$crate::push_rules!(@body ($judgment_name, $n, $v, $output); $inputs; 0; $($m)*);
240239
});
241240
};
242241

@@ -284,28 +283,25 @@ macro_rules! push_rules {
284283
// expression `v` is carried in from the conclusion and forms the final
285284
// output of this rule, once all the conditions are evaluated.
286285

287-
(@body $args:tt; $inputs:tt; $step_index:ident; (if $c:expr) $($m:tt)*) => {
286+
(@body $args:tt; $inputs:tt; $step_index:expr; (if $c:expr) $($m:tt)*) => {
288287
if $c {
289-
$step_index += 1;
290-
$crate::push_rules!(@body $args; $inputs; $step_index; $($m)*);
288+
$crate::push_rules!(@body $args; $inputs; $step_index + 1; $($m)*);
291289
} else {
292290
$crate::push_rules!(@record_failure $inputs; $step_index, $c; $crate::judgment::RuleFailureCause::IfFalse {
293291
expr: stringify!($c).to_string(),
294292
});
295293
}
296294
};
297295

298-
(@body $args:tt; $inputs:tt; $step_index:ident; (assert $c:expr) $($m:tt)*) => {
296+
(@body $args:tt; $inputs:tt; $step_index:expr; (assert $c:expr) $($m:tt)*) => {
299297
assert!($c);
300-
$step_index += 1;
301-
$crate::push_rules!(@body $args; $inputs; $step_index; $($m)*);
298+
$crate::push_rules!(@body $args; $inputs; $step_index + 1; $($m)*);
302299
};
303300

304-
(@body $args:tt; $inputs:tt; $step_index:ident; (if let $p:pat = $e:expr) $($m:tt)*) => {
301+
(@body $args:tt; $inputs:tt; $step_index:expr; (if let $p:pat = $e:expr) $($m:tt)*) => {
305302
let value = &$e;
306303
if let $p = Clone::clone(value) {
307-
$step_index += 1;
308-
$crate::push_rules!(@body $args; $inputs; $step_index; $($m)*);
304+
$crate::push_rules!(@body $args; $inputs; $step_index + 1; $($m)*);
309305
} else {
310306
$crate::push_rules!(@record_failure $inputs; $step_index, $e; $crate::judgment::RuleFailureCause::IfLetDidNotMatch {
311307
pattern: stringify!($p).to_string(),
@@ -314,14 +310,13 @@ macro_rules! push_rules {
314310
}
315311
};
316312

317-
(@body $args:tt; $inputs:tt; $step_index:ident; ($i:expr => $p:pat) $($m:tt)*) => {
313+
(@body $args:tt; $inputs:tt; $step_index:expr; ($i:expr => $p:pat) $($m:tt)*) => {
318314
// Explicitly calling `into_iter` silences some annoying lints
319315
// in the case where `$i` is an `Option` or a `Result`
320316
match $crate::judgment::TryIntoIter::try_into_iter($i, || stringify!($i).to_string()) {
321317
Ok(i) => {
322-
$step_index += 1;
323318
for $p in std::iter::IntoIterator::into_iter(i) {
324-
$crate::push_rules!(@body $args; $inputs; $step_index; $($m)*);
319+
$crate::push_rules!(@body $args; $inputs; $step_index + 1; $($m)*);
325320
}
326321
}
327322
Err(e) => {
@@ -330,17 +325,15 @@ macro_rules! push_rules {
330325
}
331326
};
332327

333-
(@body $args:tt; $inputs:tt; $step_index:ident; (let $p:pat = $i:expr) $($m:tt)*) => {
328+
(@body $args:tt; $inputs:tt; $step_index:expr; (let $p:pat = $i:expr) $($m:tt)*) => {
334329
{
335330
let $p = $i;
336-
$step_index += 1;
337-
$crate::push_rules!(@body $args; $inputs; $step_index; $($m)*);
331+
$crate::push_rules!(@body $args; $inputs; $step_index + 1; $($m)*);
338332
}
339333
};
340334

341-
(@body ($judgment_name:ident, $rule_name:literal, $v:expr, $output:expr); $inputs:tt; $step_index:ident;) => {
335+
(@body ($judgment_name:ident, $rule_name:literal, $v:expr, $output:expr); $inputs:tt; $step_index:expr;) => {
342336
{
343-
let _ = $step_index; // suppress warnings about value not being read
344337
let result = $crate::Upcast::upcast($v);
345338
tracing::debug!("produced {:?} from rule {:?} in judgment {:?}", result, $rule_name, stringify!($judgment_name));
346339
$output.insert(result)
@@ -349,7 +342,7 @@ macro_rules! push_rules {
349342

350343
//
351344

352-
(@record_failure ($failed_rules:expr, $match_index:expr, $inputs:tt, $rule_name:literal); $step_index:ident, $step_expr:expr; $cause:expr) => {
345+
(@record_failure ($failed_rules:expr, $match_index:expr, $inputs:tt, $rule_name:literal); $step_index:expr, $step_expr:expr; $cause:expr) => {
353346
let file = $crate::respan!($step_expr (file!()));
354347
let line = $crate::respan!($step_expr (line!()));
355348
let column = $crate::respan!($step_expr (column!()));

0 commit comments

Comments
 (0)