Skip to content

Commit 37bc835

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 88233a5 commit 37bc835

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
@@ -584,11 +584,16 @@ type pers_sig = {
584584
let copy_counts : (Digest.t, int * int) Hashtbl.t = Hashtbl.create 64
585585
let copy_counts_lock = Mutex.create ()
586586

587+
(* [Mutex.protect] needs OCaml 5.1. *)
588+
let with_copy_counts_lock action =
589+
Mutex.lock copy_counts_lock;
590+
Fun.protect ~finally:(fun () -> Mutex.unlock copy_counts_lock) action
591+
587592
let find_copy_counts key =
588-
Mutex.protect copy_counts_lock (fun () -> Hashtbl.find_opt copy_counts key)
593+
with_copy_counts_lock (fun () -> Hashtbl.find_opt copy_counts key)
589594

590595
let record_copy_counts key counts =
591-
Mutex.protect copy_counts_lock (fun () ->
596+
with_copy_counts_lock (fun () ->
592597
if Hashtbl.length copy_counts >= 65536 then Hashtbl.reset copy_counts;
593598
Hashtbl.replace copy_counts key counts)
594599

‎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)