Skip to content

Commit 3611d16

Browse files
committed
fix: Update to have dominance check not be done on same quality
Notably, dominance updates between sort variables were not checking if the variables were the same. If both were the same and they were not dominated (e.g. when removing the default Type->s constraint), then it would loop because it would postpone the dominance check. It really doesn't make sense though to update the dominance of a sort variable when adding the reflexive elimination constraint. The dominant will be the same in both cases, and if there is none, then it will be dominated eventually when checking with other sorts.
1 parent 3e6b224 commit 3611d16

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kernel/qGraph.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ let update_dominance_if_valid g (q1,k,q2) =
168168
else
169169
match q1, q2 with
170170
| (Quality.QConstant _ | Quality.QVar _), Quality.QConstant _ -> assert false
171+
| Quality.QVar qv1, Quality.QVar qv2 when QVar.equal qv1 qv2 -> assert false
172+
(* It makes no sense to update or delay the dominance of a sort variable when it eliminates to itself *)
171173
| Quality.QVar qv1, Quality.QVar qv2 ->
172174
(* 3 cases:
173175
- if [qv1] is a global, treat as constants.
@@ -226,8 +228,10 @@ let enforce_constraint (q1, k, q2) g =
226228
| None ->
227229
let e = lazy (G.get_explanation (q1,to_graph_cstr k,q2) g.graph) in
228230
raise @@ EliminationError (QualityInconsistency (None, (k, q1, q2, Some (Path e))))
229-
| Some g ->
230-
dominance_check g (q1, k, q2)
231+
| Some graph ->
232+
let g = { g with graph } in
233+
if Quality.equal q1 q2 then g
234+
else dominance_check g (q1, k, q2)
231235

232236
let merge_constraints csts g = ElimConstraints.fold enforce_constraint csts g
233237

@@ -292,7 +296,8 @@ let merge g g' =
292296
(fun q acc -> try add_quality q acc with _ -> acc) qs g in
293297
Quality.Set.fold
294298
(fun q -> Quality.Set.fold
295-
(fun q' acc -> if eliminates_to g' q q'
299+
(fun q' acc -> if Quality.equal q q' then acc
300+
else if eliminates_to g' q q'
296301
then enforce_eliminates_to q q' acc
297302
else acc) qs) qs g
298303

0 commit comments

Comments
 (0)