Skip to content

Commit 05a168a

Browse files
committed
Apply changes accordingly
Check the output of ocamlobjinfo bsb_helper.cmx make sure unused dependency not pulled in
1 parent 12080f2 commit 05a168a

Some content is hidden

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

46 files changed

+27387
-28255
lines changed

jscomp/bsb/bsb_ninja_file_groups.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let handle_generators oc
3737
Ext_list.iter group.generators (fun {output; input; command} ->
3838
(*TODO: add a loc for better error message *)
3939
match String_map.find_opt custom_rules command with
40-
| None -> Ext_pervasives.failwithf ~loc:__LOC__ "custom rule %s used but not defined" command
40+
| None -> Ext_fmt.failwithf ~loc:__LOC__ "custom rule %s used but not defined" command
4141
| Some rule ->
4242
Bsb_ninja_targets.output_build oc
4343
~outputs:(Ext_list.map output map_to_source_dir)

jscomp/bsb_helper/bsb_db_decode.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ let read_build_cache ~dir : t =
9393
Ext_io.load_file (Filename.concat dir bsbuild_cache) in
9494
decode_internal all_content (ref (Ext_digest.length + 1)), all_content
9595

96-
let cmp (a : string) b = String_map.compare_key a b
96+
(* Invariant: the same as encoding String_map.compare_key *)
97+
let cmp = Ext_string.compare
98+
9799

98100
let rec binarySearchAux (arr : string array) (lo : int) (hi : int) (key : string) : _ option =
99101
let mid = (lo + hi)/2 in
@@ -129,7 +131,7 @@ let find_opt_aux sorted key : _ option =
129131

130132

131133
type module_info = {
132-
case : Bsb_db.case;
134+
case : bool ; (* which is Bsb_db.case*)
133135
dir_name : string
134136
}
135137

jscomp/bsb_helper/bsb_db_decode.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ val read_build_cache :
4848

4949

5050
type module_info = {
51-
case : Bsb_db.case;
51+
case : bool (* Bsb_db.case*);
5252
dir_name : string
5353
}
5454

jscomp/common/js_config.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@
3030
(* let add_npm_package_path s =
3131
match !packages_info with
3232
| Empty ->
33-
Ext_pervasives.bad_argf "please set package name first using -bs-package-name ";
33+
Ext_arg.bad_argf "please set package name first using -bs-package-name ";
3434
| NonBrowser(name, envs) ->
3535
let env, path =
3636
match Ext_string.split ~keep_empty:false s ':' with
3737
| [ package_name; path] ->
3838
(match Js_packages_info.module_system_of_string package_name with
3939
| Some x -> x
4040
| None ->
41-
Ext_pervasives.bad_argf "invalid module system %s" package_name), path
41+
Ext_arg.bad_argf "invalid module system %s" package_name), path
4242
| [path] ->
4343
NodeJS, path
4444
| _ ->
45-
Ext_pervasives.bad_argf "invalid npm package path: %s" s
45+
Ext_arg.bad_argf "invalid npm package path: %s" s
4646
in
4747
packages_info := NonBrowser (name, ((env,path) :: envs)) *)
4848
(** Browser is not set via command line only for internal use *)

jscomp/core/js_cmj_format.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ let digest_length = 16 (*16 chars *)
8888
let verify_magic_in_beg ic =
8989
let buffer = really_input_string ic cmj_magic_number_length in
9090
if buffer <> cmj_magic_number then
91-
Ext_pervasives.failwithf ~loc:__LOC__
91+
Ext_fmt.failwithf ~loc:__LOC__
9292
"cmj files have incompatible versions, please rebuilt using the new compiler : %s"
9393
__LOC__
9494

@@ -116,7 +116,7 @@ let from_string s : t =
116116
if magic_number = cmj_magic_number then
117117
Marshal.from_string s (digest_length + cmj_magic_number_length)
118118
else
119-
Ext_pervasives.failwithf ~loc:__LOC__
119+
Ext_fmt.failwithf ~loc:__LOC__
120120
"cmj files have incompatible versions, please rebuilt using the new compiler : %s"
121121
__LOC__
122122

jscomp/core/js_exp_make.ml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,15 @@ let int32_lsl ?comment (e1 : J.expression) (e2 : J.expression) : J.expression =
11281128
expression_desc = Bin (Lsl, e1,e2)
11291129
}
11301130

1131+
let is_pos_pow n =
1132+
let module M = struct exception E end in
1133+
let rec aux c (n : Int32.t) =
1134+
if n <= 0l then -2
1135+
else if n = 1l then c
1136+
else if Int32.logand n 1l = 0l then
1137+
aux (c + 1) (Int32.shift_right n 1 )
1138+
else raise_notrace M.E in
1139+
try aux 0 n with M.E -> -1
11311140

11321141
let int32_mul ?comment
11331142
(e1 : J.expression)
@@ -1144,7 +1153,7 @@ let int32_mul ?comment
11441153
| e , {expression_desc = Number (Int {i = i0} | Uint i0 ); _}
11451154
| {expression_desc = Number (Int {i = i0} | Uint i0 ); _}, e
11461155
->
1147-
let i = Ext_pervasives.is_pos_pow i0 in
1156+
let i = is_pos_pow i0 in
11481157
if i >= 0 then
11491158
int32_lsl e (small_int i)
11501159
else

jscomp/core/js_packages_info.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,23 @@ let get_output_dir
228228

229229
let add_npm_package_path (packages_info : t) (s : string) : t =
230230
if is_empty packages_info then
231-
Ext_pervasives.bad_argf "please set package name first using -bs-package-name "
231+
Ext_arg.bad_argf "please set package name first using -bs-package-name "
232232
else
233233
let module_system, path =
234234
match Ext_string.split ~keep_empty:false s ':' with
235235
| [ module_system; path] ->
236236
(match module_system_of_string module_system with
237237
| Some x -> x
238238
| None ->
239-
Ext_pervasives.bad_argf "invalid module system %s" module_system), path
239+
Ext_arg.bad_argf "invalid module system %s" module_system), path
240240
| [path] ->
241241
NodeJS, path
242242
| module_system :: path ->
243243
(match module_system_of_string module_system with
244244
| Some x -> x
245-
| None -> Ext_pervasives.bad_argf "invalid module system %s" module_system), (String.concat ":" path)
245+
| None -> Ext_arg.bad_argf "invalid module system %s" module_system), (String.concat ":" path)
246246
| _ ->
247-
Ext_pervasives.bad_argf "invalid npm package path: %s" s
247+
Ext_arg.bad_argf "invalid npm package path: %s" s
248248
in
249249
{ packages_info with module_systems = {module_system; path}::packages_info.module_systems}
250250

jscomp/core/js_packages_state.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let set_package_name name =
3131
if Js_packages_info.is_empty !packages_info then
3232
packages_info := Js_packages_info.from_name name
3333
else
34-
Ext_pervasives.bad_argf "duplicated flag for -bs-package-name"
34+
Ext_arg.bad_argf "duplicated flag for -bs-package-name"
3535

3636
let set_package_map module_name =
3737
(* set_package_name name ;

jscomp/core/lam_compile_main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ let compile
213213
if Js_config.is_same_file () then
214214
let f =
215215
Ext_filename.new_extension !Location.input_name ".lambda" in
216-
Ext_pervasives.with_file_as_pp f begin fun fmt ->
216+
Ext_fmt.with_file_as_pp f begin fun fmt ->
217217
Format.pp_print_list ~pp_sep:Format.pp_print_newline
218218
(Lam_group.pp_group env) fmt (coerced_input.groups)
219219
end;

jscomp/core/lam_convert.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let exception_id_destructed (l : Lam.t) (fv : Ident.t): bool =
6060
| Some a -> hit a
6161
and hit_list_snd : 'a. ('a * _ ) list -> bool = fun x ->
6262
Ext_list.exists_snd x hit
63-
and hit_list xs = List.exists hit xs
63+
and hit_list xs = Ext_list.exists xs hit
6464
and hit (l : Lam.t) =
6565
match l with
6666
| Lprim {primitive = Pintcomp _ ;

jscomp/core/lam_dce.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let transitive_closure
4343
Ident_hash_set.add visited id;
4444
match Ident_hashtbl.find_opt ident_freevars id with
4545
| None ->
46-
Ext_pervasives.failwithf ~loc:__LOC__ "%s/%d not found" (Ident.name id) (id.stamp)
46+
Ext_fmt.failwithf ~loc:__LOC__ "%s/%d not found" (Ident.name id) (id.stamp)
4747
| Some e -> Ident_set.iter e dfs
4848
end in
4949
Ext_list.iter initial_idents dfs;

jscomp/core/lam_hit.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let hit_variables (fv : Ident_set.t) (l : t) : bool =
3434
and hit_var (id : Ident.t) = Ident_set.mem fv id
3535
and hit_list_snd : 'a. ('a * t ) list -> bool = fun x ->
3636
Ext_list.exists_snd x hit
37-
and hit_list xs = List.exists hit xs
37+
and hit_list xs = Ext_list.exists xs hit
3838
and hit (l : t) =
3939
begin
4040
match (l : t) with
@@ -93,7 +93,7 @@ let hit_variable (fv : Ident.t) (l : t) : bool =
9393
and hit_var (id : Ident.t) = Ident.same id fv
9494
and hit_list_snd : 'a. ('a * t ) list -> bool = fun x ->
9595
Ext_list.exists_snd x hit
96-
and hit_list xs = List.exists hit xs
96+
and hit_list xs = Ext_list.exists xs hit
9797
and hit (l : t) =
9898
begin
9999
match (l : t) with

jscomp/core/lam_iter.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ let inner_exists (l : t) (f : t -> bool) : bool =
8484
| Lconst (_ : Lam_constant.t) -> false
8585
| Lapply ({fn; args; loc; status} ) ->
8686
f fn ||
87-
List.exists f args
87+
Ext_list.exists args f
8888
| Lfunction({body; arity; params } ) ->
8989
f body
9090
| Llet(str, id, arg, body) ->
@@ -104,10 +104,10 @@ let inner_exists (l : t) (f : t -> bool) : bool =
104104
Ext_option.exists default f
105105

106106
| Lprim {args; primitive ; loc} ->
107-
List.exists f args;
107+
Ext_list.exists args f;
108108

109109
| Lstaticraise (id,args) ->
110-
List.exists f args;
110+
Ext_list.exists args f;
111111
| Lstaticcatch(e1, vars , e2) ->
112112
f e1 ||
113113
f e2
@@ -125,4 +125,4 @@ let inner_exists (l : t) (f : t -> bool) : bool =
125125
| Lassign(id, e) ->
126126
f e
127127
| Lsend (k, met, obj, args, loc) ->
128-
f met || f obj || List.exists f args
128+
f met || f obj || Ext_list.exists args f

jscomp/core/lam_scc.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let hit_mask ( mask : Hash_set_ident_mask.t) (l : Lam.t) : bool =
3939
and hit_var (id : Ident.t) = Hash_set_ident_mask.mask_check_all_hit id mask
4040
and hit_list_snd : 'a. ('a * Lam.t ) list -> bool = fun x ->
4141
Ext_list.exists_snd x hit
42-
and hit_list xs = List.exists hit xs
42+
and hit_list xs = Ext_list.exists xs hit
4343
and hit (l : Lam.t) =
4444
match l with
4545
| Lvar id -> hit_var id

jscomp/ext/ext_buffer.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ let to_bytes b = Bytes.sub b.buffer 0 b.position
3535

3636
let sub b ofs len =
3737
if ofs < 0 || len < 0 || ofs > b.position - len
38-
then invalid_arg "Buffer.sub"
38+
then invalid_arg "Ext_buffer.sub"
3939
else Bytes.sub_string b.buffer ofs len
4040

4141

4242
let blit src srcoff dst dstoff len =
4343
if len < 0 || srcoff < 0 || srcoff > src.position - len
4444
|| dstoff < 0 || dstoff > (Bytes.length dst) - len
45-
then invalid_arg "Buffer.blit"
45+
then invalid_arg "Ext_buffer.blit"
4646
else
4747
Bytes.unsafe_blit src.buffer srcoff dst dstoff len
4848

@@ -63,7 +63,7 @@ let resize b more =
6363
if !new_len > Sys.max_string_length then begin
6464
if b.position + more <= Sys.max_string_length
6565
then new_len := Sys.max_string_length
66-
else failwith "Buffer.add: cannot grow buffer"
66+
else failwith "Ext_buffer.add: cannot grow buffer"
6767
end;
6868
#end
6969
let new_buffer = Bytes.create !new_len in
@@ -81,7 +81,7 @@ let add_char b c =
8181

8282
let add_substring b s offset len =
8383
if offset < 0 || len < 0 || offset > String.length s - len
84-
then invalid_arg "Buffer.add_substring/add_subbytes";
84+
then invalid_arg "Ext_buffer.add_substring/add_subbytes";
8585
let new_position = b.position + len in
8686
if new_position > b.length then resize b len;
8787
Bytes.blit_string s offset b.buffer b.position len;
@@ -133,7 +133,7 @@ let add_channel b ic len =
133133
|| len > Sys.max_string_length
134134
#end
135135
then (* PR#5004 *)
136-
invalid_arg "Buffer.add_channel";
136+
invalid_arg "Ext_buffer.add_channel";
137137
if b.position + len > b.length then resize b len;
138138
really_input ic b.buffer b.position len;
139139
b.position <- b.position + len

jscomp/ext/ext_js_regex.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let check_from_end al =
3131
if e < 0 || e > 255 then false
3232
else (let c = Char.chr e in
3333
if c = '/' then true
34-
else (if List.exists (fun x -> x = c) seen then false (* flag should not be repeated *)
34+
else (if Ext_list.exists seen (fun x -> x = c) then false (* flag should not be repeated *)
3535
else (if c = 'i' || c = 'g' || c = 'm' || c = 'y' || c ='u' then aux r (c::seen)
3636
else false)))
3737
in aux al []

jscomp/ext/ext_namespace.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ let is_valid_npm_package_name (s : string) =
102102

103103
let namespace_of_package_name (s : string) : string =
104104
let len = String.length s in
105-
let buf = Buffer.create len in
105+
let buf = Ext_buffer.create len in
106106
let add capital ch =
107-
Buffer.add_char buf
107+
Ext_buffer.add_char buf
108108
(if capital then
109109
(Ext_char.uppercase_ascii ch)
110110
else ch) in
@@ -125,4 +125,4 @@ let namespace_of_package_name (s : string) : string =
125125
| _ -> aux capital (off+1) len
126126
in
127127
aux true 0 len ;
128-
Buffer.contents buf
128+
Ext_buffer.contents buf

jscomp/ext/ext_path.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ let rec find_root_filename ~cwd filename =
313313
if String.length cwd' < String.length cwd then
314314
find_root_filename ~cwd:cwd' filename
315315
else
316-
Ext_pervasives.failwithf
316+
Ext_fmt.failwithf
317317
~loc:__LOC__
318318
"%s not found from %s" filename cwd
319319

jscomp/ext/ext_pervasives.ml

+4-26
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,10 @@ let try_it f =
4242
let with_file_as_chan filename f =
4343
finally (open_out_bin filename) ~clean:close_out f
4444

45-
let with_file_as_pp filename f =
46-
finally (open_out_bin filename) ~clean:close_out
47-
(fun chan ->
48-
let fmt = Format.formatter_of_out_channel chan in
49-
let v = f fmt in
50-
Format.pp_print_flush fmt ();
51-
v
52-
)
53-
54-
55-
let is_pos_pow n =
56-
let module M = struct exception E end in
57-
let rec aux c (n : Int32.t) =
58-
if n <= 0l then -2
59-
else if n = 1l then c
60-
else if Int32.logand n 1l = 0l then
61-
aux (c + 1) (Int32.shift_right n 1 )
62-
else raise M.E in
63-
try aux 0 n with M.E -> -1
64-
65-
let failwithf ~loc fmt = Format.ksprintf (fun s -> failwith (loc ^ s))
66-
fmt
67-
68-
let invalid_argf fmt = Format.ksprintf invalid_arg fmt
69-
70-
let bad_argf fmt = Format.ksprintf (fun x -> raise (Arg.Bad x ) ) fmt
45+
46+
47+
48+
7149

7250
external id : 'a -> 'a = "%identity"
7351

jscomp/ext/ext_pervasives.mli

+4-5
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ val try_it : (unit -> 'a) -> unit
4343

4444
val with_file_as_chan : string -> (out_channel -> 'a) -> 'a
4545

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

48-
val is_pos_pow : Int32.t -> int
4947

50-
val failwithf : loc:string -> ('a, unit, string, 'b) format4 -> 'a
5148

52-
val invalid_argf : ('a, unit, string, 'b) format4 -> 'a
5349

54-
val bad_argf : ('a, unit, string, 'b) format4 -> 'a
50+
51+
52+
53+
5554

5655

5756

jscomp/ext/ext_string.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ let check_suffix_case = ends_with
116116
let check_suffix_case_then_chop = ends_with_then_chop
117117

118118
let check_any_suffix_case s suffixes =
119-
List.exists (fun x -> check_suffix_case s x) suffixes
119+
Ext_list.exists suffixes (fun x -> check_suffix_case s x)
120120

121121
let check_any_suffix_case_then_chop s suffixes =
122122
let rec aux suffixes =
@@ -260,8 +260,7 @@ let rec index_rec_count s lim i c count =
260260
let index_count s i c count =
261261
let lim = String.length s in
262262
if i < 0 || i >= lim || count < 1 then
263-
Ext_pervasives.invalid_argf "index_count: (%d,%d)" i count;
264-
263+
invalid_arg ("index_count: ( " ^string_of_int i ^ "," ^string_of_int count ^ ")" );
265264
index_rec_count s lim i c count
266265

267266
(* let index_next s i c =

0 commit comments

Comments
 (0)