Skip to content

Commit c253029

Browse files
committed
clean up before gentype tsx support
1 parent 43ee020 commit c253029

21 files changed

+5566
-5470
lines changed

jscomp/all.depend

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ext/set_gen.cmx :
1919
ext/map_gen.cmx :
2020
ext/ext_file_pp.cmx : ext/string_vec.cmx ext/ext_file_pp.cmi
2121
ext/ext_format.cmx : ext/ext_format.cmi
22-
ext/hashtbl_gen.cmx : ext/ext_util.cmx
22+
ext/hashtbl_gen.cmx : ext/ext_util.cmx ext/ext_array.cmx
2323
ext/ext_string.cmx : ext/ext_char.cmx ext/ext_bytes.cmx ext/ext_string.cmi
2424
ext/ext_utf8.cmx : ext/ext_utf8.cmi
2525
ext/ext_js_regex.cmx : ext/ext_utf8.cmx ext/ext_js_regex.cmi
@@ -34,7 +34,7 @@ ext/ext_pervasives.cmx : ext/ext_list.cmx ext/ext_pervasives.cmi
3434
ext/ext_pp.cmx : ext/ext_pervasives.cmx ext/ext_pp.cmi
3535
ext/ext_ref.cmx : ext/ext_list.cmx ext/ext_ref.cmi
3636
ext/ext_sys.cmx : ext/ext_sys.cmi
37-
ext/hash_set_gen.cmx : ext/ext_util.cmx
37+
ext/hash_set_gen.cmx : ext/ext_util.cmx ext/ext_array.cmx
3838
ext/hash_set.cmx : ext/hash_set_gen.cmx ext/hash_set.cmi
3939
ext/string_hash_set.cmx : ext/hash_set_gen.cmx ext/ext_string.cmx \
4040
stubs/bs_hash_stubs.cmx ext/string_hash_set.cmi
@@ -44,7 +44,7 @@ ext/int_hash_set.cmx : ext/hash_set_gen.cmx ext/ext_int.cmx \
4444
stubs/bs_hash_stubs.cmx ext/int_hash_set.cmi
4545
ext/hash_set_ident_mask.cmx : ext/ext_util.cmx ext/ext_ident.cmx \
4646
stubs/bs_hash_stubs.cmx ext/hash_set_ident_mask.cmi
47-
ext/ordered_hash_set_gen.cmx : ext/ext_util.cmx
47+
ext/ordered_hash_set_gen.cmx : ext/ext_util.cmx ext/ext_array.cmx
4848
ext/ordered_hash_set_string.cmx : ext/ordered_hash_set_gen.cmx \
4949
ext/ext_util.cmx ext/ext_string.cmx stubs/bs_hash_stubs.cmx \
5050
ext/ordered_hash_set_string.cmi
@@ -53,7 +53,7 @@ ext/ordered_hash_set_ident.cmx : ext/ordered_hash_set_gen.cmx \
5353
ext/ordered_hash_set_ident.cmi
5454
ext/ordered_hash_set_make.cmx : ext/ordered_hash_set_gen.cmx \
5555
ext/ext_util.cmx
56-
ext/ordered_hash_map_gen.cmx : ext/ext_util.cmx
56+
ext/ordered_hash_map_gen.cmx : ext/ext_util.cmx ext/ext_array.cmx
5757
ext/union_find.cmx : ext/union_find.cmi
5858
ext/ident_map.cmx : ext/map_gen.cmx ext/ext_ident.cmx ext/ident_map.cmi
5959
ext/ident_set.cmx : ext/set_gen.cmx ext/ident_set.cmi
@@ -816,7 +816,7 @@ core/js_main.cmx : super_errors/super_main.cmx \
816816
common/js_config.cmx ext/ext_string.cmx core/bs_conditional_initial.cmx \
817817
core/js_main.cmi
818818
core/cmjdump_main.cmx : ext/string_map.cmx core/lam_arity.cmx \
819-
core/js_packages_info.cmx core/js_cmj_format.cmx
819+
core/js_packages_info.cmx core/js_cmj_format.cmx ext/ext_array.cmx
820820
core/astdump_main.cmx : common/ml_binary.cmx ext/ext_path.cmx \
821821
bsb/bsb_helper_depfile_gen.cmx
822822
ounit/oUnit.cmi :
@@ -874,7 +874,7 @@ ounit_tests/ounit_hash_stubs_test.cmx : ounit_tests/ounit_tests_util.cmx \
874874
stubs/bs_hash_stubs.cmx
875875
ounit_tests/ounit_hash_set_tests.cmx : ext/string_hash_set.cmx \
876876
ext/ordered_hash_set_string.cmx ounit/oUnit.cmx ext/hash_set_poly.cmx \
877-
ext/hash_set.cmx
877+
ext/hash_set.cmx ext/ext_array.cmx
878878
ounit_tests/ounit_scc_tests.cmx : ext/string_hashtbl.cmx ounit/oUnit.cmx \
879879
ext/int_vec_vec.cmx ext/int_vec.cmx ext/ext_string.cmx ext/ext_scc.cmx
880880
ounit_tests/ounit_hashtbl_tests.cmx : ext/string_hashtbl.cmx ounit/oUnit.cmx
@@ -1010,20 +1010,21 @@ bsb/bsb_ninja_regen.cmx : ext/literals.cmx ext/ext_path.cmx \
10101010
bsb/bsb_ninja_gen.cmx bsb/bsb_ninja_check.cmx bsb/bsb_merlin_gen.cmx \
10111011
bsb/bsb_log.cmx bsb/bsb_config_parse.cmx bsb/bsb_config.cmx \
10121012
bsb/bsb_clean.cmx bsb/bsb_build_util.cmx bsb/bsb_ninja_regen.cmi
1013-
bsb/bsb_ninja_util.cmx : ext/ext_string.cmx bsb/bsb_rule.cmx \
1014-
bsb/bsb_ninja_util.cmi
1013+
bsb/bsb_ninja_util.cmx : ext/ext_string.cmx ext/ext_array.cmx \
1014+
bsb/bsb_rule.cmx bsb/bsb_ninja_util.cmi
10151015
bsb/bsb_package_specs.cmx : ext/string_map.cmx ext/literals.cmx \
10161016
ext/ext_string.cmx ext/ext_path.cmx ext/ext_namespace.cmx \
1017-
ext/ext_json_types.cmx ext/ext_json.cmx bsb/bsb_exception.cmx \
1018-
bsb/bsb_config.cmx bsb/bsb_build_schemas.cmx bsb/bsb_package_specs.cmi
1017+
ext/ext_json_types.cmx ext/ext_json.cmx ext/ext_array.cmx \
1018+
bsb/bsb_exception.cmx bsb/bsb_config.cmx bsb/bsb_build_schemas.cmx \
1019+
bsb/bsb_package_specs.cmi
10191020
bsb/bsb_parse_sources.cmx : ext/string_vec.cmx ext/string_set.cmx \
10201021
ext/string_map.cmx ext/literals.cmx ext/ext_string.cmx \
1021-
ext/ext_position.cmx ext/ext_path.cmx ext/ext_namespace.cmx \
1022-
ext/ext_json_types.cmx ext/ext_json_parse.cmx ext/ext_json.cmx \
1023-
ext/ext_filename.cmx ext/ext_file_pp.cmx ext/ext_array.cmx \
1024-
bsb/bsb_log.cmx bsb/bsb_file_groups.cmx bsb/bsb_exception.cmx \
1025-
bsb/bsb_dir_index.cmx bsb/bsb_db.cmx bsb/bsb_config.cmx \
1026-
bsb/bsb_build_util.cmx bsb/bsb_build_schemas.cmx \
1022+
ext/ext_position.cmx ext/ext_pervasives.cmx ext/ext_path.cmx \
1023+
ext/ext_namespace.cmx ext/ext_json_types.cmx ext/ext_json_parse.cmx \
1024+
ext/ext_json.cmx ext/ext_filename.cmx ext/ext_file_pp.cmx \
1025+
ext/ext_array.cmx bsb/bsb_log.cmx bsb/bsb_file_groups.cmx \
1026+
bsb/bsb_exception.cmx bsb/bsb_dir_index.cmx bsb/bsb_db.cmx \
1027+
bsb/bsb_config.cmx bsb/bsb_build_util.cmx bsb/bsb_build_schemas.cmx \
10271028
bsb/bsb_parse_sources.cmi
10281029
bsb/bsb_pkg.cmx : ext/string_hashtbl.cmx ext/literals.cmx bsb/bsb_log.cmx \
10291030
bsb/bsb_exception.cmx bsb/bsb_pkg.cmi

jscomp/bin/all_ounit_tests.ml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,11 @@ val map :
13351335
'a array ->
13361336
('a -> 'b) ->
13371337
'b array
1338+
1339+
val iter :
1340+
'a array ->
1341+
('a -> unit) ->
1342+
unit
13381343
end = struct
13391344
#1 "ext_array.ml"
13401345
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -1591,6 +1596,10 @@ let map a f =
15911596
r
15921597
end
15931598

1599+
let iter a f =
1600+
let open Array in
1601+
for i = 0 to length a - 1 do f(unsafe_get a i) done
1602+
15941603
end
15951604
module Ext_bytes : sig
15961605
#1 "ext_bytes.mli"
@@ -4619,11 +4628,11 @@ let stats h =
46194628
let mbl =
46204629
Array.fold_left (fun m b -> max m (List.length b)) 0 h.data in
46214630
let histo = Array.make (mbl + 1) 0 in
4622-
Array.iter
4631+
Ext_array.iter h.data
46234632
(fun b ->
46244633
let l = List.length b in
46254634
histo.(l) <- histo.(l) + 1)
4626-
h.data;
4635+
;
46274636
{Hashtbl.num_bindings = h.size;
46284637
num_buckets = Array.length h.data;
46294638
max_bucket_length = mbl;
@@ -5193,11 +5202,11 @@ let stats h =
51935202
let mbl =
51945203
Array.fold_left (fun m (b : _ bucket) -> max m (bucket_length 0 b)) 0 h.data in
51955204
let histo = Array.make (mbl + 1) 0 in
5196-
Array.iter
5205+
Ext_array.iter h.data
51975206
(fun b ->
51985207
let l = bucket_length 0 b in
51995208
histo.(l) <- histo.(l) + 1)
5200-
h.data;
5209+
;
52015210
{ Hashtbl.num_bindings = h.size;
52025211
num_buckets = h.data_mask + 1 ;
52035212
max_bucket_length = mbl;
@@ -5598,7 +5607,7 @@ let suites =
55985607
let of_array lst =
55995608
let len = Array.length lst in
56005609
let tbl = String_hash_set.create len in
5601-
Array.iter (String_hash_set.add tbl ) lst; tbl in
5610+
Ext_array.iter lst (String_hash_set.add tbl) ; tbl in
56025611
let hash = of_array const_tbl in
56035612
let len = String_hash_set.length hash in
56045613
String_hash_set.remove hash "x";
@@ -5954,11 +5963,11 @@ let stats h =
59545963
let mbl =
59555964
Array.fold_left (fun m b -> max m (bucket_length 0 b)) 0 h.data in
59565965
let histo = Array.make (mbl + 1) 0 in
5957-
Array.iter
5966+
Ext_array.iter h.data
59585967
(fun b ->
59595968
let l = bucket_length 0 b in
59605969
histo.(l) <- histo.(l) + 1)
5961-
h.data;
5970+
;
59625971
{Hashtbl.
59635972
num_bindings = h.size;
59645973
num_buckets = Array.length h.data;
@@ -10803,6 +10812,8 @@ external reraise: exn -> 'a = "%reraise"
1080310812

1080410813
val finally : 'a -> ('a -> 'c) -> ('a -> 'b) -> 'b
1080510814

10815+
val try_it : (unit -> unit) -> unit
10816+
1080610817
val with_file_as_chan : string -> (out_channel -> 'a) -> 'a
1080710818

1080810819
val with_file_as_pp : string -> (Format.formatter -> 'a) -> 'a
@@ -10866,6 +10877,9 @@ let finally v action f =
1086610877
reraise e
1086710878
| e -> action v ; e
1086810879

10880+
let try_it f =
10881+
try f () with _ -> ()
10882+
1086910883
let with_file_as_chan filename f =
1087010884
finally (open_out_bin filename) close_out f
1087110885

jscomp/bsb/bsb_build_util.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ let rec walk_all_deps_aux visited paths top dir cb =
199199
map
200200
|?
201201
(Bsb_build_schemas.bs_dependencies,
202-
`Arr (fun (new_packages : Ext_json_types.t array) ->
203-
new_packages
204-
|> Array.iter (fun (js : Ext_json_types.t) ->
202+
`Arr (fun (new_packages : Ext_json_types.t array) ->
203+
Ext_array.iter new_packages(fun js ->
205204
begin match js with
206205
| Str {str = new_package} ->
207206
let package_dir =
@@ -218,9 +217,8 @@ let rec walk_all_deps_aux visited paths top dir cb =
218217
map
219218
|?
220219
(Bsb_build_schemas.bs_dev_dependencies,
221-
`Arr (fun (new_packages : Ext_json_types.t array) ->
222-
new_packages
223-
|> Array.iter (fun (js : Ext_json_types.t) ->
220+
`Arr (fun (new_packages : Ext_json_types.t array) ->
221+
Ext_array.iter new_packages (fun (js : Ext_json_types.t) ->
224222
match js with
225223
| Str {str = new_package} ->
226224
let package_dir =

jscomp/bsb/bsb_ninja_util.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,6 @@ let output_kv key value oc =
166166
output_string oc "\n"
167167

168168
let output_kvs kvs oc =
169-
Array.iter (fun (k,v) -> output_kv k v oc) kvs
169+
Ext_array.iter kvs (fun (k,v) -> output_kv k v oc)
170170

171171

jscomp/bsb/bsb_package_specs.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ let bad_module_format_message_exn ~loc format =
6363
let rec from_array (arr : Ext_json_types.t array) : Spec_set.t =
6464
let spec = ref Spec_set.empty in
6565
let has_in_source = ref false in
66-
arr
67-
|> Array.iter (fun (x : Ext_json_types.t) ->
68-
66+
Ext_array.iter arr (fun x ->
6967
let result = from_json_single x in
7068
if result.in_source then
7169
(

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ let extract_generators
174174
begin match String_map.find_opt Bsb_build_schemas.generators input with
175175
| Some (Arr { content ; loc_start}) ->
176176
(* Need check is dev build or not *)
177-
Array.iter begin fun (x : Ext_json_types.t) ->
177+
Ext_array.iter content (fun x ->
178178
match x with
179179
| Obj { map = generator; loc} ->
180180
begin match String_map.find_opt Bsb_build_schemas.name generator,
@@ -201,7 +201,7 @@ let extract_generators
201201
Bsb_exception.errorf ~loc "Invalid generator format"
202202
end
203203
| _ -> Bsb_exception.errorf ~loc:(Ext_json.loc_of x) "Invalid generator format"
204-
end content
204+
)
205205
| Some x -> Bsb_exception.errorf ~loc:(Ext_json.loc_of x ) "Invalid generator format"
206206
| None -> ()
207207
end ;
@@ -225,7 +225,7 @@ let clean_staled_bs_js_files
225225
(context : cxt)
226226
(cur_sources : _ String_map.t )
227227
(files : string array) =
228-
Array.iter begin fun current_file ->
228+
Ext_array.iter files (fun current_file ->
229229
match Ext_namespace.ends_with_bs_suffix_then_chop current_file with
230230
| None -> ()
231231
| Some basename -> (* Found [.bs.js] files *)
@@ -260,9 +260,10 @@ let clean_staled_bs_js_files
260260
Literals.suffix_cmt; Literals.suffix_cmti ;
261261
Literals.suffix_mlast; Literals.suffix_mlastd;
262262
Literals.suffix_mliast; Literals.suffix_mliastd
263+
(*TODO: GenType*)
263264
];
264265
end
265-
end files
266+
)
266267

267268
let rec
268269
parsing_source_dir_map
@@ -461,7 +462,7 @@ type walk_cxt = {
461462
let rec walk_sources (cxt : walk_cxt) (sources : Ext_json_types.t) =
462463
match sources with
463464
| Arr {content = file_groups} ->
464-
Array.iter (fun x -> walk_single_source cxt x) file_groups
465+
Ext_array.iter file_groups (fun x -> walk_single_source cxt x)
465466
| x -> walk_single_source cxt x
466467
and walk_single_source cxt (x : Ext_json_types.t) =
467468
match x with
@@ -488,7 +489,7 @@ and walk_source_dir_map (cxt : walk_cxt) (input : Ext_json_types.t String_map.t)
488489
let file_array = Sys.readdir working_dir in
489490
(* Format.fprintf Format.err_formatter
490491
"@[Walking %s@]@." working_dir; *)
491-
file_array |> Array.iter begin fun file ->
492+
Ext_array.iter file_array begin fun file ->
492493
if Ext_string.ends_with file Literals.suffix_re_js then
493494
Sys.remove (Filename.concat working_dir file)
494495
end;
@@ -498,7 +499,7 @@ and walk_source_dir_map (cxt : walk_cxt) (input : Ext_json_types.t String_map.t)
498499
match sub_dirs_field, cxt_traverse with
499500
| None, true
500501
| Some(True _), _ ->
501-
file_array |> Array.iter begin fun f ->
502+
Ext_array.iter file_array begin fun f ->
502503
if Sys.is_directory (Filename.concat working_dir f ) then
503504
walk_source_dir_map
504505
{cxt with
@@ -512,18 +513,19 @@ and walk_source_dir_map (cxt : walk_cxt) (input : Ext_json_types.t String_map.t)
512513
| Some (False _), _ -> ()
513514
| Some s, _ -> walk_sources cxt s
514515

516+
(* It makes use of the side effect when [walk_sources], removing suffix_re_js,
517+
TODO: make it configurable
518+
*)
515519
let clean_re_js root =
516520
match Ext_json_parse.parse_json_from_file
517521
(Filename.concat root Literals.bsconfig_json) with
518522
| Obj {map ; loc} ->
519-
begin match String_map.find_opt Bsb_build_schemas.sources map with
523+
(match String_map.find_opt Bsb_build_schemas.sources map with
520524
| Some config ->
521-
(try
522-
walk_sources
523-
{ root ; traverse = true; cwd = Filename.current_dir_name} config
524-
with _ -> ())
525-
| None -> ()
526-
end
525+
Ext_pervasives.try_it (fun () ->
526+
walk_sources { root ; traverse = true; cwd = Filename.current_dir_name} config
527+
)
528+
| None -> ())
527529
| _ -> ()
528530
| exception _ -> ()
529531

jscomp/core/cmjdump_main.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ let pp_cmj fmt
6464
k
6565
(not non_saved)
6666
(fun fmt xs ->
67-
Array.iter (fun arity -> p fmt "@[%a@]@ ;" Lam_arity.print arity )
68-
xs) xs
67+
Ext_array.iter xs (fun arity -> p fmt "@[%a@]@ ;" Lam_arity.print arity )
68+
) xs
6969

7070
)) values
7171

jscomp/ext/ext_array.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,7 @@ let map a f =
251251
done;
252252
r
253253
end
254+
255+
let iter a f =
256+
let open Array in
257+
for i = 0 to length a - 1 do f(unsafe_get a i) done

jscomp/ext/ext_array.mli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ val for_all2_no_exn :
8383
val map :
8484
'a array ->
8585
('a -> 'b) ->
86-
'b array
86+
'b array
87+
88+
val iter :
89+
'a array ->
90+
('a -> unit) ->
91+
unit

jscomp/ext/ext_pervasives.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ let finally v action f =
3636
reraise e
3737
| e -> action v ; e
3838

39+
let try_it f =
40+
try f () with _ -> ()
41+
3942
let with_file_as_chan filename f =
4043
finally (open_out_bin filename) close_out f
4144

jscomp/ext/ext_pervasives.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ external reraise: exn -> 'a = "%reraise"
3636

3737
val finally : 'a -> ('a -> 'c) -> ('a -> 'b) -> 'b
3838

39+
val try_it : (unit -> unit) -> unit
40+
3941
val with_file_as_chan : string -> (out_channel -> 'a) -> 'a
4042

4143
val with_file_as_pp : string -> (Format.formatter -> 'a) -> 'a

jscomp/ext/hash_set_gen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ let stats h =
109109
let mbl =
110110
Array.fold_left (fun m b -> max m (List.length b)) 0 h.data in
111111
let histo = Array.make (mbl + 1) 0 in
112-
Array.iter
112+
Ext_array.iter h.data
113113
(fun b ->
114114
let l = List.length b in
115115
histo.(l) <- histo.(l) + 1)
116-
h.data;
116+
;
117117
{Hashtbl.num_bindings = h.size;
118118
num_buckets = Array.length h.data;
119119
max_bucket_length = mbl;

jscomp/ext/hashtbl_gen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ let stats h =
135135
let mbl =
136136
Array.fold_left (fun m b -> max m (bucket_length 0 b)) 0 h.data in
137137
let histo = Array.make (mbl + 1) 0 in
138-
Array.iter
138+
Ext_array.iter h.data
139139
(fun b ->
140140
let l = bucket_length 0 b in
141141
histo.(l) <- histo.(l) + 1)
142-
h.data;
142+
;
143143
{Hashtbl.
144144
num_bindings = h.size;
145145
num_buckets = Array.length h.data;

0 commit comments

Comments
 (0)