Skip to content

Commit 74d1529

Browse files
authored
fix: Do not load preludes twice (#1235) (#1237)
The `--enable-theories` option should be a no-op w.r.t. the theories that are already enabled, but it currently causes the theory preludes to be enabled twice due to an oversight in the option parsing code. Switch the option parsing code to use a set instead of a list to represent the enabled theories, ensuring uniqueness.
1 parent d99264b commit 74d1529

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/bin/common/parse_command.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,21 +1509,22 @@ let parse_theory_opt =
15091509
Term.(const mk_disable_theories $ disable_theories $ disable_adts $ no_ac)
15101510
in
15111511
let preludes enable_theories disable_theories =
1512-
let theories = Theories.default in
1512+
let theories = Theories.Set.of_list Theories.default in
15131513
let rec aux th en dis =
15141514
match en, dis with
1515-
| _ :: _, [] -> aux (List.rev_append en th) [] []
1515+
| _ :: _, [] ->
1516+
aux (List.fold_left (fun th en -> Theories.Set.add en th) th en) [] []
15161517
| e :: _, d :: _ when e = d ->
15171518
Fmt.error_msg "theory prelude '%a' cannot be both enabled and
15181519
disabled" Theories.pp e
1519-
| e :: en, d :: _ when e < d -> aux (e :: th) en dis
1520-
| _ , d :: dis -> aux (List.filter ((<>) d) th) en dis
1521-
| [], [] -> Ok th
1520+
| e :: en, d :: _ when e < d -> aux (Theories.Set.add e th) en dis
1521+
| _ , d :: dis -> aux (Theories.Set.filter ((<>) d) th) en dis
1522+
| [], [] -> Ok (Theories.Set.elements th)
15221523
in
15231524
aux
15241525
theories
1525-
(List.fast_sort compare enable_theories)
1526-
(List.fast_sort compare disable_theories)
1526+
(List.fast_sort Theories.compare enable_theories)
1527+
(List.fast_sort Theories.compare disable_theories)
15271528
in
15281529
Term.(
15291530
cli_parse_result (

src/lib/util/theories.ml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,43 @@
1616
(* *)
1717
(**************************************************************************)
1818

19-
type prelude = Fpa | Ria | Nra [@@deriving eq]
19+
type prelude = Nra | Ria | Fpa [@@deriving eq]
2020

2121
let pp_prelude ppf = function
2222
| Fpa -> Format.fprintf ppf "fpa"
2323
| Ria -> Format.fprintf ppf "ria"
2424
| Nra -> Format.fprintf ppf "nra"
2525

26+
let compare_prelude p1 p2 =
27+
match p1, p2 with
28+
| Nra, Nra -> 0
29+
| Nra, _ -> -1
30+
| _, Nra -> 1
31+
32+
| Ria, Ria -> 0
33+
| Ria, _ -> -1
34+
| _, Ria -> 1
35+
36+
| Fpa, Fpa -> 0
37+
2638
type t =
2739
| Prelude of prelude
2840
| ADT
2941
| AC
3042
[@@deriving eq]
3143

44+
let compare t1 t2 =
45+
match t1, t2 with
46+
| Prelude p1, Prelude p2 -> compare_prelude p1 p2
47+
| Prelude _, _ -> -1
48+
| _, Prelude _ -> 1
49+
50+
| ADT, ADT -> 0
51+
| ADT, _ -> -1
52+
| _, ADT -> 1
53+
54+
| AC, AC -> 0
55+
3256
let pp ppf = function
3357
| Prelude p -> pp_prelude ppf p
3458
| ADT -> Format.fprintf ppf "adt"
@@ -52,3 +76,5 @@ let default = all
5276

5377
let preludes =
5478
List.filter_map (function | Prelude p -> Some p | _ -> None)
79+
80+
module Set = Set.Make(struct type nonrec t = t let compare = compare end)

0 commit comments

Comments
 (0)