Skip to content

Commit 8cdac31

Browse files
committed
Remove Unused Binders In Simplification
1 parent d91f256 commit 8cdac31

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/rj_language/opt/VCBinderSimplification.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ private VCImplication simplify(VCImplication implication) {
3434
if (isFalseBinder(implication))
3535
return collapseFalseBinder(implication);
3636

37-
if (isTrueBinder(implication) && !containsVar(implication.getNext(), implication.getName()))
38-
return removeTrueBinder(implication);
37+
if (isRemovableUnusedBinder(implication))
38+
return removeBinder(implication);
3939

4040
VCImplication next = simplify(implication.getNext());
4141
if (next == null)
@@ -47,12 +47,12 @@ private VCImplication simplify(VCImplication implication) {
4747
}
4848

4949
/**
50-
* Removes a true binder whose name is not used in the suffix
50+
* Removes a binder whose name is not used in the suffix
5151
*/
52-
private VCImplication removeTrueBinder(VCImplication implication) {
52+
private VCImplication removeBinder(VCImplication implication) {
5353
VCImplication next = implication.getNext();
5454

55-
// ∀x. true => P -> P
55+
// ∀x. R => P -> P when x is not used in P
5656
if (next != null)
5757
return next.clone();
5858

@@ -61,6 +61,16 @@ private VCImplication removeTrueBinder(VCImplication implication) {
6161
return new VCImplication(truePredicate);
6262
}
6363

64+
/**
65+
* Checks whether a binder is unused and can be removed
66+
*/
67+
private boolean isRemovableUnusedBinder(VCImplication implication) {
68+
if (!implication.hasBinder() || containsVar(implication.getNext(), implication.getName()))
69+
return false;
70+
71+
return implication.hasNext() || isTrueBinder(implication);
72+
}
73+
6474
/**
6575
* Replaces a false binder implication with true
6676
*/

liquidjava-verifier/src/main/java/liquidjava/rj_language/opt/VCSimplificationResult.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package liquidjava.rj_language.opt;
22

3-
import java.util.Objects;
4-
53
import liquidjava.processor.VCImplication;
64

75
/**

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ void removesTrueBinderWhenVariableIsUnusedDownstream() {
1212
assertSimplificationSteps(binderSimplification, vc("∀x:int. true", "y > 0"), step("y > 0"));
1313
}
1414

15+
@Test
16+
void removesNonTrueBinderWhenVariableIsUnusedDownstream() {
17+
assertSimplificationSteps(binderSimplification, vc("∀x:int. x > 0", "y > 0"), step("y > 0"));
18+
}
19+
20+
@Test
21+
void keepsNonTrueTerminalBinderAsConclusion() {
22+
assertSimplificationSteps(binderSimplification, vc("∀x:int. x > 0"), step("x > 0"));
23+
}
24+
1525
@Test
1626
void keepsTrueBinderWhenVariableIsUsedDownstream() {
1727
assertSimplificationSteps(binderSimplification, vc("∀x:int. true", "x > 0"), step("true", "x > 0"));

liquidjava-verifier/src/test/java/liquidjava/rj_language/opt/VCSimplificationTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,13 @@ void simplifyUsesLogicalSimplificationToEnableSubstitutionOnNextStep() {
108108
}
109109

110110
@Test
111-
void simplifyUsesFoldingToEnableBinderSimplificationOnNextStep() {
112-
assertSimplificationSteps(vc("∀x:int. 1 > 2", "y > 0"), step("false", "y > 0"), step("true"));
111+
void simplifyRemovesUnusedBinderBeforeFolding() {
112+
assertSimplificationSteps(vc("∀x:int. 1 > 2", "y > 0"), step("y > 0"));
113113
}
114114

115115
@Test
116-
void simplifyUsesArithmeticAndLogicalSimplificationToEnableBinderRemoval() {
117-
assertSimplificationSteps(vc("∀x:int. x + 0 == x", "y > 0"), step("x == x", "y > 0"), step("true", "y > 0"),
118-
step("y > 0"));
116+
void simplifyRemovesUnusedBinderBeforeArithmeticAndLogicalSimplification() {
117+
assertSimplificationSteps(vc("∀x:int. x + 0 == x", "y > 0"), step("y > 0"));
119118
}
120119

121120
@Test

0 commit comments

Comments
 (0)