Skip to content

Commit 1cea958

Browse files
authored
Merge pull request #4764 from rescript-lang/fix_4762
fix #4762
2 parents f1a6581 + 0561b94 commit 1cea958

10 files changed

+514
-501
lines changed

jscomp/main/builtin_cmi_datasets.ml

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

jscomp/runtime/js.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ end
132132
module MapperRt = Js_mapperRt
133133
module Internal = struct
134134
open Fn
135-
external unsafeInvariantApply : 'a -> 'a = "#full_apply"
135+
external opaqueFullApply : 'a -> 'a = "#full_apply"
136136

137137
(* Use opaque instead of [._n] to prevent some optimizations happening *)
138138
external run : 'a arity0 -> 'a = "#run"

jscomp/snapshot.ninja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SNAP=../lib/$snapshot_path
1818
o snapshot: phony $SNAP/whole_compiler.ml $SNAP/bsb_helper.ml $SNAP/bsb.ml $SNAP/unstable/all_ounit_tests.ml
1919
# $SNAP/bspp.ml
2020
o $SNAP/whole_compiler.ml: bspack | ./bin/bspack.exe $LTO
21-
flags = ${releaseMode} -D BS_ONLY=true -bs-MD -module-alias Config=Config_whole_compiler -bs-exclude-I config -I $OCAML_SRC_UTILS -I $OCAML_SRC_PARSING -I $OCAML_SRC_TYPING -I $OCAML_SRC_BYTECOMP -I $OCAML_SRC_DRIVER ${includes}
21+
flags = ${releaseMode} -D BS_ONLY=true -bs-MD -module-alias Config=Config_whole_compiler -bs-exclude-I config -I $OCAML_SRC_UTILS -I $OCAML_SRC_PARSING -I $OCAML_SRC_TYPING -I $OCAML_SRC_BYTECOMP -I $OCAML_SRC_DRIVER $includes
2222
main = Js_main
2323
post_process = && node $LTO $SNAP/whole_compiler.ml
2424

jscomp/syntax/ast_literal.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Lid = struct
4848
(* TODO should be renamed in to {!Js.fn} *)
4949
(* TODO should be moved into {!Js.t} Later *)
5050
let js_internal : t = Ldot (Lident "Js", "Internal")
51-
let js_internal_full_apply : t = Ldot (js_internal, "unsafeInvariantApply")
51+
let js_internal_full_apply : t = Ldot (js_internal, "opaqueFullApply")
5252
let opaque : t = Ldot (js_internal, "opaque")
5353
let js_fn : t =
5454
Ldot (Lident "Js", "Fn")

jscomp/syntax/ast_uncurry_apply.ml

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ type exp = Parsetree.expression
3434
let jsInternal =
3535
Ast_literal.Lid.js_internal
3636

37+
(* we use the trick
38+
[( opaque e : _) ] to avoid it being inspected,
39+
the type constraint is avoid some syntactic transformation, e.g ` e |. (f g [@bs])`
40+
`opaque` is to avoid it being inspected in the type level
41+
*)
42+
let opaque_full_apply ~loc (e : exp) : Parsetree.expression_desc =
43+
Pexp_constraint
44+
(Exp.apply ~loc (Exp.ident {txt = Ast_literal.Lid.js_internal_full_apply; loc})
45+
[Nolabel,e],
46+
Typ.any ~loc ()
47+
)
3748
let generic_apply loc
3849
(self : Bs_ast_mapper.mapper)
3950
(obj : Parsetree.expression)
@@ -56,18 +67,15 @@ let generic_apply loc
5667
(Exp.ident {txt = Ldot (jsInternal, "run");loc}, [Nolabel,fn])
5768
else
5869
let arity_s = string_of_int arity in
59-
60-
Parsetree.Pexp_apply (
61-
Exp.ident {txt = Ast_literal.Lid.js_internal_full_apply; loc},
62-
[Nolabel,
63-
Exp.apply ~loc
64-
(Exp.apply ~loc
65-
(Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
66-
[(Nolabel, Exp.field ~loc
67-
(Exp.constraint_ ~loc fn
68-
(Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_fn, "arity"^arity_s);loc}
69-
[Typ.any ~loc ()])) {txt = Ast_literal.Lid.hidden_field arity_s; loc})])
70-
args])
70+
opaque_full_apply ~loc (
71+
Exp.apply ~loc
72+
(Exp.apply ~loc
73+
(Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
74+
[(Nolabel, Exp.field ~loc
75+
(Exp.constraint_ ~loc fn
76+
(Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_fn, "arity"^arity_s);loc}
77+
[Typ.any ~loc ()])) {txt = Ast_literal.Lid.hidden_field arity_s; loc})])
78+
args)
7179

7280
let method_apply loc
7381
(self : Bs_ast_mapper.mapper)
@@ -91,17 +99,15 @@ let method_apply loc
9199
(Exp.ident {txt = Ldot ((Ldot (Ast_literal.Lid.js_oo,"Internal")), "run");loc}, [Nolabel,fn])
92100
else
93101
let arity_s = string_of_int arity in
94-
Parsetree.Pexp_apply (
95-
Exp.ident {txt = Ast_literal.Lid.js_internal_full_apply; loc},
96-
[Nolabel,
97-
Exp.apply ~loc (
98-
Exp.apply ~loc (Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
99-
[(Nolabel,
102+
opaque_full_apply ~loc (
103+
Exp.apply ~loc (
104+
Exp.apply ~loc (Exp.ident ~loc {txt = Ast_literal.Lid.opaque; loc})
105+
[(Nolabel,
100106
Exp.field ~loc
101107
(Exp.constraint_ ~loc
102-
fn (Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_meth,"arity"^arity_s);loc} [Typ.any ~loc ()]))
108+
fn (Typ.constr ~loc {txt = Ldot (Ast_literal.Lid.js_meth,"arity"^arity_s);loc} [Typ.any ~loc ()]))
103109
{loc; txt = Ast_literal.Lid.hidden_field arity_s})])
104-
args])
110+
args)
105111

106112

107113
let uncurry_fn_apply loc self fn args =

jscomp/test/label_uncurry.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ let h = fun [@bs] ~x:unit -> 3
1717

1818
let a = u1 u
1919

20-
(* let u1 (f : u) =
21-
Js.Internal.unsafeInvariantApply ((Js.Internal.run2 (f : u)) ~y:"x" ~x:2)
22-
*)
2320

2421

2522
type u0 = ?x:int -> y : string -> int [@bs]

jscomp/test/unsafe_full_apply_primitive.ml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11

22

3-
(* external unsafeInvariantApply : 'a -> 'a = "#full_apply"
4-
5-
6-
let f1 x = unsafeInvariantApply (x ())
7-
8-
9-
let f2 x y = unsafeInvariantApply (x y ()) *)
10-
113

124
let rec f = fun [@bs] a -> f a [@bs]
135

lib/4.06.1/unstable/js_compiler.ml

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

lib/4.06.1/unstable/js_refmt_compiler.ml

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

0 commit comments

Comments
 (0)