Skip to content

Commit 0a207e9

Browse files
Keep a path condition whose own variable expected names
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent dff0e86 commit 0a207e9

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎liquidjava-verifier/src/main/java/liquidjava/rj_language/opt/NeededVariables.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public Set<String> trueBindersToKeep(VCImplication chain) {
7373
}
7474

7575
/**
76-
* Binders whose refinement shares no term with expected, directly or through other facts of the chain, and whose
77-
* variable no other row mentions: expected does not depend on them. None without expected terms
76+
* Binders that share no term with expected, neither their variable nor a term of their refinement, directly or
77+
* through other facts of the chain, and whose variable no other row mentions: expected does not depend on them.
78+
* None without expected terms
7879
*/
7980
public Set<String> unlinkedBinders(VCImplication chain) {
8081
Set<String> unlinked = new HashSet<>();
@@ -83,12 +84,16 @@ public Set<String> unlinkedBinders(VCImplication chain) {
8384
List<Expression> facts = factsOf(chain.toPredicate().getExpression());
8485
Set<String> linked = linkedTerms(facts, expectedTerms, VCSimplificationUtils::termsOf);
8586
for (VCImplication row = chain; row != null; row = row.getNext())
86-
if (row.hasBinder() && termsOf(row.getRefinement().getExpression()).stream().noneMatch(linked::contains)
87-
&& !mentionedByOtherRows(chain, row))
87+
if (row.hasBinder() && !isLinked(row, linked) && !mentionedByOtherRows(chain, row))
8888
unlinked.add(row.getName());
8989
return unlinked;
9090
}
9191

92+
private static boolean isLinked(VCImplication row, Set<String> linked) {
93+
return linked.contains(row.getName())
94+
|| termsOf(row.getRefinement().getExpression()).stream().anyMatch(linked::contains);
95+
}
96+
9297
private static boolean mentionedByOtherRows(VCImplication chain, VCImplication row) {
9398
for (VCImplication other = chain; other != null; other = other.getNext())
9499
if (other != row && containsVar(other.getRefinement().getExpression(), row.getName()))

‎liquidjava-verifier/src/test/java/liquidjava/rj_language/opt/VCBinderSimplificationTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ void keepsPathConditionAnotherRowMentions() {
143143
step("p", "#if_condition¹ ? open(f) : created(f)"));
144144
}
145145

146+
@Test
147+
void keepsPathConditionExpectedNames() {
148+
assertSimplificationSteps(forRefinementError("##if_condition_1"),
149+
vc("∀##if_condition_1:boolean. p", "∀##if_condition_2:boolean. q"), step("p"));
150+
}
151+
146152
@Test
147153
void removesPathConditionAboveAnUnknownStateLeavingTrue() {
148154
assertSimplificationSteps(forStateError("open(f)"), vc("∀##if_condition_1:boolean. a || b", "∀f:Object. true"),

0 commit comments

Comments
 (0)