Skip to content

Commit 23835ed

Browse files
committed
Fix #810: keep hashing the filename
Since we only keep the first 36 bits of the string, we get collisions pretty easily if we use the filename directly.
1 parent 705cc19 commit 23835ed

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/ppx/ppx_eliom_utils.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let pat_args = function [] -> punit () | [p] -> p | l -> Pat.tuple l
5050
These bits are encoded using an OCaml-compatible variant of Base
5151
64, as the hash is used to generate OCaml identifiers. *)
5252
let file_hash loc =
53-
let s = Filename.basename loc.Location.loc_start.pos_fname in
53+
let s = Digest.string (Filename.basename loc.Location.loc_start.pos_fname) in
5454
let e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_'" in
5555
let o = Bytes.create 6 in
5656
let g p = Char.code s.[p] in
@@ -283,7 +283,7 @@ module Cmo = struct
283283
; ev_kind = Event_after ty
284284
; _ } ->
285285
if pos_cnum' = pos_cnum + 1
286-
then Hashtbl.add events (Filename.basename pos_fname, pos_cnum) ty
286+
then Hashtbl.add events (pos_fname, pos_cnum) ty
287287
| _ -> ())
288288
evl
289289

@@ -459,7 +459,7 @@ module Cmo = struct
459459

460460
let find err loc =
461461
let {Lexing.pos_fname; pos_cnum; _} = loc.Location.loc_start in
462-
try typ (Hashtbl.find (Lazy.force events) (Filename.basename pos_fname, pos_cnum))
462+
try typ (Hashtbl.find (Lazy.force events) (pos_fname, pos_cnum))
463463
with Not_found ->
464464
Typ.extension ~loc @@ Location.Error.to_extension
465465
@@ Location.Error.make ~loc ~sub:[]

0 commit comments

Comments
 (0)