Skip to content

Commit ffb6e9a

Browse files
DZakhcristianoc
authored andcommitted
Remove unused non-bs code
1 parent b90ad1e commit ffb6e9a

11 files changed

+19
-173
lines changed

jscomp/ext/config.ml

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ let standard_library =
77

88
let standard_library_default = standard_library
99

10-
let bs_only = ref true
11-
1210
let unsafe_empty_array = ref false
1311

1412
let cmi_magic_number = "Caml1999I022"

jscomp/ext/config.mli

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ val version : string
2121
val standard_library : string
2222
(* The directory containing the standard libraries *)
2323

24-
val bs_only : bool ref
25-
2624
val unsafe_empty_array : bool ref
2725

2826
val load_path : string list ref

jscomp/ml/cmt_format.ml

+1-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ open Cmi_format
174174

175175
let save_cmt filename modname binary_annots sourcefile initial_env cmi =
176176
if !Clflags.binary_annotations then begin
177-
(if !Config.bs_only then Misc.output_to_bin_file_directly else
178-
Misc.output_to_file_via_temporary
179-
~mode:[Open_binary] ) filename
177+
Misc.output_to_bin_file_directly filename
180178
(fun temp_file_name oc ->
181179
let this_crc =
182180
match cmi with

jscomp/ml/ctype.ml

-11
Original file line numberDiff line numberDiff line change
@@ -2534,16 +2534,6 @@ and unify_row env row1 row2 =
25342534
let rm1 = row_more row1 and rm2 = row_more row2 in
25352535
if unify_eq rm1 rm2 then () else
25362536
let r1, r2, pairs = merge_row_fields row1.row_fields row2.row_fields in
2537-
if not !Config.bs_only && (r1 <> [] && r2 <> []) then begin
2538-
(* pairs are the intersection, r1 , r2 should be disjoint *)
2539-
let ht = Hashtbl.create (List.length r1) in
2540-
List.iter (fun (l,_) -> Hashtbl.add ht (hash_variant l) l) r1;
2541-
List.iter
2542-
(fun (l,_) ->
2543-
try raise (Tags(l, Hashtbl.find ht (hash_variant l)))
2544-
with Not_found -> ())
2545-
r2
2546-
end;
25472537
let fixed1 = row_fixed row1 and fixed2 = row_fixed row2 in
25482538
let more =
25492539
if fixed1 then rm1 else
@@ -3712,7 +3702,6 @@ let rec subtype_rec env trace t1 t2 cstrs =
37123702
(trace, t1, t2, !univar_pairs)::cstrs
37133703
end
37143704
| Tvariant v, _ when
3715-
!Config.bs_only &&
37163705
!variant_is_subtype env (row_repr v) t2
37173706
->
37183707
cstrs

jscomp/ml/env.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ and lookup_module ~load ?loc lid env : Path.t =
11171117
(* see #5965 *)
11181118
raise Recmodule
11191119
| Mty_alias (_, Path.Pident id) ->
1120-
if !Config.bs_only && not !Clflags.transparent_modules && Ident.persistent id then
1120+
if not !Clflags.transparent_modules && Ident.persistent id then
11211121
find_pers_struct (Ident.name id) |> ignore
11221122
| _ -> ()
11231123
end;

jscomp/ml/matching.ml

+10-88
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,6 @@ let make_constr_matching p def ctx = function
13351335
(arg, Alias) :: argl
13361336
else match cstr.cstr_tag with
13371337
| Cstr_block _ when
1338-
!Config.bs_only &&
13391338
Datarepr.constructor_has_optional_shape cstr
13401339
->
13411340
begin
@@ -2280,7 +2279,6 @@ let split_extension_cases tag_lambda_list =
22802279
| (cstr, act) :: rem ->
22812280
let (consts, nonconsts) = split_rec rem in
22822281
match cstr with
2283-
Cstr_extension(path, true) when not !Config.bs_only -> ((path, act) :: consts, nonconsts)
22842282
| Cstr_extension(path, _) -> (consts, (path, act) :: nonconsts)
22852283
| _ -> assert false in
22862284
split_rec tag_lambda_list
@@ -2309,17 +2307,13 @@ let combine_constructor sw_names loc arg ex_pat cstr partial ctx def
23092307
match nonconsts with
23102308
[] -> default
23112309
| _ ->
2312-
let tag = Ident.create "tag" in
2313-
let tests =
2314-
List.fold_right
2315-
(fun (path, act) rem ->
2316-
let ext = transl_extension_path ex_pat.pat_env path in
2317-
Lifthenelse(Lprim(extension_slot_eq , [Lvar tag; ext], loc),
2318-
act, rem))
2319-
nonconsts
2320-
default
2321-
in
2322-
Llet(Alias, Pgenval,tag, arg, tests)
2310+
List.fold_right
2311+
(fun (path, act) rem ->
2312+
let ext = transl_extension_path ex_pat.pat_env path in
2313+
Lifthenelse(Lprim(extension_slot_eq , [arg; ext], loc),
2314+
act, rem))
2315+
nonconsts
2316+
default
23232317
in
23242318
List.fold_right
23252319
(fun (path, act) rem ->
@@ -2355,7 +2349,7 @@ let combine_constructor sw_names loc arg ex_pat cstr partial ctx def
23552349
(* Typically, match on lists, will avoid isint primitive in that
23562350
case *)
23572351
let arg =
2358-
if !Config.bs_only && Datarepr.constructor_has_optional_shape cstr then
2352+
if Datarepr.constructor_has_optional_shape cstr then
23592353
Lprim(is_not_none_bs_primitve , [arg], loc)
23602354
else arg
23612355
in
@@ -2452,10 +2446,7 @@ let combine_variant names loc row arg partial ctx def
24522446
else
24532447
num_constr := max_int;
24542448
let test_int_or_block arg if_int if_block =
2455-
if !Config.bs_only then
2456-
Lifthenelse(Lprim (Pccall(Primitive.simple ~name:"#is_poly_var_block" ~arity:1 ~alloc:false), [arg], loc), if_block, if_int)
2457-
else
2458-
Lifthenelse(Lprim (Pisint, [arg], loc), if_int, if_block) in
2449+
Lifthenelse(Lprim (Pccall(Primitive.simple ~name:"#is_poly_var_block" ~arity:1 ~alloc:false), [arg], loc), if_block, if_int) in
24592450
let sig_complete = List.length tag_lambda_list = !num_constr
24602451
and one_action = same_actions tag_lambda_list in (* reduandant work under bs context *)
24612452
let fail, local_jumps =
@@ -3001,67 +2992,6 @@ let simple_for_let loc param pat body =
30012992
catch/exit.
30022993
*)
30032994

3004-
let rec map_return f = function
3005-
| Llet (str, k, id, l1, l2) -> Llet (str, k, id, l1, map_return f l2)
3006-
| Lletrec (l1, l2) -> Lletrec (l1, map_return f l2)
3007-
| Lifthenelse (lcond, lthen, lelse) ->
3008-
Lifthenelse (lcond, map_return f lthen, map_return f lelse)
3009-
| Lsequence (l1, l2) -> Lsequence (l1, map_return f l2)
3010-
| Ltrywith (l1, id, l2) -> Ltrywith (map_return f l1, id, map_return f l2)
3011-
| Lstaticcatch (l1, b, l2) ->
3012-
Lstaticcatch (map_return f l1, b, map_return f l2)
3013-
| Lstaticraise _ | Lprim(Praise _, _, _) as l -> l
3014-
| l -> f l
3015-
3016-
(* The 'opt' reference indicates if the optimization is worthy.
3017-
3018-
It is shared by the different calls to 'assign_pat' performed from
3019-
'map_return'. For example with the code
3020-
let (x, y) = if foo then z else (1,2)
3021-
the else-branch will activate the optimization for both branches.
3022-
3023-
That means that the optimization is activated if *there exists* an
3024-
interesting tuple in one hole of the let-rhs context. We could
3025-
choose to activate it only if *all* holes are interesting. We made
3026-
that choice because being optimistic is extremely cheap (one static
3027-
exit/catch overhead in the "wrong cases"), while being pessimistic
3028-
can be costly (one unnecessary tuple allocation).
3029-
*)
3030-
3031-
let assign_pat opt nraise catch_ids loc pat lam =
3032-
let rec collect acc pat lam = match pat.pat_desc, lam with
3033-
| Tpat_tuple patl, Lprim(Pmakeblock _, lams, _) ->
3034-
opt := true;
3035-
List.fold_left2 collect acc patl lams
3036-
| Tpat_tuple patl, Lconst(Const_block( _, scl)) ->
3037-
opt := true;
3038-
let collect_const acc pat sc = collect acc pat (Lconst sc) in
3039-
List.fold_left2 collect_const acc patl scl
3040-
| _ ->
3041-
(* pattern idents will be bound in staticcatch (let body), so we
3042-
refresh them here to guarantee binders uniqueness *)
3043-
let pat_ids = pat_bound_idents pat in
3044-
let fresh_ids = List.map (fun id -> id, Ident.rename id) pat_ids in
3045-
(fresh_ids, alpha_pat fresh_ids pat, lam) :: acc
3046-
in
3047-
3048-
(* sublets were accumulated by 'collect' with the leftmost tuple
3049-
pattern at the bottom of the list; to respect right-to-left
3050-
evaluation order for tuples, we must evaluate sublets
3051-
top-to-bottom. To preserve tail-rec, we will fold_left the
3052-
reversed list. *)
3053-
let rev_sublets = List.rev (collect [] pat lam) in
3054-
let exit =
3055-
(* build an Ident.tbl to avoid quadratic refreshing costs *)
3056-
let add t (id, fresh_id) = Ident.add id fresh_id t in
3057-
let add_ids acc (ids, _pat, _lam) = List.fold_left add acc ids in
3058-
let tbl = List.fold_left add_ids Ident.empty rev_sublets in
3059-
let fresh_var id = Lvar (Ident.find_same id tbl) in
3060-
Lstaticraise(nraise, List.map fresh_var catch_ids)
3061-
in
3062-
let push_sublet code (_ids, pat, lam) = simple_for_let loc lam pat code in
3063-
List.fold_left push_sublet exit rev_sublets
3064-
30652995
let for_let loc param pat body =
30662996
match pat.pat_desc with
30672997
| Tpat_any ->
@@ -3072,15 +3002,7 @@ let for_let loc param pat body =
30723002
(* fast path, and keep track of simple bindings to unboxable numbers *)
30733003
Llet(Strict, Pgenval, id, param, body)
30743004
| _ ->
3075-
(* Turn off such optimization to reduce diff in the beginning - FIXME*)
3076-
if !Config.bs_only then simple_for_let loc param pat body
3077-
else
3078-
let opt = ref false in
3079-
let nraise = next_raise_count () in
3080-
let catch_ids = pat_bound_idents pat in
3081-
let bind = map_return (assign_pat opt nraise catch_ids loc pat) param in
3082-
if !opt then Lstaticcatch(bind, (nraise, catch_ids), body)
3083-
else simple_for_let loc param pat body
3005+
simple_for_let loc param pat body
30843006

30853007
(* Handling of tupled functions and matchings *)
30863008

jscomp/ml/predef.ml

-12
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,6 @@ and ident_assert_failure = ident_create_predef_exn "Assert_failure"
140140
and ident_undefined_recursive_module =
141141
ident_create_predef_exn "Undefined_recursive_module"
142142

143-
let all_predef_exns = [
144-
ident_match_failure;
145-
ident_invalid_argument;
146-
ident_failure;
147-
ident_js_error;
148-
ident_not_found;
149-
ident_end_of_file;
150-
ident_division_by_zero;
151-
ident_assert_failure;
152-
ident_undefined_recursive_module;
153-
]
154-
155143
let path_match_failure = Pident ident_match_failure
156144
and path_assert_failure = Pident ident_assert_failure
157145
and path_undefined_recursive_module = Pident ident_undefined_recursive_module

jscomp/ml/predef.mli

-7
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ val build_initial_env:
7777
val builtin_values: (string * Ident.t) list
7878
val builtin_idents: (string * Ident.t) list
7979

80-
(** All predefined exceptions, exposed as [Ident.t] for flambda (for
81-
building value approximations).
82-
The [Ident.t] for division by zero is also exported explicitly
83-
so flambda can generate code to raise it. *)
84-
val ident_division_by_zero: Ident.t
85-
val all_predef_exns : Ident.t list
86-
8780
type test =
8881
| For_sure_yes
8982
| For_sure_no

jscomp/ml/switch.ml

+5-27
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,8 @@ and enum top cases =
560560
do_make_if_out
561561
(Arg.make_const d) ctx.arg (mk_ifso ctx) (mk_ifno ctx)
562562
| _ ->
563-
if (*true || *)!Config.bs_only then
564-
do_make_if_out
565-
(Arg.make_const d) (Arg.make_offset ctx.arg (-l)) (mk_ifso ctx) (mk_ifno ctx) else
566-
Arg.bind
567-
(Arg.make_offset ctx.arg (-l))
568-
(fun arg ->
569-
let ctx = {off= (-l+ctx.off) ; arg=arg} in
570-
do_make_if_out
571-
(Arg.make_const d) arg (mk_ifso ctx) (mk_ifno ctx))
563+
do_make_if_out
564+
(Arg.make_const d) (Arg.make_offset ctx.arg (-l)) (mk_ifso ctx) (mk_ifno ctx)
572565

573566
let do_make_if_in h arg ifso ifno =
574567
Arg.make_if (Arg.make_isin h arg) ifso ifno
@@ -578,15 +571,8 @@ and enum top cases =
578571
do_make_if_in
579572
(Arg.make_const d) ctx.arg (mk_ifso ctx) (mk_ifno ctx)
580573
| _ ->
581-
if (*true || *) !Config.bs_only then
582-
do_make_if_in
583-
(Arg.make_const d) (Arg.make_offset ctx.arg (-l)) (mk_ifso ctx) (mk_ifno ctx) else
584-
Arg.bind
585-
(Arg.make_offset ctx.arg (-l))
586-
(fun arg ->
587-
let ctx = {off= (-l+ctx.off) ; arg=arg} in
588-
do_make_if_in
589-
(Arg.make_const d) arg (mk_ifso ctx) (mk_ifno ctx))
574+
do_make_if_in
575+
(Arg.make_const d) (Arg.make_offset ctx.arg (-l)) (mk_ifso ctx) (mk_ifno ctx)
590576

591577
let rec c_test ctx ({cases=cases ; actions=actions} as s) =
592578
let lcases = Array.length cases in
@@ -756,15 +742,7 @@ let make_switch loc {cases=cases ; actions=actions} i j sw_names =
756742
(fun act i -> acts.(i) <- actions.(act))
757743
t ;
758744
(fun ctx ->
759-
if !Config.bs_only then
760-
Arg.make_switch ~offset:(ll+ctx.off) loc ctx.arg tbl acts sw_names
761-
else
762-
match -ll-ctx.off with
763-
| 0 -> Arg.make_switch loc ctx.arg tbl acts sw_names ~offset:0
764-
| _ ->
765-
Arg.bind
766-
(Arg.make_offset ctx.arg (-ll-ctx.off))
767-
(fun arg -> Arg.make_switch loc arg tbl acts sw_names ~offset:0))
745+
Arg.make_switch ~offset:(ll+ctx.off) loc ctx.arg tbl acts sw_names)
768746

769747

770748
let make_clusters loc ({cases=cases ; actions=actions} as s) n_clusters k sw_names =

jscomp/ml/typedecl.ml

+2-11
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,9 @@ let make_params env params =
208208
List.map make_param params
209209

210210
let transl_labels ?record_name env closed lbls =
211-
if !Config.bs_only then
212-
match !Builtin_attributes.check_duplicated_labels lbls with
211+
(match !Builtin_attributes.check_duplicated_labels lbls with
213212
| None -> ()
214-
| Some {loc;txt=name} -> raise (Error(loc,Duplicate_label (name, record_name)))
215-
else (
216-
let all_labels = ref StringSet.empty in
217-
List.iter
218-
(fun {pld_name = {txt=name; loc}} ->
219-
if StringSet.mem name !all_labels then
220-
raise(Error(loc, Duplicate_label (name, record_name)));
221-
all_labels := StringSet.add name !all_labels)
222-
lbls);
213+
| Some {loc;txt=name} -> raise (Error(loc,Duplicate_label (name, record_name))));
223214
let mk {pld_name=name;pld_mutable=mut;pld_type=arg;pld_loc=loc;
224215
pld_attributes=attrs} =
225216
Builtin_attributes.warning_scope attrs

jscomp/ml/typetexp.ml

-9
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,7 @@ and transl_type_aux env policy styp =
411411
row_bound=(); row_closed=true;
412412
row_fixed=false; row_name=None}) in
413413
let hfields = Hashtbl.create 17 in
414-
let collection_detect = Hashtbl.create 17 in
415414
let add_typed_field loc l f =
416-
if not !Config.bs_only then begin
417-
let h = Btype.hash_variant l in
418-
if Hashtbl.mem collection_detect h then
419-
let l' = Hashtbl.find collection_detect h in
420-
(* Check for tag conflicts *)
421-
if l <> l' then raise(Error(styp.ptyp_loc, env, Variant_tags(l, l')));
422-
else Hashtbl.add collection_detect h l
423-
end ;
424415
try
425416
let (_,f') = Hashtbl.find hfields l in
426417
let ty = mkfield l f and ty' = mkfield l f' in

0 commit comments

Comments
 (0)