Skip to content

Remove the transformation of application using opaqueFullApply from the compiler's PPX. #6893

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

Merged
merged 11 commits into from
Jul 24, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- Cleanup: remove tracking of uncurried state in parser/printer. https://github.com/rescript-lang/rescript-compiler/pull/6888
- Remove `%opaque` primitive. https://github.com/rescript-lang/rescript-compiler/pull/6892
- Reunify JsxC/JsxU -> Jsx etc. https://github.com/rescript-lang/rescript-compiler/pull/6895
- Remove the transformation of `foo(1,2)` into `Js.Internal.opaqueFullApply(Internal.opaque(f), 1, 2)`, and change the back-end to treat all applications as uncurried. https://github.com/rescript-lang/rescript-compiler/pull/6893

#### :nail_care: Polish

Expand Down
34 changes: 9 additions & 25 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1531,15 +1531,10 @@ and compile_prim (prim_info : Lam.prim_info)
check the arity of fn before wrapping it
we need mark something that such eta-conversion can not be simplified in some cases
*)
| {
primitive = Pjs_unsafe_downgrade { name = property; setter };
args = [ obj ];
} -> (
(*
either a getter {[ x #. height ]} or {[ x ## method_call ]}
*)
assert (not setter);

| { primitive = Pjs_unsafe_downgrade { name = property; setter=false };
args = [ obj ];
} -> (
(* getter {[ x #. height ]} *)
match
compile_lambda { lambda_cxt with continuation = NeedValue Not_tail } obj
with
Expand All @@ -1555,18 +1550,10 @@ and compile_prim (prim_info : Lam.prim_info)
in
Js_output.output_of_block_and_expression lambda_cxt.continuation
blocks ret)
| {
primitive = Pfull_apply;
args =
[
Lprim
{
primitive = Pjs_unsafe_downgrade { name = property; setter = true };
args = [ obj ];
};
setter_val;
];
} -> (
| { primitive = Pjs_unsafe_downgrade { name = property; setter = true };
args = [ obj; setter_val ];
} -> (
(* setter {[ x ## method_call ]} *)
let need_value_no_return_cxt =
{ lambda_cxt with continuation = NeedValue Not_tail }
in
Expand All @@ -1589,10 +1576,7 @@ and compile_prim (prim_info : Lam.prim_info)
| Some (obj_code, obj) ->
cont obj_block arg_block (Some obj_code)
(E.seq (E.assign (E.dot (E.var obj) property) value) E.unit)))
| {
primitive = Pfull_apply;
args = Lprim { primitive = Pjs_unsafe_downgrade { setter = true } } :: _;
} ->
| { primitive = Pjs_unsafe_downgrade _; args } ->
assert false
| { primitive = Pfull_apply | Pvoid_run; args; loc } -> (
(* 1. uncurried call should not do eta-conversion
Expand Down
45 changes: 20 additions & 25 deletions jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ let unit = Lam.unit
let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
match p with
| Pidentity -> Ext_list.singleton_exn args
| Puncurried_apply | Pccall _ -> assert false
| Pccall _ -> assert false
| Prevapply -> assert false
| Pdirapply -> assert false
| Ploc _ -> assert false (* already compiled away here*)
Expand Down Expand Up @@ -527,11 +527,29 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
match lam with
| Lvar x -> Lam.var (Hash_ident.find_default alias_tbl x x)
| Lconst x -> Lam.const (Lam_constant_convert.convert_constant x)
| Lapply { ap_func = ((Lsend (name, obj, loc))); ap_args } when Ext_string.ends_with name Literals.setter_suffix ->
let obj = convert_aux obj in
let args = obj :: (Ext_list.map ap_args convert_aux) in
let property =
(String.sub name 0
(String.length name - Literals.setter_suffix_len))
in
prim
~primitive:(Pjs_unsafe_downgrade { name = property; setter=true })
~args loc
| Lsend (name, obj, loc) ->
let obj = convert_aux obj in
let args = [ obj ] in
let setter = Ext_string.ends_with name Literals.setter_suffix in
let _ = assert (not setter) in
prim
~primitive:(Pjs_unsafe_downgrade { name; setter })
~args loc
| Lapply { ap_func = fn; ap_args = args; ap_loc = loc; ap_inlined } ->
(* we need do this eargly in case [aux fn] add some wrapper *)
Lam.apply (convert_aux fn)
(Ext_list.map args convert_aux)
{ ap_loc = loc; ap_inlined; ap_status = App_na }
{ ap_loc = loc; ap_inlined; ap_status = App_uncurry }
| Lfunction { params; body; attr } ->
let new_map, body =
rename_optional_parameters Map_ident.empty params body
Expand Down Expand Up @@ -566,16 +584,6 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
may_depend may_depends (Lam_module_ident.of_ml ~dynamic_import id);
assert (args = []);
Lam.global_module ~dynamic_import id)
| Lprim
( Puncurried_apply,
[ Lapply { ap_func; ap_args } ],
loc ) ->
let ap_func = convert_aux ap_func in
let ap_args = Ext_list.map ap_args convert_aux in
prim ~primitive:Pfull_apply ~args:(ap_func :: ap_args) loc
(* There may be some optimization opportunities here
for cases like `(fun [@bs] a b -> a + b ) 1 2 [@bs]` *)
| Lprim (Puncurried_apply, _, _) -> assert false
| Lprim (primitive, args, loc) ->
let args = Ext_list.map args (convert_aux ~dynamic_import) in
lam_prim ~primitive ~args loc
Expand Down Expand Up @@ -611,19 +619,6 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
| Lfor (id, from_, to_, dir, loop) ->
Lam.for_ id (convert_aux from_) (convert_aux to_) dir (convert_aux loop)
| Lassign (id, body) -> Lam.assign id (convert_aux body)
| Lsend (name, obj, loc) ->
let obj = convert_aux obj in
let args = [ obj ] in
let setter = Ext_string.ends_with name Literals.setter_suffix in
let property =
if setter then
(String.sub name 0
(String.length name - Literals.setter_suffix_len))
else name
in
prim
~primitive:(Pjs_unsafe_downgrade { name = property; setter })
~args loc
and convert_let (kind : Lam_compat.let_kind) id (e : Lambda.lambda) body :
Lam.t =
match (kind, e) with
Expand Down
4 changes: 0 additions & 4 deletions jscomp/frontend/ast_literal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ module Lid = struct

let type_bool : t = Lident "bool" (* use *predef* *)

(* TODO should be renamed in to {!Js.fn} *)
(* TODO should be moved into {!Js.t} Later *)
let js_internal : t = Ldot (Lident "Js", "Internal")

let js_oo : t = Lident "Js_OO"

let js_meth_callback : t = Ldot (js_oo, "Callback")
Expand Down
2 changes: 0 additions & 2 deletions jscomp/frontend/ast_literal.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ module Lid : sig
val js_null_undefined : t

val js_re_id : t

val js_internal : t
end

type expression_lit = Parsetree.expression lit
Expand Down
Loading