Skip to content

Commit a9b17b8

Browse files
committed
Upgrade to Eio 0.15 and OCaml 5.1.1
1 parent 6fb4792 commit a9b17b8

6 files changed

Lines changed: 42 additions & 111 deletions

File tree

DEVELOPMENT.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ From the root of the repo:
55
```sh
66
brew install opam libomp llvm
77

8-
opam switch create . ocaml-variants.5.0.0+options --deps-only -t
8+
opam switch create . ocaml-variants.5.1.1+options --no-install
9+
opam install . --deps-only -t
910

1011
# Remove old Flow version
1112
rm -rf flow && unlink src/flow_parser && unlink src/sedlex && unlink src/collections

src/cli/strings.ml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open! Core
22
open Eio.Std
33

4-
let version = "2.3.0"
4+
let version = "2.4.0"
55

66
type counts = {
77
vue: int ref;
@@ -33,7 +33,7 @@ type file_type =
3333
type traversal = {
3434
table: String.Set.t String.Table.t;
3535
counts: counts;
36-
wp: Eio.Workpool.t;
36+
wp: Eio.Executor_pool.t;
3737
slow_pug: bool;
3838
template_script: Vue.template_script;
3939
root: string;
@@ -96,19 +96,23 @@ let process_job ({ path; _ } as job) =
9696

9797
Vue.collect_from_possible_scripts collector job.template_script
9898

99-
let rec traverse ~fs ~stderr ({ slow_pug; template_script; counts; wp; _ } as traversal) directory =
99+
let rec traverse ~fs ~stderr ({ slow_pug; template_script; counts; _ } as traversal) directory =
100100
Eio.Path.with_open_dir Eio.Path.(fs / directory) Eio.Path.read_dir
101101
|> Fiber.List.iter (fun filename ->
102102
let path = Filename.concat directory filename in
103-
match filename, Utils.Io.stat wp path with
103+
let eio_path = Eio.Path.(fs / path) in
104+
match filename, Eio.Path.kind ~follow:true eio_path with
104105
| "node_modules", _ -> ()
105-
| _, { st_kind = S_DIR; _ } -> traverse ~fs ~stderr traversal path
106-
| _, { st_kind = S_REG; _ } -> (
106+
| _, `Directory -> traverse ~fs ~stderr traversal path
107+
| _, `Regular_file -> (
107108
match file_type_of_filename filename with
108109
| None -> ()
109110
| Some file_type ->
110-
let job = { file_type; eio_path = Eio.Path.(fs / path); path; template_script; slow_pug } in
111-
let collector = Eio.Workpool.submit_exn traversal.wp (fun () -> process_job job) in
111+
let job = { file_type; eio_path; path; template_script; slow_pug } in
112+
let collector =
113+
Eio.Executor_pool.submit_exn traversal.wp ~weight:Utils.Io.traversal_jobs_weight (fun () ->
114+
process_job job )
115+
in
112116
let count =
113117
match job.file_type with
114118
| JS -> counts.js
@@ -134,7 +138,7 @@ let main env options = function
134138
let languages = Vue.parse ~path ~slow_pug flow in
135139
Vue.debug_template ~stdout ~path languages template_script lang
136140
| Pug, ".pug" -> (
137-
let source = Utils.Io.load_flow flow in
141+
let source = Eio.Flow.read_all flow in
138142
let slow_parse () =
139143
let collector = Utils.Collector.create ~path in
140144
Quickjs.extract_to_collector collector Pug source;
@@ -164,27 +168,22 @@ let main env options = function
164168
| _ -> Eio.Flow.copy_string (sprintf "Nothing to do for file [%s]\n" path) stdout )
165169
| Run ->
166170
let overall_time = Utils.Timing.start () in
167-
Switch.run @@ fun sw ->
168171
let outdir = options.outdir in
169172
if List.is_empty options.targets then failwith "Please specify at least one directory";
170173
let fs = Eio.Stdenv.fs env in
171174
let stdout = Eio.Stdenv.stdout env in
172-
let sys_wp =
173-
Eio.Workpool.create ~sw ~domain_count:Utils.Io.num_systhreads ~domain_concurrency:1
174-
(Eio.Stdenv.domain_mgr env)
175-
in
176175
(* Check current directory *)
177176
let strings_dir_files =
178177
let git_dir, strings_dir =
179178
Fiber.pair
180-
(fun () -> Utils.Io.directory_exists sys_wp ".git")
181-
(fun () -> Utils.Io.directory_exists sys_wp outdir)
179+
(fun () -> Eio.Path.is_directory Eio.Path.(fs / ".git"))
180+
(fun () -> Eio.Path.is_directory Eio.Path.(fs / outdir))
182181
in
183182
if not (git_dir || strings_dir) then failwith "This program must be run from the root of your project";
184183
match strings_dir with
185184
| true -> Eio.Path.with_open_dir Eio.Path.(fs / outdir) Eio.Path.read_dir
186185
| false ->
187-
Utils.Io.mkdir_p env sys_wp ~dir_name:outdir ~perms:0o751;
186+
Eio.Path.mkdirs ~exists_ok:true ~perm:0o751 Eio.Path.(fs / outdir);
188187
[]
189188
in
190189

@@ -194,10 +193,7 @@ let main env options = function
194193
let table = String.Table.create () in
195194
let counts = { vue = ref 0; pug = ref 0; html = ref 0; js = ref 0; ts = ref 0 } in
196195
Switch.run @@ fun sw ->
197-
let wp =
198-
Eio.Workpool.create ~sw ~domain_count:Utils.Io.num_cores
199-
~domain_concurrency:Utils.Io.traversal_jobs_per_core (Eio.Stdenv.domain_mgr env)
200-
in
196+
let wp = Eio.Executor_pool.create ~sw ~domain_count:Utils.Io.num_cores (Eio.Stdenv.domain_mgr env) in
201197
options.targets
202198
|> Fiber.List.iter (fun directory ->
203199
let root_slash, root_noslash =
@@ -242,9 +238,10 @@ let main env options = function
242238
| Some "english" -> ()
243239
| Some language -> (
244240
let path = Filename.concat outdir filename in
245-
match Utils.Io.stat sys_wp path with
246-
| { st_kind = S_REG; _ } ->
247-
let other = Eio.Path.with_open_in Eio.Path.(fs / path) (Parsing.Strings.parse ~path) in
241+
let eio_path = Eio.Path.(fs / path) in
242+
match Eio.Path.kind ~follow:true eio_path with
243+
| `Regular_file ->
244+
let other = Eio.Path.with_open_in eio_path (Parsing.Strings.parse ~path) in
248245
Generate.write_other ~fs ~stdout ~version ~outdir ~language english other
249246
| _ -> () )
250247
| None -> ())

src/quickjs/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
(rule
5454
(targets libomp.a)
5555
(action (bash "
56-
cp /usr/local/Cellar/libomp/16.0.5/lib/libomp.a . &> /dev/null \
56+
cp /usr/local/Cellar/libomp/17.0.6/lib/libomp.a . &> /dev/null \
5757
|| cp /usr/lib/libgomp.a libomp.a
5858
"))
5959
(mode standard)

src/quickjs/quickjs.ml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,12 @@ external stub_init_contexts : int -> (unit, string) Result.t = "stub_init_contex
1414
external stub_extract : int -> string -> fn_name:string -> (string array * string array, string) Result.t
1515
= "stub_extract"
1616

17-
module Pool : sig
18-
type t
19-
20-
val create : int -> t
21-
22-
val with_pool : t -> f:(int -> 'a) -> 'a
23-
end = struct
24-
type t = int Eio.Stream.t
25-
26-
let create n =
27-
let stream = Eio.Stream.create n in
28-
for i = 0 to n - 1 do
29-
Eio.Stream.add stream i
30-
done;
31-
stream
32-
33-
let with_pool stream ~f =
34-
let id = Eio.Stream.take stream in
35-
let result =
36-
try f id with
37-
| exn ->
38-
Eio.Stream.add stream id;
39-
raise exn
40-
in
41-
Eio.Stream.add stream id;
42-
result
43-
end
17+
let pool =
18+
let i = ref 0 in
19+
Eio.Pool.create Utils.Io.num_js_workers @@ fun () ->
20+
let x = !i in
21+
incr i;
22+
x
4423

4524
let init_time = Atomic.make Int63.zero
4625

@@ -57,7 +36,7 @@ let init_contexts =
5736

5837
let time = time `Stop in
5938
Atomic.set init_time time;
60-
Promise.resolve w (Pool.create num_js_workers);
39+
Promise.resolve w pool;
6140
print_endline
6241
(sprintf
6342
!"✅ [%{Int63}ms] Initialized %d JS runtimes for TS and/or Pug processing\n"
@@ -101,7 +80,7 @@ let extract kind code =
10180
| Pug -> clean_pug code
10281
in
10382
let fn_name = fn_name_of_kind kind in
104-
Pool.with_pool pool ~f:(fun id -> stub_extract id code ~fn_name)
83+
Eio.Pool.use pool (fun id -> stub_extract id code ~fn_name)
10584

10685
let extract_to_collector (collector : Utils.Collector.t) kind code =
10786
match extract kind code with

src/utils/io.ml

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,4 @@ let num_js_workers = 4
66

77
let num_cores = 4
88

9-
let traversal_jobs_per_core = 4
10-
11-
let num_systhreads = 2
12-
13-
let stat wp path : Core_unix.stats = Eio.Workpool.submit_exn wp (fun () -> Core_unix.stat path)
14-
15-
let load_flow flow =
16-
let open Eio in
17-
(* Taken from [Eio.Path.load] *)
18-
try
19-
let size = File.size flow in
20-
if Optint.Int63.(compare size (of_int Sys.max_string_length)) = 1 then raise @@ Fs.err File_too_large;
21-
let buf = Cstruct.create (Optint.Int63.to_int size) in
22-
let rec loop buf got =
23-
match Flow.single_read flow buf with
24-
| n -> loop (Cstruct.shift buf n) (n + got)
25-
| exception End_of_file -> got
26-
in
27-
let got = loop buf 0 in
28-
Cstruct.to_string ~len:got buf
29-
with
30-
| Exn.Io _ as ex ->
31-
let bt = Stdlib.Printexc.get_raw_backtrace () in
32-
Exn.reraise_with_context ex bt "loading flow"
33-
34-
let directory_exists wp path =
35-
match stat wp path with
36-
| { st_kind = S_DIR; _ } -> true
37-
| { st_kind = _; _ } -> failwithf "%s already exists, but is not a directory" path ()
38-
| exception _ -> false
39-
40-
let mkdir_p env wp ~dir_name ~perms:perm =
41-
let (_ : string) =
42-
Filename.parts dir_name
43-
|> List.fold ~init:"" ~f:(fun acc part ->
44-
match acc with
45-
| "" -> part
46-
| acc -> (
47-
let path = Filename.concat acc part in
48-
directory_exists wp path |> function
49-
| true -> path
50-
| false ->
51-
Eio.Path.mkdir ~perm Eio.Path.(env#fs / path);
52-
path ) )
53-
in
54-
()
9+
let traversal_jobs_weight = 0.25

strings.opam

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@ bug-reports: "https://github.com/okTurtles/strings/issues"
1515
pin-depends: [
1616
[ "angstrom-eio.0.15.0.custom" "git+https://github.com/SGrondin/angstrom.git#1a961940ffb746379b4bdc648bc194501b65348a" ]
1717
[ "angstrom.0.15.0.custom" "git+https://github.com/SGrondin/angstrom.git#1a961940ffb746379b4bdc648bc194501b65348a" ]
18-
[ "eio.0.12.custom" "git+https://github.com/SGrondin/eio.git#37e0dc0d98bd6c18506a974c3ce2b81e89be30a9" ]
19-
[ "eio_posix.0.12.custom" "git+https://github.com/SGrondin/eio.git#37e0dc0d98bd6c18506a974c3ce2b81e89be30a9" ]
20-
[ "eio_linux.0.12.custom" "git+https://github.com/SGrondin/eio.git#37e0dc0d98bd6c18506a974c3ce2b81e89be30a9" ]
21-
[ "eio_main.0.12.custom" "git+https://github.com/SGrondin/eio.git#37e0dc0d98bd6c18506a974c3ce2b81e89be30a9" ]
22-
[ "SZXX.4.0.1.custom" "git+https://github.com/asemio/SZXX.git#4.0.1" ]
18+
[ "eio.0.15.custom" "/Users/simongrondin/dev/eio" ]
19+
[ "eio_posix.0.15.custom" "/Users/simongrondin/dev/eio" ]
20+
[ "eio_linux.0.15.custom" "/Users/simongrondin/dev/eio" ]
21+
[ "eio_main.0.15.custom" "/Users/simongrondin/dev/eio" ]
2322
]
2423
depends: [
25-
"ocaml" { = "5.0.0" }
24+
"ocaml" { = "5.1.1" }
2625
"ocaml-option-flambda"
2726
"dune" { >= "2.8.0"}
2827

2928
"ocamlformat" { = "0.25.1" & with-test }
3029
"ocaml-lsp-server" { with-test }
3130

32-
"eio_main" { = "0.12.custom" }
31+
"eio_main" { = "0.15.custom" }
3332

3433
"angstrom" { = "0.15.0.custom" }
3534
"angstrom-eio" { = "0.15.0.custom" }
36-
"core" { >= "v0.15.0" }
37-
"core_unix" { >= "v0.15.0" }
35+
"core" { >= "v0.16.0" }
36+
"core_unix" { >= "v0.16.0" }
3837
"ppx_deriving"
3938
"ppx_deriving_yojson"
4039
"ppx_gen_rec"
@@ -43,5 +42,5 @@ depends: [
4342
"yojson"
4443
"uuidm"
4544
"wtf8"
46-
"SZXX" { = "4.0.1.custom" }
45+
"SZXX" { >= "4.1.0" }
4746
]

0 commit comments

Comments
 (0)