Skip to content

Commit 17416be

Browse files
committed
Fix HC collisions.
When hashing formulas, consider the type. This ensures consistency with formula equality checks and reduces collision rates, enhancing performance, especially with OCaml 5.
1 parent 517dad7 commit 17416be

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/ecAst.ml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ module Hexpr = Why3.Hashcons.Make (struct
854854
in
855855
Why3.Hashcons.combine_list b1_hash 0 bs
856856

857-
let hash e =
858-
match e.e_node with
857+
let hash_node (e : expr_node) =
858+
match e with
859859
| Eint i -> BI.hash i
860860
| Elocal x -> Hashtbl.hash x
861861
| Evar x -> pv_hash x
@@ -889,6 +889,9 @@ module Hexpr = Why3.Hashcons.Make (struct
889889
| Eproj (e, i) ->
890890
Why3.Hashcons.combine (e_hash e) i
891891

892+
let hash (e : expr) =
893+
Why3.Hashcons.combine (ty_hash e.e_ty) (hash_node e.e_node)
894+
892895
let fv_node e =
893896
let union ex =
894897
List.fold_left (fun s e -> fv_union s (ex e)) Mid.empty
@@ -980,8 +983,8 @@ module Hsform = Why3.Hashcons.Make (struct
980983
ty_equal f1.f_ty f2.f_ty
981984
&& equal_node f1.f_node f2.f_node
982985

983-
let hash f =
984-
match f.f_node with
986+
let hash_node (f : f_node) =
987+
match f with
985988
| Fquant(q, b, f) ->
986989
Why3.Hashcons.combine2 (f_hash f) (b_hash b) (qt_hash q)
987990

@@ -1028,6 +1031,9 @@ module Hsform = Why3.Hashcons.Make (struct
10281031
| FeagerF eg -> eg_hash eg
10291032
| Fpr pr -> pr_hash pr
10301033

1034+
let hash (f : form) =
1035+
Why3.Hashcons.combine (ty_hash f.f_ty) (hash_node f.f_node)
1036+
10311037
let fv_mlr = Sid.add mleft (Sid.singleton mright)
10321038

10331039
let fv_node f =

0 commit comments

Comments
 (0)