Skip to content

Commit 6a81272

Browse files
committed
Use Dolmen identifiers directly in Uid
1 parent d47ace5 commit 6a81272

6 files changed

Lines changed: 34 additions & 27 deletions

File tree

src/lib/frontend/typechecker.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ module Types = struct
210210
Errors.typing_error WrongNumberOfLabels loc;
211211
List.iter
212212
(fun (lb, _) ->
213-
try ignore (Uid.list_assoc lb l)
213+
try ignore (Lists.assoc Uid.equal lb l)
214214
with Not_found ->
215215
Errors.typing_error
216216
(WrongLabel((Hstring.make @@ Uid.show lb), ty)) loc) lbs;
@@ -869,7 +869,8 @@ let rec type_term ?(call_from_type_form=false) env f =
869869
| Ty.Trecord { Ty.name = g; lbs; _ } ->
870870
begin
871871
try
872-
TTdot(te, Hstring.make a), Uid.list_assoc (Uid.of_string a) lbs
872+
TTdot(te, Hstring.make a),
873+
Lists.assoc Uid.equal (Uid.of_string a) lbs
873874
with Not_found ->
874875
let g = Uid.show g in
875876
Errors.typing_error (ShouldHaveLabel(g,a)) t.pp_loc

src/lib/reasoners/adt_rel.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ let calc_destructor d e uf =
208208
let r, ex = Uf.find uf e in
209209
match Th.embed r with
210210
| Constr { c_args; _ } ->
211-
begin match Lists.assoc Hstring.equal d c_args with
211+
begin match Lists.assoc Uid.equal d c_args with
212212
| v -> Some (v, ex)
213213
| exception Not_found -> None
214214
end

src/lib/reasoners/records.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module Shostak (X : ALIEN) = struct
123123
| Access (a, x, ty) ->
124124
begin
125125
match normalize x with
126-
| Record (lbs, _) -> Uid.list_assoc a lbs
126+
| Record (lbs, _) -> Lists.assoc Uid.equal a lbs
127127
| x_n -> Access (a, x_n, ty)
128128
end
129129
| Other _ -> v
@@ -326,7 +326,7 @@ module Shostak (X : ALIEN) = struct
326326
| Record (lbs, ty) ->
327327
Record (List.map (fun (n,e') -> n, subst_access x s e') lbs, ty)
328328
| Access (lb, e', _) when compare_mine x e' = 0 ->
329-
Uid.list_assoc lb s
329+
Lists.assoc Uid.equal lb s
330330
| Access (lb', e', ty) -> Access (lb', subst_access x s e', ty)
331331
| Other _ -> e
332332
*)

src/lib/structures/fpa_rounding.ml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,23 @@ let hstring_ae_reprs =
8888
(* The rounding mode is the enum with the SMT values.
8989
The Alt-Ergo values are injected in this type. *)
9090
let fpa_rounding_mode =
91-
let fake_reprs = List.map Uid.of_hstring hstring_smt_reprs in
92-
Ty.Tsum (Uid.of_string "RoundingMode", fake_reprs)
91+
let module DStd = Dolmen.Std in
92+
let cstrs =
93+
List.map
94+
(fun cstr ->
95+
DStd.Expr.Id.mk ~builtin:DStd.Builtin.Base
96+
(DStd.Path.global @@ Hstring.view cstr)
97+
DStd.Expr.{ arity = 0; alias = No_alias }
98+
|> Uid.of_dolmen
99+
)
100+
hstring_smt_reprs
101+
in
102+
let name =
103+
DStd.Expr.Ty.Const.mk
104+
(DStd.Path.global "RoundingMode") 0
105+
|> Uid.of_dolmen
106+
in
107+
Ty.Tsum (name, cstrs)
93108

94109
let rounding_mode_of_smt_hs =
95110
let table = Hashtbl.create 5 in

src/lib/structures/uid.ml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ module DStd = Dolmen.Std
3232
module DE = DStd.Expr
3333

3434
type t =
35-
| Hstring of Hstring.t
36-
| Unique of { name : Hstring.t; index : int }
35+
| Hstring : Hstring.t -> t
36+
| Dolmen : 'a DE.id -> t
3737

3838
(** Helper function: returns the basename of a dolmen path, since in AE
3939
the problems are contained in one-file (for now at least), the path is
@@ -52,38 +52,32 @@ let get_basename = function
5252
| _ -> ()
5353
) path
5454

55-
let[@inline always] of_dolmen DE.{ path; index; _ } =
56-
let name = Hstring.make @@ get_basename path in
57-
Unique { name; index = (index :> int) }
58-
55+
let[@inline always] of_dolmen id = Dolmen id
5956
let[@inline always] of_hstring hs = Hstring hs
6057
let[@inline always] of_string s = of_hstring @@ Hstring.make s
6158

6259
let hash = function
6360
| Hstring hs -> Hstring.hash hs
64-
| Unique { index; _ } -> index
61+
| Dolmen { index; _ } -> (index :> int)
6562

6663
let pp ppf = function
6764
| Hstring hs -> Hstring.print ppf hs
68-
| Unique { name; _ } -> Hstring.print ppf name
65+
| Dolmen { path; _ } -> Fmt.string ppf @@ get_basename path
6966

7067
let show = Fmt.to_to_string pp
7168

7269
let equal u1 u2 =
7370
match u1, u2 with
7471
| Hstring hs1, Hstring hs2 -> Hstring.equal hs1 hs2
75-
| Unique { index = i1; _ }, Unique { index = i2; _ }-> i1 = i2
76-
| _ -> false
72+
| Dolmen id1, Dolmen id2 -> DE.Id.equal id1 id2
73+
| _ ->
74+
Hstring.equal (Hstring.make @@ show u1) (Hstring.make @@ show u2)
7775

7876
let compare u1 u2 =
7977
match u1, u2 with
8078
| Hstring hs1, Hstring hs2 -> Hstring.compare hs1 hs2
81-
| Unique { index = i1; _ }, Unique { index = i2; _ } -> i1 - i2
82-
| _ -> -1
83-
84-
let rec list_assoc x = function
85-
| [] -> raise Not_found
86-
| (y, v) :: l -> if equal x y then v else list_assoc x l
79+
| Dolmen id1, Dolmen id2 -> DE.Id.compare id1 id2
80+
| _ -> Hstring.compare (Hstring.make @@ show u1) (Hstring.make @@ show u2)
8781

8882
module Set = Set.Make
8983
(struct

src/lib/structures/uid.mli

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030

3131
module DE = Dolmen.Std.Expr
3232

33-
type t = private
34-
| Hstring of Hstring.t
35-
| Unique of { name : Hstring.t; index : int }
33+
type t
3634

3735
val of_dolmen : 'a DE.Id.t -> t
3836
val of_string : string -> t
@@ -42,7 +40,6 @@ val pp : t Fmt.t
4240
val show : t -> string
4341
val equal : t -> t -> bool
4442
val compare : t -> t -> int
45-
val list_assoc : t -> (t * 'a) list -> 'a
4643

4744
module Set : Set.S with type elt = t
4845
module Map : Map.S with type key = t

0 commit comments

Comments
 (0)