Skip to content

Commit 2eddf54

Browse files
committed
Remove @return(undefined_to_opt) and %undefined_to_opt primitive
1 parent bece9c7 commit 2eddf54

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
@@ -220,7 +220,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
220220
| Pisnullable -> prim ~primitive:Pis_null_undefined ~args loc
221221
| Pnull_to_opt -> prim ~primitive:Pnull_to_opt ~args loc
222222
| Pnullable_to_opt -> prim ~primitive:Pnull_undefined_to_opt ~args loc
223-
| Pundefined_to_opt -> prim ~primitive:Pundefined_to_opt ~args loc
224223
| Pis_not_none -> prim ~primitive:Pis_not_none ~args loc
225224
| Pval_from_option -> prim ~primitive:Pval_from_option ~args loc
226225
| 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

compiler/frontend/ast_attributes.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ val get_index : attr
5959

6060
val set : attr
6161

62-
val bs_return_undefined : attr
63-
6462
val internal_expansive : attr
6563
(* val deprecated : string -> attr *)
6664

compiler/frontend/ast_derive_abstract.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ let is_abstract (xs : Ast_payload.action list) =
5454
(** For this attributes, its type was wrapped as an option,
5555
so we can still reuse existing frame work
5656
*)
57-
let get_optional_attrs =
58-
[Ast_attributes.get; Ast_attributes.bs_return_undefined]
57+
let get_optional_attrs = [Ast_attributes.get]
5958

6059
let get_attrs = []
6160

compiler/frontend/ast_external_process.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ let init_st =
190190

191191
let return_wrapper loc (txt : string) : External_ffi_types.return_wrapper =
192192
match txt with
193-
| "undefined_to_opt" -> Return_undefined_to_opt
194193
| "null_to_opt" -> Return_null_to_opt
195194
| "nullable" | "null_undefined_to_opt" -> Return_null_undefined_to_opt
196195
| "identity" -> Return_identity
@@ -407,8 +406,7 @@ let check_return_wrapper loc (wrapper : External_ffi_types.return_wrapper)
407406
| Return_unset ->
408407
if Ast_core_type.is_unit result_type then Return_replaced_with_unit
409408
else wrapper
410-
| Return_undefined_to_opt | Return_null_to_opt | Return_null_undefined_to_opt
411-
->
409+
| Return_null_to_opt | Return_null_undefined_to_opt ->
412410
if Ast_core_type.is_user_option result_type then wrapper
413411
else Bs_syntaxerr.err loc Expect_opt_in_bs_return_to_opt
414412
| Return_replaced_with_unit -> assert false

compiler/frontend/external_ffi_types.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ type external_spec =
9898
type return_wrapper =
9999
| Return_unset
100100
| Return_identity
101-
| Return_undefined_to_opt
102101
| Return_null_to_opt
103102
| Return_null_undefined_to_opt
104103
| Return_replaced_with_unit

compiler/frontend/external_ffi_types.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ type external_spec =
7474
type return_wrapper =
7575
| Return_unset
7676
| Return_identity
77-
| Return_undefined_to_opt
7877
| Return_null_to_opt
7978
| Return_null_undefined_to_opt
8079
| Return_replaced_with_unit

compiler/ml/lambda.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ type primitive =
298298
(* js *)
299299
| Pcurry_apply of int
300300
| Pjscomp of comparison
301-
| Pundefined_to_opt
302301
| Pnull_to_opt
303302
| Pnullable_to_opt
304303
| Pis_not_none

compiler/ml/lambda.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ type primitive =
265265
(* js *)
266266
| Pcurry_apply of int
267267
| Pjscomp of comparison
268-
| Pundefined_to_opt
269268
| Pnull_to_opt
270269
| Pnullable_to_opt
271270
| Pis_not_none

compiler/ml/printlambda.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ let primitive ppf = function
253253
| Pjscomp Cle -> fprintf ppf "<="
254254
| Pjscomp Cgt -> fprintf ppf ">"
255255
| Pjscomp Cge -> fprintf ppf ">="
256-
| Pundefined_to_opt -> fprintf ppf "undefined_to_opt"
257256
| Pnull_to_opt -> fprintf ppf "null_to_opt"
258257
| Pnullable_to_opt -> fprintf ppf "nullable_to_opt"
259258
| Pis_not_none -> fprintf ppf "#is_not_none"

compiler/ml/translcore.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ let primitives_table =
372372
("%null", Pnull);
373373
("%undefined", Pundefined);
374374
("%is_nullable", Pisnullable);
375-
("%undefined_to_opt", Pundefined_to_opt);
376375
("%null_to_opt", Pnull_to_opt);
377376
("%nullable_to_opt", Pnullable_to_opt);
378377
("%function_arity", Pfn_arity);
@@ -397,7 +396,6 @@ let primitives_table =
397396
("#is_nullable", Pisnullable);
398397
("#null_to_opt", Pnull_to_opt);
399398
("#nullable_to_opt", Pnullable_to_opt);
400-
("#undefined_to_opt", Pundefined_to_opt);
401399
("#makemutablelist", Pmakelist Mutable);
402400
("#import", Pimport);
403401
(* FIXME: Deprecated *)

lib/es6/Js_array.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22

3-
import * as Primitive_option from "./Primitive_option.js";
43

54
function copyWithin(to_, obj) {
65
return obj.copyWithin(to_);
@@ -115,11 +114,11 @@ function filteri(arg1, obj) {
115114
}
116115

117116
function find(arg1, obj) {
118-
return Primitive_option.fromUndefined(obj.find(arg1));
117+
return obj.find(arg1);
119118
}
120119

121120
function findi(arg1, obj) {
122-
return Primitive_option.fromUndefined(obj.find(arg1));
121+
return obj.find(arg1);
123122
}
124123

125124
function findIndex(arg1, obj) {

lib/es6/Js_undefined.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ function testAny(x) {
1212

1313
function getExn(f) {
1414
if (f !== undefined) {
15-
return f;
15+
return Primitive_option.valFromOption(f);
1616
}
1717
throw new Error("Js.Undefined.getExn");
1818
}
1919

2020
function bind(x, f) {
2121
if (x !== undefined) {
22-
return f(x);
22+
return f(Primitive_option.valFromOption(x));
2323
}
2424

2525
}
2626

2727
function iter(x, f) {
2828
if (x !== undefined) {
29-
return f(x);
29+
return f(Primitive_option.valFromOption(x));
3030
}
3131

3232
}

lib/js/Js_array.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
let Primitive_option = require("./Primitive_option.js");
43

54
function copyWithin(to_, obj) {
65
return obj.copyWithin(to_);
@@ -115,11 +114,11 @@ function filteri(arg1, obj) {
115114
}
116115

117116
function find(arg1, obj) {
118-
return Primitive_option.fromUndefined(obj.find(arg1));
117+
return obj.find(arg1);
119118
}
120119

121120
function findi(arg1, obj) {
122-
return Primitive_option.fromUndefined(obj.find(arg1));
121+
return obj.find(arg1);
123122
}
124123

125124
function findIndex(arg1, obj) {

lib/js/Js_undefined.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ function testAny(x) {
1212

1313
function getExn(f) {
1414
if (f !== undefined) {
15-
return f;
15+
return Primitive_option.valFromOption(f);
1616
}
1717
throw new Error("Js.Undefined.getExn");
1818
}
1919

2020
function bind(x, f) {
2121
if (x !== undefined) {
22-
return f(x);
22+
return f(Primitive_option.valFromOption(x));
2323
}
2424

2525
}
2626

2727
function iter(x, f) {
2828
if (x !== undefined) {
29-
return f(x);
29+
return f(Primitive_option.valFromOption(x));
3030
}
3131

3232
}

runtime/Belt_internalBucketsType.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type container<'hash, 'eq, 'c> = {
3131
}
3232

3333
module A = Belt_Array
34-
external toOpt: opt<'a> => option<'a> = "%undefined_to_opt"
34+
external toOpt: opt<'a> => option<'a> = "%identity"
3535
external return: 'a => opt<'a> = "%identity"
3636

3737
let emptyOpt = Js.undefined

runtime/Belt_internalBucketsType.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type container<'hash, 'eq, 'c> = {
3030
eq: 'eq,
3131
}
3232

33-
external toOpt: opt<'a> => option<'a> = "%undefined_to_opt"
33+
external toOpt: opt<'a> => option<'a> = "%identity"
3434
external return: 'a => opt<'a> = "%identity"
3535

3636
let emptyOpt: Js.undefined<'a>

runtime/Js.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type nullable<+'a> = Js_null_undefined.t<'a> = Value('a) | @as(null) Null | @as(
190190
type null_undefined<+'a> = nullable<'a>
191191

192192
external toOption: nullable<'a> => option<'a> = "%nullable_to_opt"
193-
external undefinedToOption: undefined<'a> => option<'a> = "%undefined_to_opt"
193+
external undefinedToOption: undefined<'a> => option<'a> = "%identity"
194194
external nullToOption: null<'a> => option<'a> = "%null_to_opt"
195195
external isNullable: nullable<'a> => bool = "%is_nullable"
196196
external import: 'a => promise<'a> = "%import"

0 commit comments

Comments
 (0)