11package liquidjava .rj_language .opt ;
22
3- import static liquidjava .rj_language .opt .VCSimplificationUtils .isTrue ;
4- import static liquidjava .rj_language .opt .VCSimplificationUtils .linkedConjuncts ;
5- import static liquidjava .rj_language .opt .VCSimplificationUtils .splitConjuncts ;
3+ import static liquidjava .rj_language .opt .VCSimplificationUtils .containsVar ;
64import static liquidjava .rj_language .opt .VCSimplificationUtils .termsOf ;
75import static liquidjava .rj_language .opt .VCSimplificationUtils .valueVariablesOf ;
8- import static liquidjava .rj_language .opt .VCSimplificationUtils .variablesOf ;
96
10- import java .util .ArrayList ;
117import java .util .HashSet ;
12- import java .util .List ;
138import java .util .Set ;
149
1510import liquidjava .processor .VCImplication ;
1813
1914/**
2015 * Decides which binders refined only by {@code true} a simplified VC chain keeps for an error. Such a binder states no
21- * fact, so it is kept only when a fact linked to the expected refinement (sharing a term with it, directly or through
22- * other facts) constrains its variable's value, or, when the error shows a counterexample, when expected itself
23- * constrains its value, so that the counterexample can show it
16+ * fact, and a variable that another row mentions is already shown there, so its row would only read as if its value
17+ * were true. It is kept only when the error shows a counterexample, expected constrains the variable's value and no
18+ * other row mentions it: the row then shows that nothing is known about a value the error depends on
2419 *
2520 * @param expectedTerms
2621 * variables and ghost applications of the expected refinement
2722 * @param expectedValues
2823 * variables whose value the expected refinement constrains
2924 * @param keepExpected
30- * whether the binders of expectedValues are kept for that alone
25+ * whether the binders of expectedValues that no other row mentions are kept
3126 */
3227public record NeededVariables (Set <String > expectedTerms , Set <String > expectedValues , boolean keepExpected ) {
3328
@@ -39,7 +34,7 @@ public record NeededVariables(Set<String> expectedTerms, Set<String> expectedVal
3934 }
4035
4136 /**
42- * For a refinement error, whose counterexample lists the values of the binders
37+ * For a refinement error, which shows a counterexample
4338 */
4439 public static NeededVariables forRefinementError (Predicate expected ) {
4540 return of (expected , true );
@@ -59,40 +54,20 @@ private static NeededVariables of(Predicate expected, boolean keepExpected) {
5954 }
6055
6156 /**
62- * Variables whose binder refined only by true the chain keeps: those whose own value a fact linked to expected
63- * constrains, and, when {@code keepExpected}, those whose value expected constrains
57+ * Variables whose binder refined only by true the chain keeps: when {@code keepExpected}, those whose value
58+ * expected constrains and that no other row of the chain mentions
6459 */
6560 public Set <String > trueBindersToKeep (VCImplication chain ) {
66- Set <String > primitives = primitiveBinders (chain );
6761 Set <String > keep = new HashSet <>();
68- for (Expression fact : linkedConjuncts (factsOf (chain ), VCSimplificationUtils ::termsOf , expectedTerms ))
69- for (String name : variablesOf (fact ))
70- if (!expectedTerms .contains (name ) && hasOwnValue (name , fact , primitives ))
71- keep .add (name );
72- if (keepExpected )
73- for (String name : expectedTerms )
74- if (expectedValues .contains (name ) || primitives .contains (name ))
75- keep .add (name );
62+ if (!keepExpected )
63+ return keep ;
64+ Set <String > primitives = primitiveBinders (chain );
65+ for (String name : expectedTerms )
66+ if ((expectedValues .contains (name ) || primitives .contains (name )) && !containsVar (chain , name ))
67+ keep .add (name );
7668 return keep ;
7769 }
7870
79- /**
80- * Whether a fact constrains the variable's own value. A variable of an object type that the fact names only as the
81- * argument of a ghost or state application ({@code x} in {@code b == size(x)}) has no value of its own there, so
82- * its row would say nothing; a primitive argument ({@code k} in {@code y == f(k)}) has one
83- */
84- private static boolean hasOwnValue (String name , Expression fact , Set <String > primitives ) {
85- return primitives .contains (name ) || valueVariablesOf (fact ).contains (name );
86- }
87-
88- private static List <Expression > factsOf (VCImplication chain ) {
89- List <Expression > facts = new ArrayList <>();
90- for (VCImplication current = chain ; current != null ; current = current .getNext ())
91- if (!isTrue (current .getRefinement ().getExpression ()))
92- facts .addAll (splitConjuncts (current .getRefinement ().getExpression ()));
93- return facts ;
94- }
95-
9671 private static Set <String > primitiveBinders (VCImplication chain ) {
9772 Set <String > primitives = new HashSet <>();
9873 for (VCImplication current = chain ; current != null ; current = current .getNext ())
0 commit comments