Skip to content

Commit badaa5a

Browse files
committed
Build on OCaml 5.0 and test unread copies with runtime interfaces
Mutex.protect only exists from OCaml 5.1, so the count table locks with Mutex.lock and Fun.protect like Process_child.with_lock. The unread copy test asked for Belt modules, which the coverage job doesn't build; it now uses runtime interfaces only. Signed-off-by: Jono Prest <jjprest@gmail.com>
1 parent d2fb7c1 commit badaa5a

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎changes/defer-dependency-signature-copy.internal.md‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Build: copy a dependency's interface only when it is read, after the first copy of the same interface in a build, instead of every time a module checks whether the dependency is an alias.

‎compiler/ml/env.ml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,16 @@ type pers_sig = {
571571
let copy_counts : (Digest.t, int * int) Hashtbl.t = Hashtbl.create 64
572572
let copy_counts_lock = Mutex.create ()
573573

574+
(* [Mutex.protect] needs OCaml 5.1. *)
575+
let with_copy_counts_lock action =
576+
Mutex.lock copy_counts_lock;
577+
Fun.protect ~finally:(fun () -> Mutex.unlock copy_counts_lock) action
578+
574579
let find_copy_counts key =
575-
Mutex.protect copy_counts_lock (fun () -> Hashtbl.find_opt copy_counts key)
580+
with_copy_counts_lock (fun () -> Hashtbl.find_opt copy_counts key)
576581

577582
let record_copy_counts key counts =
578-
Mutex.protect copy_counts_lock (fun () ->
583+
with_copy_counts_lock (fun () ->
579584
if Hashtbl.length copy_counts >= 65536 then Hashtbl.reset copy_counts;
580585
Hashtbl.replace copy_counts key counts)
581586

‎tests/ounit_tests/ounit_deferred_signature_tests.ml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ let interface_dirs () =
1414
let runtime = Runtime_package.get_path () in
1515
let belt = Filename.concat (Filename.dirname runtime) "belt" in
1616
List.filter Sys.file_exists
17-
[Filename.concat runtime "lib/ocaml"; Filename.concat belt "lib/ocaml"]
17+
[
18+
Filename.concat runtime "lib/rescript"; Filename.concat belt "lib/rescript";
19+
]
1820

1921
let unit_names dirs =
2022
List.concat_map
@@ -84,7 +86,7 @@ let deferred_copy_tests _ =
8486
(* A copy that is never read still takes its stamps and ids. *)
8587
let unread_copy_tests _ =
8688
let dirs = interface_dirs () in
87-
let names = ["Belt_Array"; "Stdlib_Array"; "Belt_Id"; "Stdlib"] in
89+
let names = ["Stdlib_Array"; "Stdlib_List"; "Stdlib_Option"; "Stdlib"] in
8890
let ask_only ~eager =
8991
Compiler_request_state.with_fresh (fun () ->
9092
Request_local.with_fresh (fun () ->

0 commit comments

Comments
 (0)