Skip to content

Commit fbb3a5c

Browse files
committed
Remove @return(undefined_to_opt) and %undefined_to_opt primitive
1 parent 060edd5 commit fbb3a5c

40 files changed

+61
-131
lines changed

compiler/core/lam.ml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ let rec apply ?(ap_transformed_jsx = false) fn args (ap_info : ap_info) : t =
298298
Lprim
299299
{
300300
primitive =
301-
( Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt
302-
| Pis_null | Pis_null_undefined | Ptypeof ) as wrap;
301+
( Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
302+
| Pis_null_undefined | Ptypeof ) as wrap;
303303
args =
304304
[Lprim ({primitive = _; args = inner_args} as primitive_call)];
305305
};
@@ -442,11 +442,7 @@ let rec seq (a : t) b : t =
442442
match a with
443443
| Lprim {primitive = Pmakeblock _; args = x :: xs} ->
444444
seq (Ext_list.fold_left xs x seq) b
445-
| Lprim
446-
{
447-
primitive = Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt;
448-
args = [a];
449-
} ->
445+
| Lprim {primitive = Pnull_to_opt | Pnull_undefined_to_opt; args = [a]} ->
450446
seq a b
451447
| _ -> Lsequence (a, b)
452448

@@ -719,8 +715,6 @@ let result_wrap loc (result_type : External_ffi_types.return_wrapper) result =
719715
| Return_null_to_opt -> prim ~primitive:Pnull_to_opt ~args:[result] loc
720716
| Return_null_undefined_to_opt ->
721717
prim ~primitive:Pnull_undefined_to_opt ~args:[result] loc
722-
| Return_undefined_to_opt ->
723-
prim ~primitive:Pundefined_to_opt ~args:[result] loc
724718
| Return_unset | Return_identity -> result
725719

726720
let handle_bs_non_obj_ffi ?(transformed_jsx = false)

compiler/core/lam_analysis.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ let rec no_side_effects (lam : Lam.t) : bool =
4646
| _ -> false)
4747
| Pcreate_extension _ | Ptypeof | Pis_null | Pis_not_none | Psome
4848
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pnull_to_opt
49-
| Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _
50-
| Pjs_fn_make_unit | Pjs_object_create _ | Pimport
49+
| Pnull_undefined_to_opt | Pjs_fn_make _ | Pjs_fn_make_unit
50+
| Pjs_object_create _ | Pimport
5151
(* TODO: check *)
5252
| Pmakeblock _
5353
(* whether it's mutable or not *)

compiler/core/lam_compile_primitive.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
9595
| Var _ | Undefined _ | Null -> Js_of_lam_option.null_to_opt e
9696
| _ -> E.runtime_call Primitive_modules.option "fromNull" args)
9797
| _ -> assert false)
98-
| Pundefined_to_opt -> (
99-
match args with
100-
| [e] -> (
101-
match e.expression_desc with
102-
| Var _ | Undefined _ | Null -> Js_of_lam_option.undef_to_opt e
103-
| _ -> E.runtime_call Primitive_modules.option "fromUndefined" args)
104-
| _ -> assert false)
10598
| Pnull_undefined_to_opt -> (
10699
match args with
107100
| [e] -> (

compiler/core/lam_convert.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
197197
| Pisnullable -> prim ~primitive:Pis_null_undefined ~args loc
198198
| Pnull_to_opt -> prim ~primitive:Pnull_to_opt ~args loc
199199
| Pnullable_to_opt -> prim ~primitive:Pnull_undefined_to_opt ~args loc
200-
| Pundefined_to_opt -> prim ~primitive:Pundefined_to_opt ~args loc
201200
| Pis_not_none -> prim ~primitive:Pis_not_none ~args loc
202201
| Pval_from_option -> prim ~primitive:Pval_from_option ~args loc
203202
| Pval_from_option_not_nest ->

compiler/core/lam_pass_collect.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ let collect_info (meta : Lam_stats.t) (lam : Lam.t) =
7373
(FunctionId {arity = Lam_arity.info [arity] false; lambda = None})
7474
| Lprim {primitive = Pnull_to_opt; args = [(Lvar _ as l)]; _} ->
7575
Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Null))
76-
| Lprim {primitive = Pundefined_to_opt; args = [(Lvar _ as l)]; _} ->
77-
Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Undefined))
7876
| Lprim {primitive = Pnull_undefined_to_opt; args = [(Lvar _ as l)]} ->
7977
Hash_ident.replace meta.ident_tbl ident
8078
(OptionalBlock (l, Null_undefined))

compiler/core/lam_pass_deep_flatten.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ let deep_flatten (lam : Lam.t) : Lam.t =
123123
id,
124124
(Lprim
125125
{
126-
primitive =
127-
Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt;
126+
primitive = Pnull_to_opt | Pnull_undefined_to_opt;
128127
args = [Lvar _];
129128
} as arg),
130129
body ) ->
@@ -134,9 +133,7 @@ let deep_flatten (lam : Lam.t) : Lam.t =
134133
id,
135134
Lprim
136135
{
137-
primitive =
138-
(Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt) as
139-
primitive;
136+
primitive = (Pnull_to_opt | Pnull_undefined_to_opt) as primitive;
140137
args = [arg];
141138
},
142139
body ) ->

compiler/core/lam_primitive.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ type t =
161161
play safe first
162162
*)
163163
| Pjs_fn_method
164-
| Pundefined_to_opt
165164
| Pnull_to_opt
166165
| Pnull_undefined_to_opt
167166
| Pis_null
@@ -224,12 +223,12 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
224223
| Pawait
225224
(* etc *)
226225
| Pjs_apply | Pjs_runtime_apply | Pval_from_option | Pval_from_option_not_nest
227-
| Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
228-
| Pis_not_none | Psome | Psome_not_nest | Pis_undefined | Pis_null_undefined
229-
| Pimport | Ptypeof | Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod
230-
| Pupdate_mod | Pduprecord | Pmakearray | Parraylength | Parrayrefu
231-
| Parraysetu | Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method
232-
| Phash | Phash_mixstring | Phash_mixint | Phash_finalmix ->
226+
| Pnull_to_opt | Pnull_undefined_to_opt | Pis_null | Pis_not_none | Psome
227+
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pimport | Ptypeof
228+
| Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod | Pupdate_mod
229+
| Pduprecord | Pmakearray | Parraylength | Parrayrefu | Parraysetu
230+
| Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method | Phash
231+
| Phash_mixstring | Phash_mixint | Phash_finalmix ->
233232
rhs = lhs
234233
| Pcreate_extension a -> (
235234
match rhs with

compiler/core/lam_primitive.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ type t =
152152
| Pjs_fn_make of int
153153
| Pjs_fn_make_unit
154154
| Pjs_fn_method
155-
| Pundefined_to_opt
156155
| Pnull_to_opt
157156
| Pnull_undefined_to_opt
158157
| Pis_null

compiler/core/lam_print.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ let primitive ppf (prim : Lam_primitive.t) =
6161
| Praw_js_code _ -> fprintf ppf "[raw]"
6262
| Ptypeof -> fprintf ppf "typeof"
6363
| Pnull_to_opt -> fprintf ppf "[null->opt]"
64-
| Pundefined_to_opt -> fprintf ppf "[undefined->opt]"
6564
| Pnull_undefined_to_opt -> fprintf ppf "[null/undefined->opt]"
6665
| Pis_null -> fprintf ppf "[?null]"
6766
| Pis_not_none -> fprintf ppf "[?is-not-none]"

compiler/frontend/ast_attributes.ml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,24 +279,6 @@ let set : attr = ({txt = "set"; loc = locg}, Ast_payload.empty)
279279
let internal_expansive : attr =
280280
({txt = "internal.expansive"; loc = locg}, Ast_payload.empty)
281281

282-
let bs_return_undefined : attr =
283-
( {txt = "return"; loc = locg},
284-
PStr
285-
[
286-
{
287-
pstr_desc =
288-
Pstr_eval
289-
( {
290-
pexp_desc =
291-
Pexp_ident {txt = Lident "undefined_to_opt"; loc = locg};
292-
pexp_loc = locg;
293-
pexp_attributes = [];
294-
},
295-
[] );
296-
pstr_loc = locg;
297-
};
298-
] )
299-
300282
let is_gentype (attr : attr) =
301283
match attr with
302284
| {Location.txt = "genType" | "gentype"; _}, _ -> true

0 commit comments

Comments
 (0)