Skip to content
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

Don't emit f(undefined) when passing unit (). #6459

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
isUnit
  • Loading branch information
cristianoc committed Oct 31, 2023
commit f0f02026d6a15617289b54488b8704b18295abe2
2 changes: 1 addition & 1 deletion jscomp/core/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ and expression_desc =
*)
| Number of number
| Object of property_map
| Undefined of bool (* true means: unit *)
| Undefined of {isUnit: bool}
| Null
| Await of expression

Expand Down
11 changes: 6 additions & 5 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,17 @@ and expression_desc cxt ~(level : int) f x : cxt =
async;
};
};
] -> (* *)

] ->
pp_function ~is_method ~return_unit ~async cxt f
~fn_state:(No_name { single_arg = true })
params body env
| _ ->
let el = match el with
| [e] when e.expression_desc = Undefined true (* unit *) -> []
| _ ->el in

| [e] when e.expression_desc = Undefined {isUnit = true} ->
(* omit passing undefined when the calls is f() *)
[]
| _ ->
el in
arguments cxt f el)
| _, _ ->
let len = List.length el in
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let var ?comment id : t = { expression_desc = Var (Id id); comment }
Invariant: it should not call an external module .. *)

let js_global ?comment (v : string) = var ?comment (Ext_ident.create_js v)
let undefined : t = { expression_desc = Undefined false; comment = None }
let undefined : t = { expression_desc = Undefined {isUnit = false}; comment = None }
let nil : t = { expression_desc = Null; comment = None }

let call ?comment ~info e0 args : t =
Expand Down Expand Up @@ -183,7 +183,7 @@ let is_array (e0 : t) : t =
let new_ ?comment e0 args : t =
{ expression_desc = New (e0, Some args); comment }

let unit : t = { expression_desc = Undefined true; comment = None }
let unit : t = { expression_desc = Undefined {isUnit = true}; comment = None }

(* let math ?comment v args : t =
{comment ; expression_desc = Math(v,args)} *)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ let stringswitch (lam : t) cases default : t =

let true_ : t = Lconst Const_js_true
let false_ : t = Lconst Const_js_false
let unit : t = Lconst (Const_js_undefined true)
let unit : t = Lconst (Const_js_undefined {isUnit = true})

let rec seq (a : t) b : t =
match a with
Expand Down
6 changes: 3 additions & 3 deletions jscomp/core/lam_compile_const.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let rec nested_some_none n none =
let rec translate_some (x : Lam_constant.t) : J.expression =
let depth = is_some_none_aux x 0 in
if depth < 0 then E.optional_not_nest_block (translate x)
else nested_some_none depth (E.optional_block (translate (Const_js_undefined false)))
else nested_some_none depth (E.optional_block (translate (Const_js_undefined {isUnit = false})))

and translate (x : Lam_constant.t) : J.expression =
match x with
Expand All @@ -46,8 +46,8 @@ and translate (x : Lam_constant.t) : J.expression =
| Const_js_true -> E.bool true
| Const_js_false -> E.bool false
| Const_js_null -> E.nil
| Const_js_undefined true -> E.unit
| Const_js_undefined false -> E.undefined
| Const_js_undefined {isUnit = true} -> E.unit
| Const_js_undefined {isUnit = false} -> E.undefined
| Const_int { i; comment = Pt_constructor {cstr_name={name; tag_type=None}}} when name <> "[]" ->
E.str name
| Const_int { i; comment = Pt_constructor {cstr_name={tag_type = Some t}}} ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_constant_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t =
| Const_base (Const_nativeint _) -> assert false
| Const_pointer (0, Pt_constructor { name = "()"; const = 1; non_const = 0 })
->
Const_js_undefined true
Const_js_undefined {isUnit = true}
| Const_false -> Const_js_false
| Const_true -> Const_js_true
| Const_pointer (i, p) -> (
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
| _ when s = "#null" -> Lam.const Const_js_null
| _ when s = "#os_type" ->
prim ~primitive:(Pctconst Ostype) ~args:[ unit ] loc
| _ when s = "#undefined" -> Lam.const (Const_js_undefined false)
| _ when s = "#undefined" -> Lam.const (Const_js_undefined {isUnit = false})
| _ when s = "#init_mod" -> (
let args = Ext_list.map args convert_aux in
match args with
Expand Down
4 changes: 2 additions & 2 deletions jscomp/frontend/lam_constant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let string_of_pointer_info (x : pointer_info) : string option =

type t =
| Const_js_null
| Const_js_undefined of bool (* true: unit *)
| Const_js_undefined of {isUnit: bool}
| Const_js_true
| Const_js_false
| Const_int of {i: int32; comment: pointer_info}
Expand Down Expand Up @@ -104,4 +104,4 @@ let rec eq_approx (x : t) (y : t) =
| Const_some iy -> eq_approx ix iy
| _ -> false)

let lam_none : t = Const_js_undefined false
let lam_none : t = Const_js_undefined {isUnit = false}
2 changes: 1 addition & 1 deletion jscomp/frontend/lam_constant.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ val string_of_pointer_info : pointer_info -> string option

type t =
| Const_js_null
| Const_js_undefined of bool (* true: unit *)
| Const_js_undefined of {isUnit: bool}
| Const_js_true
| Const_js_false
| Const_int of {i: int32; comment: pointer_info}
Expand Down