Skip to content

Commit 9b893c6

Browse files
committed
CHC: add function to prioritize invariants
1 parent 4d77e14 commit 9b893c6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CodeHawk/CHC/cchpre/cCHInvariantFact.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,3 +744,14 @@ let get_invariant_messages
744744
let inv = invio#get_invariant invindex in
745745
let p = LBLOCK [STR "["; INT k; STR "] "; inv#value_to_pretty] in
746746
p::acci) acc ilist) [] l
747+
748+
749+
let prioritize_invariants (f: invariant_int -> bool) (invs: invariant_int list) =
750+
List.stable_sort
751+
(fun inv1 inv2 ->
752+
if f inv1 && f inv2 then
753+
0
754+
else if f inv1 then
755+
-1
756+
else
757+
1) invs

CodeHawk/CHC/cchpre/cCHInvariantFact.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,15 @@ val mk_invariant_io:
7272

7373
val get_invariant_messages:
7474
invariant_io_int -> (int * int list) list -> pretty_t list
75+
76+
77+
(** [prioritize_invariants f invs] returns the invariants in [invs]
78+
sorted such that the invariants for which [(f inv)] is true are
79+
listed before other invariants.
80+
81+
This is useful in the application of invariants in the checkers,
82+
where multiple invariants apply to discharge a proof obligation,
83+
but some invariants may be preferred over others.
84+
*)
85+
val prioritize_invariants:
86+
(invariant_int -> bool) -> invariant_int list -> invariant_int list

0 commit comments

Comments
 (0)