Skip to content

Commit de78f97

Browse files
committed
Clarify logic
1 parent bfff13a commit de78f97

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Source/DafnyCore/Verifier/BoogieGenerator.Types.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,21 +793,29 @@ private void GenerateAndCheckGuesses(IOrigin tok, List<BoundVar> bvars, List<Bou
793793
/// <summary>
794794
/// Return a pair of expressions (a, b) such that the disjunction "a || b" is equivalent to "expression"
795795
/// and expression "a" does not mention any variable in "vars".
796-
/// Expression "a" is always returns as "false" unless all variables in "vars" are known to have a value.
796+
/// Expression "a" is always returned as "false" unless the types of all variables in "vars" are known to have a value.
797797
/// </summary>
798798
(Expression, Expression) SeparateDisjunctsAccordingToVariableUsage(List<BoundVar> vars, Expression expression) {
799799
Expression a = Expression.CreateBoolLiteral(expression.Origin, false);
800800

801-
if (vars.Exists(x => !x.Type.KnownToHaveToAValue(x.IsGhost))) {
801+
if (vars.Any(x => !x.Type.KnownToHaveToAValue(x.IsGhost))) {
802802
return (a, expression);
803803
}
804804

805805
// Place the left-most var-independent disjuncts into "a" and the rest into "b".
806+
// The loop below has the effect of:
807+
// var d: List<Expression> := Expression.Disjuncts(expression);
808+
// var (prefix, rest) :|
809+
// "prefix" is the longest prefix of "d" where no Expression mentions a variable in "vars" and
810+
// "rest" is the remaining Expression's of "d";
811+
// return (Or(prefix), Or(rest));
812+
// But the loop optimizes the case where "prefix" is empty, returning "(false, expression)" in the event
813+
// that the first element of "d" contains some variable in "vars".
806814
Expression b = Expression.CreateBoolLiteral(expression.Origin, false);
807815
var seenDisjunctsWithoutVariables = false;
808816
var seenDisjunctsWithVariables = false;
809817
foreach (var disjunct in Expression.Disjuncts(expression)) {
810-
if (!seenDisjunctsWithVariables && vars.All(x => !FreeVariablesUtil.ContainsFreeVariable(disjunct, false, x))) {
818+
if (!seenDisjunctsWithVariables && !vars.Any(x => FreeVariablesUtil.ContainsFreeVariable(disjunct, false, x))) {
811819
a = Expression.CreateOr(a, disjunct);
812820
seenDisjunctsWithoutVariables = true;
813821
} else if (!seenDisjunctsWithoutVariables) {

0 commit comments

Comments
 (0)