Skip to content

Commit d236f76

Browse files
committed
apply the optimization
1 parent 60b5e1a commit d236f76

File tree

5 files changed

+129
-122
lines changed

5 files changed

+129
-122
lines changed

jscomp/core/lam_compile_external_obj.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
104104
(Ext_list.flat_map assignment (fun
105105
((xlabel : External_arg_spec.obj_param), (arg : J.expression )) ->
106106
match xlabel with
107-
| {obj_arg_label = Obj_optional {name = label} } ->
107+
| {obj_arg_label = Obj_optional {name = label;for_sure_no_nested_option} } ->
108108
(* Need make sure whether assignment is effectful or not
109109
to avoid code duplication
110110
*)
@@ -114,7 +114,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
114114
Lam_compile_external_call.ocaml_to_js_eff
115115
~arg_label:
116116
Arg_empty ~arg_type:xlabel.obj_arg_type
117-
(Js_of_lam_option.val_from_option arg) in
117+
(if for_sure_no_nested_option then arg else Js_of_lam_option.val_from_option arg) in
118118
begin match acc with
119119
| Splice1 v ->
120120
[S.if_ (Js_of_lam_option.is_not_none arg )
@@ -134,7 +134,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
134134
~arg_label:
135135
Arg_empty
136136
~arg_type:xlabel.obj_arg_type
137-
(Js_of_lam_option.val_from_option arg) in
137+
(if for_sure_no_nested_option then arg else Js_of_lam_option.val_from_option arg) in
138138
begin match acc with
139139
| Splice1 v ->
140140
st ::

jscomp/frontend/ast_external_process.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,22 @@ let process_obj
492492
param_type::arg_types, result_types
493493
| Nothing ->
494494
let s = (Lam_methname.translate name) in
495-
{obj_arg_label = External_arg_spec.optional s; obj_arg_type},
495+
let for_sure_not_nested =
496+
match ty.ptyp_desc with
497+
| Ptyp_constr({txt = Lident txt;_}, []) ->
498+
Ast_core_type.is_builtin_rank0_type txt
499+
| _ -> false in
500+
{obj_arg_label = External_arg_spec.optional for_sure_not_nested s; obj_arg_type},
496501
param_type :: arg_types,
497502
( Parsetree.Otag ({Asttypes.txt = name; loc}, [], Ast_comb.to_undefined_type loc ty) :: result_types)
498503
| Int _ ->
499504
let s = Lam_methname.translate name in
500-
{obj_arg_label = External_arg_spec.optional s ; obj_arg_type },
505+
{obj_arg_label = External_arg_spec.optional true s ; obj_arg_type },
501506
param_type :: arg_types,
502507
(Otag ({Asttypes.txt = name; loc}, [], Ast_comb.to_undefined_type loc @@ Ast_literal.type_int ~loc ()) :: result_types)
503508
| Poly_var_string _ ->
504509
let s = Lam_methname.translate name in
505-
{obj_arg_label = External_arg_spec.optional s ; obj_arg_type },
510+
{obj_arg_label = External_arg_spec.optional true s ; obj_arg_type },
506511
param_type::arg_types,
507512
(Otag ({Asttypes.txt = name; loc}, [], Ast_comb.to_undefined_type loc @@ Ast_literal.type_string ~loc ()) :: result_types)
508513
| Arg_cst _
@@ -1020,7 +1025,7 @@ let pval_prim_of_option_labels
10201025
let label_name = Lam_methname.translate p.txt in
10211026
let obj_arg_label =
10221027
if is_option then
1023-
External_arg_spec.optional label_name
1028+
External_arg_spec.optional false label_name
10241029
else External_arg_spec.obj_label label_name
10251030
in
10261031
{obj_arg_type = Nothing ;

0 commit comments

Comments
 (0)