Skip to content

Remove @return(undefined_to_opt) and %undefined_to_opt primitive #7462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions compiler/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ let rec apply ?(ap_transformed_jsx = false) fn args (ap_info : ap_info) : t =
Lprim
{
primitive =
( Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt
| Pis_null | Pis_null_undefined | Ptypeof ) as wrap;
( Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
| Pis_null_undefined | Ptypeof ) as wrap;
args =
[Lprim ({primitive = _; args = inner_args} as primitive_call)];
};
Expand Down Expand Up @@ -442,11 +442,7 @@ let rec seq (a : t) b : t =
match a with
| Lprim {primitive = Pmakeblock _; args = x :: xs} ->
seq (Ext_list.fold_left xs x seq) b
| Lprim
{
primitive = Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt;
args = [a];
} ->
| Lprim {primitive = Pnull_to_opt | Pnull_undefined_to_opt; args = [a]} ->
seq a b
| _ -> Lsequence (a, b)

Expand Down Expand Up @@ -719,8 +715,6 @@ let result_wrap loc (result_type : External_ffi_types.return_wrapper) result =
| Return_null_to_opt -> prim ~primitive:Pnull_to_opt ~args:[result] loc
| Return_null_undefined_to_opt ->
prim ~primitive:Pnull_undefined_to_opt ~args:[result] loc
| Return_undefined_to_opt ->
prim ~primitive:Pundefined_to_opt ~args:[result] loc
| Return_unset | Return_identity -> result

let handle_bs_non_obj_ffi ?(transformed_jsx = false)
Expand Down
4 changes: 2 additions & 2 deletions compiler/core/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ let rec no_side_effects (lam : Lam.t) : bool =
| _ -> false)
| Pcreate_extension _ | Ptypeof | Pis_null | Pis_not_none | Psome
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pnull_to_opt
| Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _
| Pjs_fn_make_unit | Pjs_object_create _ | Pimport
| Pnull_undefined_to_opt | Pjs_fn_make _ | Pjs_fn_make_unit
| Pjs_object_create _ | Pimport
(* TODO: check *)
| Pmakeblock _
(* whether it's mutable or not *)
Expand Down
7 changes: 0 additions & 7 deletions compiler/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
| Var _ | Undefined _ | Null -> Js_of_lam_option.null_to_opt e
| _ -> E.runtime_call Primitive_modules.option "fromNull" args)
| _ -> assert false)
| Pundefined_to_opt -> (
match args with
| [e] -> (
match e.expression_desc with
| Var _ | Undefined _ | Null -> Js_of_lam_option.undef_to_opt e
| _ -> E.runtime_call Primitive_modules.option "fromUndefined" args)
| _ -> assert false)
| Pnull_undefined_to_opt -> (
match args with
| [e] -> (
Expand Down
1 change: 0 additions & 1 deletion compiler/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
| Pisnullable -> prim ~primitive:Pis_null_undefined ~args loc
| Pnull_to_opt -> prim ~primitive:Pnull_to_opt ~args loc
| Pnullable_to_opt -> prim ~primitive:Pnull_undefined_to_opt ~args loc
| Pundefined_to_opt -> prim ~primitive:Pundefined_to_opt ~args loc
| Pis_not_none -> prim ~primitive:Pis_not_none ~args loc
| Pval_from_option -> prim ~primitive:Pval_from_option ~args loc
| Pval_from_option_not_nest ->
Expand Down
2 changes: 0 additions & 2 deletions compiler/core/lam_pass_collect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ let collect_info (meta : Lam_stats.t) (lam : Lam.t) =
(FunctionId {arity = Lam_arity.info [arity] false; lambda = None})
| Lprim {primitive = Pnull_to_opt; args = [(Lvar _ as l)]; _} ->
Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Null))
| Lprim {primitive = Pundefined_to_opt; args = [(Lvar _ as l)]; _} ->
Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Undefined))
| Lprim {primitive = Pnull_undefined_to_opt; args = [(Lvar _ as l)]} ->
Hash_ident.replace meta.ident_tbl ident
(OptionalBlock (l, Null_undefined))
Expand Down
7 changes: 2 additions & 5 deletions compiler/core/lam_pass_deep_flatten.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ let deep_flatten (lam : Lam.t) : Lam.t =
id,
(Lprim
{
primitive =
Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt;
primitive = Pnull_to_opt | Pnull_undefined_to_opt;
args = [Lvar _];
} as arg),
body ) ->
Expand All @@ -134,9 +133,7 @@ let deep_flatten (lam : Lam.t) : Lam.t =
id,
Lprim
{
primitive =
(Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt) as
primitive;
primitive = (Pnull_to_opt | Pnull_undefined_to_opt) as primitive;
args = [arg];
},
body ) ->
Expand Down
13 changes: 6 additions & 7 deletions compiler/core/lam_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ type t =
play safe first
*)
| Pjs_fn_method
| Pundefined_to_opt
| Pnull_to_opt
| Pnull_undefined_to_opt
| Pis_null
Expand Down Expand Up @@ -224,12 +223,12 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
| Pawait
(* etc *)
| Pjs_apply | Pjs_runtime_apply | Pval_from_option | Pval_from_option_not_nest
| Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
| Pis_not_none | Psome | Psome_not_nest | Pis_undefined | Pis_null_undefined
| Pimport | Ptypeof | Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod
| Pupdate_mod | Pduprecord | Pmakearray | Parraylength | Parrayrefu
| Parraysetu | Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method
| Phash | Phash_mixstring | Phash_mixint | Phash_finalmix ->
| Pnull_to_opt | Pnull_undefined_to_opt | Pis_null | Pis_not_none | Psome
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pimport | Ptypeof
| Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod | Pupdate_mod
| Pduprecord | Pmakearray | Parraylength | Parrayrefu | Parraysetu
| Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method | Phash
| Phash_mixstring | Phash_mixint | Phash_finalmix ->
rhs = lhs
| Pcreate_extension a -> (
match rhs with
Expand Down
1 change: 0 additions & 1 deletion compiler/core/lam_primitive.mli
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ type t =
| Pjs_fn_make of int
| Pjs_fn_make_unit
| Pjs_fn_method
| Pundefined_to_opt
| Pnull_to_opt
| Pnull_undefined_to_opt
| Pis_null
Expand Down
1 change: 0 additions & 1 deletion compiler/core/lam_print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ let primitive ppf (prim : Lam_primitive.t) =
| Praw_js_code _ -> fprintf ppf "[raw]"
| Ptypeof -> fprintf ppf "typeof"
| Pnull_to_opt -> fprintf ppf "[null->opt]"
| Pundefined_to_opt -> fprintf ppf "[undefined->opt]"
| Pnull_undefined_to_opt -> fprintf ppf "[null/undefined->opt]"
| Pis_null -> fprintf ppf "[?null]"
| Pis_not_none -> fprintf ppf "[?is-not-none]"
Expand Down
18 changes: 0 additions & 18 deletions compiler/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,6 @@ let set : attr = ({txt = "set"; loc = locg}, Ast_payload.empty)
let internal_expansive : attr =
({txt = "internal.expansive"; loc = locg}, Ast_payload.empty)

let bs_return_undefined : attr =
( {txt = "return"; loc = locg},
PStr
[
{
pstr_desc =
Pstr_eval
( {
pexp_desc =
Pexp_ident {txt = Lident "undefined_to_opt"; loc = locg};
pexp_loc = locg;
pexp_attributes = [];
},
[] );
pstr_loc = locg;
};
] )

let is_gentype (attr : attr) =
match attr with
| {Location.txt = "genType" | "gentype"; _}, _ -> true
Expand Down
2 changes: 0 additions & 2 deletions compiler/frontend/ast_attributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ val get_index : attr

val set : attr

val bs_return_undefined : attr

val internal_expansive : attr
(* val deprecated : string -> attr *)

Expand Down
3 changes: 1 addition & 2 deletions compiler/frontend/ast_derive_abstract.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ let is_abstract (xs : Ast_payload.action list) =
(** For this attributes, its type was wrapped as an option,
so we can still reuse existing frame work
*)
let get_optional_attrs =
[Ast_attributes.get; Ast_attributes.bs_return_undefined]
let get_optional_attrs = [Ast_attributes.get]

let get_attrs = []

Expand Down
4 changes: 1 addition & 3 deletions compiler/frontend/ast_external_process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ let init_st =

let return_wrapper loc (txt : string) : External_ffi_types.return_wrapper =
match txt with
| "undefined_to_opt" -> Return_undefined_to_opt
| "null_to_opt" -> Return_null_to_opt
| "nullable" | "null_undefined_to_opt" -> Return_null_undefined_to_opt
| "identity" -> Return_identity
Expand Down Expand Up @@ -407,8 +406,7 @@ let check_return_wrapper loc (wrapper : External_ffi_types.return_wrapper)
| Return_unset ->
if Ast_core_type.is_unit result_type then Return_replaced_with_unit
else wrapper
| Return_undefined_to_opt | Return_null_to_opt | Return_null_undefined_to_opt
->
| Return_null_to_opt | Return_null_undefined_to_opt ->
if Ast_core_type.is_user_option result_type then wrapper
else Bs_syntaxerr.err loc Expect_opt_in_bs_return_to_opt
| Return_replaced_with_unit -> assert false
Expand Down
1 change: 0 additions & 1 deletion compiler/frontend/external_ffi_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ type external_spec =
type return_wrapper =
| Return_unset
| Return_identity
| Return_undefined_to_opt
| Return_null_to_opt
| Return_null_undefined_to_opt
| Return_replaced_with_unit
Expand Down
1 change: 0 additions & 1 deletion compiler/frontend/external_ffi_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type external_spec =
type return_wrapper =
| Return_unset
| Return_identity
| Return_undefined_to_opt
| Return_null_to_opt
| Return_null_undefined_to_opt
| Return_replaced_with_unit
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ type primitive =
(* js *)
| Pcurry_apply of int
| Pjscomp of comparison
| Pundefined_to_opt
| Pnull_to_opt
| Pnullable_to_opt
| Pis_not_none
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ type primitive =
(* js *)
| Pcurry_apply of int
| Pjscomp of comparison
| Pundefined_to_opt
| Pnull_to_opt
| Pnullable_to_opt
| Pis_not_none
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/printlambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ let primitive ppf = function
| Pjscomp Cle -> fprintf ppf "<="
| Pjscomp Cgt -> fprintf ppf ">"
| Pjscomp Cge -> fprintf ppf ">="
| Pundefined_to_opt -> fprintf ppf "undefined_to_opt"
| Pnull_to_opt -> fprintf ppf "null_to_opt"
| Pnullable_to_opt -> fprintf ppf "nullable_to_opt"
| Pis_not_none -> fprintf ppf "#is_not_none"
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ let primitives_table =
("%null", Pnull);
("%undefined", Pundefined);
("%is_nullable", Pisnullable);
("%undefined_to_opt", Pundefined_to_opt);
("%null_to_opt", Pnull_to_opt);
("%nullable_to_opt", Pnullable_to_opt);
("%function_arity", Pfn_arity);
Expand All @@ -397,7 +396,6 @@ let primitives_table =
("#is_nullable", Pisnullable);
("#null_to_opt", Pnull_to_opt);
("#nullable_to_opt", Pnullable_to_opt);
("#undefined_to_opt", Pundefined_to_opt);
("#makemutablelist", Pmakelist Mutable);
("#import", Pimport);
(* FIXME: Deprecated *)
Expand Down
5 changes: 2 additions & 3 deletions lib/es6/Js_array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


import * as Primitive_option from "./Primitive_option.js";

function copyWithin(to_, obj) {
return obj.copyWithin(to_);
Expand Down Expand Up @@ -115,11 +114,11 @@ function filteri(arg1, obj) {
}

function find(arg1, obj) {
return Primitive_option.fromUndefined(obj.find(arg1));
return obj.find(arg1);
}

function findi(arg1, obj) {
return Primitive_option.fromUndefined(obj.find(arg1));
return obj.find(arg1);
}

function findIndex(arg1, obj) {
Expand Down
6 changes: 3 additions & 3 deletions lib/es6/Js_undefined.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ function testAny(x) {

function getExn(f) {
if (f !== undefined) {
return f;
return Primitive_option.valFromOption(f);
}
throw new Error("Js.Undefined.getExn");
}

function bind(x, f) {
if (x !== undefined) {
return f(x);
return f(Primitive_option.valFromOption(x));
}

}

function iter(x, f) {
if (x !== undefined) {
return f(x);
return f(Primitive_option.valFromOption(x));
}

}
Expand Down
5 changes: 2 additions & 3 deletions lib/js/Js_array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

let Primitive_option = require("./Primitive_option.js");

function copyWithin(to_, obj) {
return obj.copyWithin(to_);
Expand Down Expand Up @@ -115,11 +114,11 @@ function filteri(arg1, obj) {
}

function find(arg1, obj) {
return Primitive_option.fromUndefined(obj.find(arg1));
return obj.find(arg1);
}

function findi(arg1, obj) {
return Primitive_option.fromUndefined(obj.find(arg1));
return obj.find(arg1);
}

function findIndex(arg1, obj) {
Expand Down
6 changes: 3 additions & 3 deletions lib/js/Js_undefined.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ function testAny(x) {

function getExn(f) {
if (f !== undefined) {
return f;
return Primitive_option.valFromOption(f);
}
throw new Error("Js.Undefined.getExn");
}

function bind(x, f) {
if (x !== undefined) {
return f(x);
return f(Primitive_option.valFromOption(x));
}

}

function iter(x, f) {
if (x !== undefined) {
return f(x);
return f(Primitive_option.valFromOption(x));
}

}
Expand Down
2 changes: 1 addition & 1 deletion runtime/Belt_internalBucketsType.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type container<'hash, 'eq, 'c> = {
}

module A = Belt_Array
external toOpt: opt<'a> => option<'a> = "%undefined_to_opt"
external toOpt: opt<'a> => option<'a> = "%identity"
external return: 'a => opt<'a> = "%identity"

let emptyOpt = Js.undefined
Expand Down
2 changes: 1 addition & 1 deletion runtime/Belt_internalBucketsType.resi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type container<'hash, 'eq, 'c> = {
eq: 'eq,
}

external toOpt: opt<'a> => option<'a> = "%undefined_to_opt"
external toOpt: opt<'a> => option<'a> = "%identity"
external return: 'a => opt<'a> = "%identity"

let emptyOpt: Js.undefined<'a>
Expand Down
2 changes: 1 addition & 1 deletion runtime/Js.res
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type nullable<+'a> = Js_null_undefined.t<'a> = Value('a) | @as(null) Null | @as(
type null_undefined<+'a> = nullable<'a>

external toOption: nullable<'a> => option<'a> = "%nullable_to_opt"
external undefinedToOption: undefined<'a> => option<'a> = "%undefined_to_opt"
external undefinedToOption: undefined<'a> => option<'a> = "%identity"
external nullToOption: null<'a> => option<'a> = "%null_to_opt"
external isNullable: nullable<'a> => bool = "%is_nullable"
external import: 'a => promise<'a> = "%import"
Expand Down
Loading
Loading