Skip to content

Commit 90f9bef

Browse files
authored
unwrap nested always violations recursively (#134)
1 parent fe4ba05 commit 90f9bef

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

  • lib/bombadil/src/specification

lib/bombadil/src/specification/ltl.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -661,32 +661,42 @@ impl<'a, Function: Clone> Evaluator<'a, Function> {
661661
}
662662
None => always_residual,
663663
};
664-
// Unwrap one layer of Always if present, since
665-
// we're about to re-wrap. The inner Always was
666-
// produced by either evaluate_always or a prior
667-
// evaluate_and_always call for the same formula.
664+
// Unwrap all layers of Always if present, since
665+
// we're about to re-wrap. The inner Always wrappers
666+
// were produced by prior evaluate_always or
667+
// evaluate_and_always calls for the same formula.
668668
//
669669
// When the left side fails, use onset (when the
670670
// left residual was first created) so that "but
671671
// at T" reflects when the subformula first
672672
// started failing. When the right side fails,
673-
// use the time from the inner Always (set by
673+
// use the time from the innermost Always (set by
674674
// evaluate_always at the current step).
675675
let (violation, violation_time) = match (&left, &right) {
676-
(Value::False(v, _), _) => match v {
677-
Violation::Always { violation, .. } => {
678-
(violation.as_ref(), onset)
676+
(Value::False(v, _), _) => {
677+
let mut current = v;
678+
while let Violation::Always {
679+
violation: inner, ..
680+
} = current
681+
{
682+
current = inner.as_ref();
679683
}
680-
other => (other, onset),
681-
},
682-
(_, Value::False(v, _)) => match v {
683-
Violation::Always {
684-
violation,
684+
(current, onset)
685+
}
686+
(_, Value::False(v, _)) => {
687+
let mut current = v;
688+
let mut last_time = time;
689+
while let Violation::Always {
690+
violation: inner,
685691
time: inner_time,
686692
..
687-
} => (violation.as_ref(), *inner_time),
688-
other => (other, time),
689-
},
693+
} = current
694+
{
695+
last_time = *inner_time;
696+
current = inner.as_ref();
697+
}
698+
(current, last_time)
699+
}
690700
_ => unreachable!(),
691701
};
692702
Value::False(

0 commit comments

Comments
 (0)