Skip to content

Commit 5aa8ef1

Browse files
committed
Use built-in type uncurried$ with one variant Uncurried$.
1 parent af8f0f8 commit 5aa8ef1

File tree

9 files changed

+35
-29
lines changed

9 files changed

+35
-29
lines changed

jscomp/frontend/ast_core_type.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ let get_uncurry_arity (ty : t) =
133133
let get_curry_arity (ty : t) =
134134
match ty.ptyp_desc with
135135
| Ptyp_constr ({ txt = Ldot (Ldot (Lident "Js", "Fn"), _) }, [ t ])
136-
| Ptyp_constr ({ txt = Ldot (Lident "Js", "uncurried") }, [ t; _ ]) ->
136+
| Ptyp_constr ({ txt = Lident "uncurried$" }, [ t; _ ]) ->
137137
get_uncurry_arity_aux t 0
138138
| _ -> get_uncurry_arity_aux ty 0
139139

jscomp/frontend/ast_core_type_class_type.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
7676
[ { ptyp_desc = Ptyp_arrow (label, args, body) } ] )
7777
| Ptyp_constr
7878
(* Js.uncurried is re-wrapped around only in case Nothing below *)
79-
( { txt = Ldot (Lident "Js", "uncurried") },
79+
( { txt = Lident "uncurried$" },
8080
[ { ptyp_desc = Ptyp_arrow (label, args, body) }; _ ] ) );
8181
(* let it go without regard label names,
8282
it will report error later when the label is not empty

jscomp/frontend/ast_external_process.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,7 @@ let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type)
870870
let prim_name_with_source = { name = prim_name; source = External } in
871871
let type_annotation, build_uncurried_type =
872872
match type_annotation.ptyp_desc with
873-
| Ptyp_constr
874-
(({ txt = Ldot (Lident "Js", "uncurried"); _ } as lid), [ t; arity_ ])
875-
->
873+
| Ptyp_constr (({ txt = Lident "uncurried$"; _ } as lid), [ t; arity_ ]) ->
876874
( t,
877875
fun ~arity x ->
878876
let tArity =

jscomp/ml/ast_uncurried.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let uncurriedType ~loc ~arity tArg =
1111
if new_representation arity then
1212
let tArity = arityType ~loc arity in
1313
Ast_helper.Typ.constr ~loc
14-
{ txt = Ldot (Lident "Js", "uncurried"); loc }
14+
{ txt = Lident "uncurried$"; loc }
1515
[ tArg; tArity ]
1616
else
1717
Ast_helper.Typ.constr ~loc
@@ -52,7 +52,7 @@ let uncurriedFun ~loc ~arity funExpr =
5252
if new_representation arity then
5353
Ast_helper.Exp.construct ~loc
5454
~attrs:(arity_to_attributes arity)
55-
{ txt = Ldot (Lident "Js", "Uncurried"); loc }
55+
{ txt = Lident "Uncurried$"; loc }
5656
(Some funExpr)
5757
else
5858
Ast_helper.Exp.record ~loc
@@ -70,14 +70,14 @@ let exprIsUncurriedFun (expr : Parsetree.expression) =
7070
| Pexp_record ([ ({ txt = Ldot (Ldot (Lident "Js", "Fn"), _) }, _e) ], None)
7171
->
7272
true
73-
| Pexp_construct ({ txt = Ldot (Lident "Js", "Uncurried") }, Some _) -> true
73+
| Pexp_construct ({ txt = Lident "Uncurried$" }, Some _) -> true
7474
| _ -> false
7575

7676
let exprExtractUncurriedFun (expr : Parsetree.expression) =
7777
match expr.pexp_desc with
7878
| Pexp_record ([ ({ txt = Ldot (Ldot (Lident "Js", "Fn"), _) }, e) ], None) ->
7979
e
80-
| Pexp_construct ({ txt = Ldot (Lident "Js", "Uncurried") }, Some e) -> e
80+
| Pexp_construct ({ txt = Lident "Uncurried$" }, Some e) -> e
8181
| _ -> assert false
8282

8383
(* Typed AST *)
@@ -105,13 +105,12 @@ let type_to_arity (tArity : Types.type_expr) =
105105

106106
let mk_js_fn ~env ~arity t =
107107
let typ_arity = arity_to_type arity in
108-
let lid : Longident.t = Ldot (Lident "Js", "uncurried") in
108+
let lid : Longident.t = Lident "uncurried$" in
109109
let path = Env.lookup_type lid env in
110110
Ctype.newconstr path [ t; typ_arity ]
111111

112112
let uncurried_type_get_arity ~env typ =
113113
match (Ctype.expand_head env typ).desc with
114-
| Tconstr (Pdot (Pident { name = "Js" }, "uncurried", _), [ _t; tArity ], _)
115-
->
114+
| Tconstr (Pident { name = "uncurried$" }, [ _t; tArity ], _) ->
116115
type_to_arity tArity
117116
| _ -> assert false

jscomp/ml/predef.ml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ and ident_floatarray = ident_create "floatarray"
4949
and ident_unknown = ident_create "unknown"
5050

5151
and ident_promise = ident_create "promise"
52+
and ident_uncurried = ident_create "uncurried$"
5253

5354
type test =
5455
| For_sure_yes
@@ -176,8 +177,9 @@ and ident_nil = ident_create "[]"
176177
and ident_cons = ident_create "::"
177178
and ident_none = ident_create "None"
178179
and ident_some = ident_create "Some"
179-
180180
and ident_ctor_unknown = ident_create "Unknown"
181+
and ident_ctor_uncurried = ident_create "Uncurried$"
182+
181183
let common_initial_env add_type add_extension empty_env =
182184
let decl_bool =
183185
{decl_abstr with
@@ -211,6 +213,15 @@ let common_initial_env add_type add_extension empty_env =
211213
type_arity = 1;
212214
type_kind = Type_variant([cstr ident_none []; cstr ident_some [tvar]]);
213215
type_variance = [Variance.covariant]}
216+
and decl_uncurried =
217+
let tvar1, tvar2 = newgenvar(), newgenvar() in
218+
{decl_abstr with
219+
type_params = [tvar1; tvar2];
220+
type_arity = 2;
221+
type_kind = Type_variant([cstr ident_ctor_uncurried [tvar1]]);
222+
type_variance = [Variance.covariant; Variance.covariant];
223+
type_unboxed = Types.unboxed_true_default_false;
224+
}
214225
and decl_unknown =
215226
let tvar = newgenvar () in
216227
{decl_abstr with
@@ -273,13 +284,14 @@ let common_initial_env add_type add_extension empty_env =
273284
add_type ident_unit decl_unit (
274285
add_type ident_bool decl_bool (
275286
add_type ident_float decl_abstr (
276-
add_type ident_unknown decl_unknown(
287+
add_type ident_unknown decl_unknown (
288+
add_type ident_uncurried decl_uncurried (
277289
add_type ident_string decl_abstr (
278290
add_type ident_int decl_abstr_imm (
279291
add_type ident_extension_constructor decl_abstr (
280292
add_type ident_floatarray decl_abstr (
281293
add_type ident_promise decl_promise (
282-
empty_env))))))))))))))))))))))))
294+
empty_env)))))))))))))))))))))))))
283295

284296
let build_initial_env add_type add_exception empty_env =
285297
let common = common_initial_env add_type add_exception empty_env in

jscomp/ml/translcore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
775775
with Not_constant -> Lprim (Pmakeblock Blk_tuple, ll, e.exp_loc))
776776
| Texp_construct ({ txt = Lident "false" }, _, []) -> Lconst Const_false
777777
| Texp_construct ({ txt = Lident "true" }, _, []) -> Lconst Const_true
778-
| Texp_construct ({ txt = Ldot (Lident "Js", "Uncurried")}, _, [expr]) ->
778+
| Texp_construct ({ txt = Lident "Uncurried$"}, _, [expr]) ->
779779
(* ReScript uncurried encoding *)
780780
let loc = expr.exp_loc in
781781
let lambda = transl_exp expr in

jscomp/ml/typecore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
21052105
exp_env = env }
21062106
| Pexp_construct(lid, sarg) ->
21072107
(match lid.txt with
2108-
| Ldot (Lident "Js", "Uncurried") ->
2108+
| Lident "Uncurried$" ->
21092109
let arity = Ast_uncurried.attributes_to_arity sexp.pexp_attributes in
21102110
let uncurried_typ = Ast_uncurried.mk_js_fn ~env ~arity (newvar()) in
21112111
unify_exp_types loc env uncurried_typ ty_expected
@@ -2998,7 +2998,7 @@ and type_application uncurried env funct (sargs : sargs) : targs * Types.type_ex
29982998
then int_of_string (String.sub a 5 (String.length a - 5))
29992999
else 0 in
30003000
Some (arity, t)
3001-
| Tconstr (Pdot(Pident {name = "Js"},"uncurried",_),[t; tArity],_) ->
3001+
| Tconstr (Pident {name = "uncurried$"},[t; tArity],_) ->
30023002
let arity = Ast_uncurried.type_to_arity tArity in
30033003
Some (arity, t)
30043004
| _ -> None in

jscomp/ml/typedecl.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,8 @@ let rec parse_native_repr_attributes env core_type ty =
15931593
let parse_native_repr_attributes env core_type ty =
15941594
match core_type.ptyp_desc, (Ctype.repr ty).desc
15951595
with
1596-
| Ptyp_constr ({txt = Ldot(Lident "Js", "uncurried")}, [{ptyp_desc = Ptyp_arrow (_, _, ct2)}; _]),
1597-
Tconstr (Pdot(Pident {name = "Js"},"uncurried",_),[{desc = Tarrow (_, _, t2, _)}; _],_) ->
1596+
| Ptyp_constr ({txt = Lident "uncurried$"}, [{ptyp_desc = Ptyp_arrow (_, _, ct2)}; _]),
1597+
Tconstr (Pident {name = "uncurried$"},[{desc = Tarrow (_, _, t2, _)}; _],_) ->
15981598
let repr_args, repr_res = parse_native_repr_attributes env ct2 t2 in
15991599
let native_repr_args = Same_as_ocaml_repr :: repr_args in
16001600
(native_repr_args, repr_res)

res_syntax/src/res_uncurried.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ let new_representation arity = arity = 5
3232
let uncurriedType ~loc ~arity tArg =
3333
if new_representation arity then
3434
let tArity = arityType ~loc arity in
35-
Ast_helper.Typ.constr ~loc
36-
{txt = Ldot (Lident "Js", "uncurried"); loc}
37-
[tArg; tArity]
35+
Ast_helper.Typ.constr ~loc {txt = Lident "uncurried$"; loc} [tArg; tArity]
3836
else
3937
Ast_helper.Typ.constr ~loc
4038
{
@@ -58,7 +56,7 @@ let uncurriedFun ~loc ~arity funExpr =
5856
if new_representation arity then
5957
Ast_helper.Exp.construct ~loc
6058
~attrs:(arity_to_attributes arity)
61-
{txt = Ldot (Lident "Js", "Uncurried"); loc}
59+
{txt = Lident "Uncurried$"; loc}
6260
(Some funExpr)
6361
else
6462
Ast_helper.Exp.record ~loc
@@ -72,13 +70,13 @@ let exprIsUncurriedFun (expr : Parsetree.expression) =
7270
match expr.pexp_desc with
7371
| Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, _e)], None) ->
7472
true
75-
| Pexp_construct ({txt = Ldot (Lident "Js", "Uncurried")}, Some _) -> true
73+
| Pexp_construct ({txt = Lident "Uncurried$"}, Some _) -> true
7674
| _ -> false
7775

7876
let exprExtractUncurriedFun (expr : Parsetree.expression) =
7977
match expr.pexp_desc with
8078
| Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) -> e
81-
| Pexp_construct ({txt = Ldot (Lident "Js", "Uncurried")}, Some e) -> e
79+
| Pexp_construct ({txt = Lident "Uncurried$"}, Some e) -> e
8280
| _ -> assert false
8381

8482
let typeIsUncurriedFun (typ : Parsetree.core_type) =
@@ -87,8 +85,7 @@ let typeIsUncurriedFun (typ : Parsetree.core_type) =
8785
({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [{ptyp_desc = Ptyp_arrow _}])
8886
->
8987
true
90-
| Ptyp_constr
91-
({txt = Ldot (Lident "Js", "uncurried")}, [{ptyp_desc = Ptyp_arrow _}; _])
88+
| Ptyp_constr ({txt = Lident "uncurried$"}, [{ptyp_desc = Ptyp_arrow _}; _])
9289
->
9390
true
9491
| _ -> false
@@ -101,6 +98,6 @@ let typeExtractUncurriedFun (typ : Parsetree.core_type) =
10198
((String.sub [@doesNotRaise]) arity 5 (String.length arity - 5))
10299
in
103100
(arity, tArg)
104-
| Ptyp_constr ({txt = Ldot (Lident "Js", "uncurried")}, [tArg; tArity]) ->
101+
| Ptyp_constr ({txt = Lident "uncurried$"}, [tArg; tArity]) ->
105102
(arityFromType tArity, tArg)
106103
| _ -> assert false

0 commit comments

Comments
 (0)