Skip to content

Commit c4468b4

Browse files
authored
Merge pull request #4984 from rescript-lang/simplify_method_call
simplify the method call
2 parents f10405b + b7ed630 commit c4468b4

21 files changed

+1843
-1744
lines changed

jscomp/.merlin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ B ounit
1515
S ounit_tests
1616
B ounit_tests
1717

18+
S main
19+
B main
20+
1821
S depends
1922
B depends
2023

jscomp/core/lam_convert.ml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -816,22 +816,20 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
816816
Lam.for_ id (convert_aux from_) (convert_aux to_) dir (convert_aux loop)
817817
| Lassign (id, body) ->
818818
Lam.assign id (convert_aux body)
819-
| Lsend (Public(Some name), _, obj, _, _loc) ->
819+
| Lsend (Public(Some name), _, obj, _, loc) ->
820820
(* Format.fprintf Format.err_formatter "%a@." Printlambda.lambda b ; *)
821-
(match convert_aux obj with
822-
| Lprim {primitive = Pjs_unsafe_downgrade _; args;loc}
823-
->
824-
let setter = Ext_string.ends_with name Literals.setter_suffix in
825-
let property =
826-
if setter then
827-
Lam_methname.translate
828-
(String.sub name 0
829-
(String.length name - Literals.setter_suffix_len))
830-
else Lam_methname.translate name in
831-
prim ~primitive:(Pjs_unsafe_downgrade {name = property; setter})
832-
~args loc
833-
| _ ->
834-
assert false)
821+
let obj = convert_aux obj in
822+
let args = [obj] in
823+
let setter = Ext_string.ends_with name Literals.setter_suffix in
824+
let property =
825+
if setter then
826+
Lam_methname.translate
827+
(String.sub name 0
828+
(String.length name - Literals.setter_suffix_len))
829+
else Lam_methname.translate name in
830+
prim ~primitive:(Pjs_unsafe_downgrade {name = property; setter})
831+
~args loc
832+
835833
| Lsend _ -> assert false
836834
| Levent _ ->
837835
(* disabled by upstream*)

jscomp/ext/literals.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let setter_suffix = "#="
5353
let setter_suffix_len = String.length setter_suffix
5454

5555
let debugger = "debugger"
56-
let unsafe_downgrade = "unsafe_downgrade"
56+
5757
let fn_run = "fn_run"
5858
let method_run = "method_run"
5959

jscomp/frontend/ast_exp_apply.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ let app_exp_mapper
177177
)
178178
;
179179
pexp_loc}
180-
(* f##paint *)
180+
(* f##paint
181+
TODO: this is not relevant: remove it later
182+
*)
181183
->
182184
sane_property_name_check pexp_loc name ;
183185
{ e with pexp_desc =

jscomp/frontend/ast_uncurry_apply.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let method_apply loc
8686
Ext_list.map args (fun (lbl,e) ->
8787
Bs_syntaxerr.optional_err loc lbl;
8888
(lbl,self.expr self e)) in
89-
let fn = Exp.mk ~loc (Ast_util.js_property loc obj name) in
89+
let fn = Exp.send ~loc obj {txt = name;loc} in
9090
let args =
9191
match args with
9292
| [ Nolabel, {pexp_desc =
@@ -115,4 +115,4 @@ let uncurry_fn_apply loc self fn args =
115115

116116
let property_apply loc self obj name args
117117
= generic_apply loc self obj args
118-
(fun loc obj -> Exp.mk ~loc (Ast_util.js_property loc obj name))
118+
(fun loc obj -> Exp.send ~loc obj {txt = name; loc})

jscomp/frontend/ast_util.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ type label_exprs = (Longident.t Asttypes.loc * Parsetree.expression) list
2929

3030
let js_property loc obj (name : string) =
3131
Parsetree.Pexp_send
32-
((Ast_compatible.app1 ~loc
33-
(Exp.ident ~loc
34-
{loc;
35-
txt = Ldot (Ast_literal.Lid.js_oo, Literals.unsafe_downgrade)})
36-
obj),
32+
(obj,
3733
{loc; txt = name}
3834
)
3935

jscomp/frontend/bs_ast_invariant.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ let emit_external_warnings : iterator=
142142
| Pexp_new _ ->
143143
Location.raise_errorf ~loc:a.pexp_loc
144144
"OCaml style objects are not supported"
145-
| Pexp_send (obj, _) ->
146-
begin match obj with
147-
| {pexp_desc = Pexp_apply ({pexp_desc = Pexp_ident ({txt = Ldot(_,"unsafe_downgrade")})},_)} -> ()
148-
| _ -> Location.raise_errorf ~loc:a.pexp_loc
149-
"OCaml style objects are not supported"
150-
end
151145
| _ -> super.expr self a
152146
);
153147
label_declaration = (fun self lbl ->

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

jscomp/others/js_OO.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
[@@@bs.config {flags = [|"-unboxed-types"|]}]
2626
(**/**)
27-
external unsafe_downgrade : 'a -> 'a = "#unsafe_downgrade"
28-
external unsafe_to_method : 'a -> 'a = "#fn_method"
27+
external unsafe_to_method : 'a -> 'a = "#fn_method"
2928
(**/**)
3029
module Callback = struct
3130
type 'a arity1 = {

jscomp/test/build.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ o test/gray_code_test.cmi test/gray_code_test.cmj : cc test/gray_code_test.ml |
335335
o test/guide_for_ext.cmi test/guide_for_ext.cmj : cc test/guide_for_ext.ml | $stdlib
336336
o test/hamming_test.cmi test/hamming_test.cmj : cc test/hamming_test.ml | test/mt.cmj $stdlib
337337
o test/hash_collision_test.cmi test/hash_collision_test.cmj : cc test/hash_collision_test.ml | test/mt.cmj $stdlib
338+
o test/hash_sugar_desugar.cmj : cc_cmi test/hash_sugar_desugar.ml | test/hash_sugar_desugar.cmi $stdlib
339+
o test/hash_sugar_desugar.cmi : cc test/hash_sugar_desugar.mli | $stdlib
338340
o test/hash_test.cmi test/hash_test.cmj : cc test/hash_test.ml | test/mt.cmj test/mt_global.cmj $stdlib
339341
o test/hashtbl_test.cmi test/hashtbl_test.cmj : cc test/hashtbl_test.ml | test/mt.cmj $stdlib
340342
o test/hello.foo.cmi test/hello.foo.cmj : cc test/hello.foo.ml | $stdlib

0 commit comments

Comments
 (0)