Skip to content

Commit 44e9786

Browse files
authored
Format compiler sources with ocamlformat (#6901)
* add with-dev-setup group * update dune-project and ocamlformat-ignore * ci: remove --with-dev-setup * ocaml 4.10 * delete all ocamlformat * install ocamlformat * increase cache version * remove grep * add with-test group * restore cache version * use v3 cache * ocamlformat-ignore: add compiler/ext/js_reserved_map.ml * chore: format
1 parent 2ff0dce commit 44e9786

File tree

390 files changed

+40040
-40124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

390 files changed

+40040
-40124
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ jobs:
186186
187187
- name: Install OPAM dependencies
188188
if: steps.cache-opam-env.outputs.cache-hit != 'true'
189-
run: opam install . --deps-only
189+
run: opam install . --deps-only --with-test
190190

191191
- name: Cache OPAM environment
192192
if: steps.cache-opam-env.outputs.cache-hit != 'true'

.ocamlformat-ignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
compiler/js_parser/**
2+
compiler/ml/cmt_format.ml
3+
compiler/ml/pprintast.ml
4+
compiler/core/js_name_of_module_id.ml
5+
compiler/core/js_pass_debug.ml
6+
compiler/core/lam_util.ml
7+
compiler/core/lam_compile_main.ml
8+
compiler/ext/bs_hash_stubs.ml
9+
compiler/ext/js_reserved_map.ml
10+
compiler/ext/ext_string.ml
11+
compiler/ext/ext_string.mli
12+
compiler/ext/ext_sys.ml
13+
compiler/ext/hash.cppo.ml
14+
compiler/ext/hash_set.cppo.ml
15+
compiler/ext/map.cppo.ml
16+
compiler/ext/ordered_hash_map.cppo.ml
17+
compiler/ext/set.cppo.ml
18+
compiler/ext/vec.cppo.ml
19+
compiler/syntax/compiler-libs-406/*

CONTRIBUTING.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Happy hacking!
1717
- [NodeJS v18](https://nodejs.org/)
1818
- C compiler toolchain (usually installed with `xcode` on Mac)
1919
- Rust toolchain (required to build rewatch; follow the instructions at https://www.rust-lang.org/tools/install)
20-
- `opam` (OCaml Package Manager)
20+
- `opam` (OCaml Package Manager) v2.2.0
2121
- VSCode (+ [OCaml Platform Extension](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform))
2222

2323
## Cloning the Git Repo
@@ -49,10 +49,7 @@ opam init
4949
opam switch create 5.2.0 # can also create local switch with opam switch create
5050

5151
# Install dev dependencies from OPAM
52-
opam install . --deps-only
53-
54-
# For IDE support, install the OCaml language server
55-
opam install ocaml-lsp-server
52+
opam install . --deps-only --with-test --with-dev-setup -y
5653
```
5754

5855
#### npm install

compiler/bsb/.ocamlformat

-1
This file was deleted.

compiler/bsb/bsb_arg.ml

+27-27
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,29 @@ let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
6363
buf +> String.make (!max_col + 4) ' ');
6464
match String.index_from_opt doc !cur '\n' with
6565
| None ->
66-
buf +> String.sub doc !cur (String.length doc - !cur);
67-
cur := doc_length
66+
buf +> String.sub doc !cur (String.length doc - !cur);
67+
cur := doc_length
6868
| Some new_line_pos ->
69-
buf +> String.sub doc !cur (new_line_pos - !cur);
70-
cur := new_line_pos + 1
69+
buf +> String.sub doc !cur (new_line_pos - !cur);
70+
cur := new_line_pos + 1
7171
done;
7272
buf +> "\n")))
7373

7474
let stop_raise ~usage ~(error : error) (speclist : t) =
7575
let b = Ext_buffer.create 200 in
7676
(match error with
7777
| Unknown ("-help" | "--help" | "-h") ->
78-
usage_b b ~usage speclist;
79-
Ext_buffer.output_buffer stdout b;
80-
exit 0
78+
usage_b b ~usage speclist;
79+
Ext_buffer.output_buffer stdout b;
80+
exit 0
8181
| Unknown s ->
82-
b +> "Unknown option \"";
83-
b +> s;
84-
b +> "\".\n"
82+
b +> "Unknown option \"";
83+
b +> s;
84+
b +> "\".\n"
8585
| Missing s ->
86-
b +> "Option \"";
87-
b +> s;
88-
b +> "\" needs an argument.\n");
86+
b +> "Option \"";
87+
b +> s;
88+
b +> "\" needs an argument.\n");
8989
usage_b b ~usage speclist;
9090
bad_arg (Ext_buffer.contents b)
9191

@@ -99,20 +99,20 @@ let parse_exn ~usage ~argv ?(start = 1) ?(finish = Array.length argv)
9999
if s <> "" && s.[0] = '-' then
100100
match Ext_spec.assoc3 speclist s with
101101
| Some action -> (
102-
match action with
103-
| Unit r -> (
104-
match r with
105-
| Unit_set r -> r.contents <- true
106-
| Unit_call f -> f ())
107-
| String f -> (
108-
if !current >= finish then
109-
stop_raise ~usage ~error:(Missing s) speclist
110-
else
111-
let arg = argv.(!current) in
112-
incr current;
113-
match f with
114-
| String_call f -> f arg
115-
| String_set u -> u.contents <- arg))
102+
match action with
103+
| Unit r -> (
104+
match r with
105+
| Unit_set r -> r.contents <- true
106+
| Unit_call f -> f ())
107+
| String f -> (
108+
if !current >= finish then
109+
stop_raise ~usage ~error:(Missing s) speclist
110+
else
111+
let arg = argv.(!current) in
112+
incr current;
113+
match f with
114+
| String_call f -> f arg
115+
| String_set u -> u.contents <- arg))
116116
| None -> stop_raise ~usage ~error:(Unknown s) speclist
117117
else rev_list := s :: !rev_list
118118
done;

compiler/bsb/bsb_build_util.ml

+74-69
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
let flag_concat flag xs =
2626
String.concat Ext_string.single_space
27-
(Ext_list.flat_map xs (fun x -> [ flag; x ]))
27+
(Ext_list.flat_map xs (fun x -> [flag; x]))
2828

2929
let ( // ) = Ext_path.combine
3030

@@ -42,11 +42,11 @@ let pp_flag (xs : string) = "-pp " ^ Ext_filename.maybe_quote xs
4242

4343
let include_dirs dirs =
4444
String.concat Ext_string.single_space
45-
(Ext_list.flat_map dirs (fun x -> [ "-I"; Ext_filename.maybe_quote x ]))
45+
(Ext_list.flat_map dirs (fun x -> ["-I"; Ext_filename.maybe_quote x]))
4646

4747
let include_dirs_by dirs fn =
4848
String.concat Ext_string.single_space
49-
(Ext_list.flat_map dirs (fun x -> [ "-I"; Ext_filename.maybe_quote (fn x) ]))
49+
(Ext_list.flat_map dirs (fun x -> ["-I"; Ext_filename.maybe_quote (fn x)]))
5050

5151
(* we use lazy $src_root_dir *)
5252

@@ -64,7 +64,7 @@ let convert_and_resolve_path : string -> string -> string =
6464
else failwith ("Unknown OS :" ^ Sys.os_type)
6565
(* we only need convert the path in the beginning *)
6666

67-
type result = { path : string; checked : bool }
67+
type result = {path: string; checked: bool}
6868

6969
(* Magic path resolution:
7070
foo => foo
@@ -78,7 +78,7 @@ let resolve_bsb_magic_file ~cwd ~desc p : result =
7878
let no_slash = Ext_string.no_slash_idx p in
7979
if no_slash < 0 then
8080
(* Single file FIXME: better error message for "" input *)
81-
{ path = p; checked = false }
81+
{path = p; checked = false}
8282
else
8383
let first_char = String.unsafe_get p 0 in
8484
if Filename.is_relative p && first_char <> '.' then
@@ -91,13 +91,13 @@ let resolve_bsb_magic_file ~cwd ~desc p : result =
9191
(* let p = if Ext_sys.is_windows_or_cygwin then Ext_string.replace_slash_backward p else p in *)
9292
let package_dir = Bsb_pkg.resolve_bs_package ~cwd package_name in
9393
let path = package_dir // relative_path in
94-
if Sys.file_exists path then { path; checked = true }
94+
if Sys.file_exists path then {path; checked = true}
9595
else (
9696
Bsb_log.error "@{<error>Could not resolve @} %s in %s@." p cwd;
9797
failwith (p ^ " not found when resolving " ^ desc))
9898
else
9999
(* relative path [./x/y]*)
100-
{ path = convert_and_resolve_path cwd p; checked = true }
100+
{path = convert_and_resolve_path cwd p; checked = true}
101101

102102
(** converting a file from Linux path format to Windows *)
103103

@@ -121,7 +121,9 @@ let rec mkp dir =
121121

122122
let get_list_string_acc (s : Ext_json_types.t array) acc =
123123
Ext_array.to_list_map_acc s acc (fun x ->
124-
match x with Str x -> Some x.str | _ -> None)
124+
match x with
125+
| Str x -> Some x.str
126+
| _ -> None)
125127

126128
let get_list_string s = get_list_string_acc s []
127129

@@ -130,7 +132,7 @@ let ( |? ) m (key, cb) = m |> Ext_json.test key cb
130132

131133
type top = Expect_none | Expect_name of string
132134

133-
type package_context = { proj_dir : string; top : top; is_pinned: bool }
135+
type package_context = {proj_dir: string; top: top; is_pinned: bool}
134136

135137
(**
136138
TODO: check duplicate package name
@@ -146,79 +148,82 @@ type package_context = { proj_dir : string; top : top; is_pinned: bool }
146148
let pp_packages_rev ppf lst =
147149
Ext_list.rev_iter lst (fun s -> Format.fprintf ppf "%s " s)
148150

149-
let extract_pinned_dependencies (map : Ext_json_types.t Map_string.t) : Set_string.t =
151+
let extract_pinned_dependencies (map : Ext_json_types.t Map_string.t) :
152+
Set_string.t =
150153
match Map_string.find_opt map Bsb_build_schemas.pinned_dependencies with
151154
| None -> Set_string.empty
152-
| Some (Arr { content }) ->
153-
Set_string.of_list (get_list_string content)
155+
| Some (Arr {content}) -> Set_string.of_list (get_list_string content)
154156
| Some config -> Bsb_exception.config_error config "expect an array of string"
155157

156158
let rec walk_all_deps_aux (visited : string Hash_string.t) (paths : string list)
157159
~(top : top) (dir : string) (queue : _ Queue.t) ~pinned_dependencies =
158-
match Bsb_config_load.load_json ~per_proj_dir:dir ~warn_legacy_config:false with
159-
| _, Obj { map; loc } ->
160-
let cur_package_name =
161-
match Map_string.find_opt map Bsb_build_schemas.name with
162-
| Some (Str { str; loc }) ->
163-
(match top with
164-
| Expect_none -> ()
165-
| Expect_name s ->
166-
if s <> str then
167-
Bsb_exception.errorf ~loc
168-
"package name is expected to be %s but got %s" s str);
169-
str
170-
| Some _ | None ->
171-
Bsb_exception.errorf ~loc "package name missing in %s/bsconfig.json"
172-
dir
160+
match
161+
Bsb_config_load.load_json ~per_proj_dir:dir ~warn_legacy_config:false
162+
with
163+
| _, Obj {map; loc} ->
164+
let cur_package_name =
165+
match Map_string.find_opt map Bsb_build_schemas.name with
166+
| Some (Str {str; loc}) ->
167+
(match top with
168+
| Expect_none -> ()
169+
| Expect_name s ->
170+
if s <> str then
171+
Bsb_exception.errorf ~loc
172+
"package name is expected to be %s but got %s" s str);
173+
str
174+
| Some _ | None ->
175+
Bsb_exception.errorf ~loc "package name missing in %s/bsconfig.json" dir
176+
in
177+
if Ext_list.mem_string paths cur_package_name then (
178+
Bsb_log.error "@{<error>Cyclic dependencies in package stack@}@.";
179+
exit 2);
180+
let package_stacks = cur_package_name :: paths in
181+
Bsb_log.info "@{<info>Package stack:@} %a @." pp_packages_rev package_stacks;
182+
if Hash_string.mem visited cur_package_name then
183+
Bsb_log.info "@{<info>Visited before@} %s@." cur_package_name
184+
else
185+
let explore_deps (deps : string) pinned_dependencies =
186+
map
187+
|? ( deps,
188+
`Arr
189+
(fun (new_packages : Ext_json_types.t array) ->
190+
Ext_array.iter new_packages (fun js ->
191+
match js with
192+
| Str {str = new_package} ->
193+
let package_dir =
194+
Bsb_pkg.resolve_bs_package ~cwd:dir
195+
(Bsb_pkg_types.string_as_package new_package)
196+
in
197+
walk_all_deps_aux visited package_stacks
198+
~top:(Expect_name new_package) package_dir queue
199+
~pinned_dependencies
200+
| _ -> Bsb_exception.errorf ~loc "%s expect an array" deps))
201+
)
202+
|> ignore
173203
in
174-
if Ext_list.mem_string paths cur_package_name then (
175-
Bsb_log.error "@{<error>Cyclic dependencies in package stack@}@.";
176-
exit 2);
177-
let package_stacks = cur_package_name :: paths in
178-
Bsb_log.info "@{<info>Package stack:@} %a @." pp_packages_rev
179-
package_stacks;
180-
if Hash_string.mem visited cur_package_name then
181-
Bsb_log.info "@{<info>Visited before@} %s@." cur_package_name
182-
else
183-
let explore_deps (deps : string) pinned_dependencies =
184-
map
185-
|? ( deps,
186-
`Arr
187-
(fun (new_packages : Ext_json_types.t array) ->
188-
Ext_array.iter new_packages (fun js ->
189-
match js with
190-
| Str { str = new_package } ->
191-
let package_dir =
192-
Bsb_pkg.resolve_bs_package ~cwd:dir
193-
(Bsb_pkg_types.string_as_package new_package)
194-
in
195-
walk_all_deps_aux visited package_stacks
196-
~top:(Expect_name new_package) package_dir queue
197-
~pinned_dependencies
198-
| _ ->
199-
Bsb_exception.errorf ~loc "%s expect an array" deps))
200-
)
201-
|> ignore
202-
in
203-
let is_pinned = match top with
204+
let is_pinned =
205+
match top with
204206
| Expect_name n when Set_string.mem pinned_dependencies n -> true
205207
| _ -> false
206-
in
207-
let pinned_dependencies = match is_pinned with
208+
in
209+
let pinned_dependencies =
210+
match is_pinned with
208211
| true ->
209-
let transitive_pinned_dependencies = extract_pinned_dependencies map
212+
let transitive_pinned_dependencies =
213+
extract_pinned_dependencies map
210214
in
211215
Set_string.union transitive_pinned_dependencies pinned_dependencies
212216
| false -> pinned_dependencies
213-
in
214-
explore_deps Bsb_build_schemas.bs_dependencies pinned_dependencies;
215-
(match top with
216-
| Expect_none -> explore_deps Bsb_build_schemas.bs_dev_dependencies pinned_dependencies
217-
| Expect_name _ when is_pinned ->
218-
explore_deps Bsb_build_schemas.bs_dev_dependencies pinned_dependencies
219-
| Expect_name _ -> ());
220-
Queue.add { top; proj_dir = dir; is_pinned } queue;
221-
Hash_string.add visited cur_package_name dir
217+
in
218+
explore_deps Bsb_build_schemas.bs_dependencies pinned_dependencies;
219+
(match top with
220+
| Expect_none ->
221+
explore_deps Bsb_build_schemas.bs_dev_dependencies pinned_dependencies
222+
| Expect_name _ when is_pinned ->
223+
explore_deps Bsb_build_schemas.bs_dev_dependencies pinned_dependencies
224+
| Expect_name _ -> ());
225+
Queue.add {top; proj_dir = dir; is_pinned} queue;
226+
Hash_string.add visited cur_package_name dir
222227
| _ -> ()
223228

224229
let walk_all_deps dir ~pinned_dependencies : package_context Queue.t =

compiler/bsb/bsb_build_util.mli

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ val get_list_string : Ext_json_types.t array -> string list
7474

7575
type top = Expect_none | Expect_name of string
7676

77-
type result = { path : string; checked : bool }
77+
type result = {path: string; checked: bool}
7878

7979
(* [resolve_bsb_magic_file]
8080
returns a tuple (path,checked)
8181
when checked is true, it means such file should exist without depending on env
8282
*)
8383
val resolve_bsb_magic_file : cwd:string -> desc:string -> string -> result
8484

85-
type package_context = { proj_dir : string; top : top; is_pinned: bool }
85+
type package_context = {proj_dir: string; top: top; is_pinned: bool}
8686

87-
val extract_pinned_dependencies: Ext_json_types.t Map_string.t -> Set_string.t
87+
val extract_pinned_dependencies : Ext_json_types.t Map_string.t -> Set_string.t
8888

8989
val walk_all_deps :
9090
string -> pinned_dependencies:Set_string.t -> package_context Queue.t

compiler/bsb/bsb_clean.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let ninja_clean proj_dir =
3131
let cwd = proj_dir // lib_artifacts_dir in
3232
if Sys.file_exists cwd then
3333
let eid =
34-
Bsb_unix.run_command_execv { cmd; args = [| cmd; "-t"; "clean" |]; cwd }
34+
Bsb_unix.run_command_execv {cmd; args = [|cmd; "-t"; "clean"|]; cwd}
3535
in
3636
if eid <> 0 then Bsb_log.warn "@{<warning>Failed@}@."
3737
with e -> Bsb_log.warn "@{<warning>Failed@}: %s @." (Printexc.to_string e)

0 commit comments

Comments
 (0)