Skip to content

Commit e96f2f2

Browse files
authored
Remove res partial (#7240)
* Add partial flag to untyped and typed AST node and prepare to remove `@res.partial`. * Remove `@res.partial` entirely. * Update CHANGELOG.md
1 parent 38a93a4 commit e96f2f2

40 files changed

+159
-165
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- AST cleanup: Prepare for ast async cleanup: Refactor code for "@res.async" payload handling and clean up handling of type and term parameters, so that now each `=>` in a function definition corresponds to a function. https://github.com/rescript-lang/rescript/pull/7223
2525
- AST: always put type parameters first in function definitions. https://github.com/rescript-lang/rescript/pull/7233
2626
- AST cleanup: Remove `@res.async` attribute from the internal representation, and add a flag to untyped and typed ASTs instead. https://github.com/rescript-lang/rescript/pull/7234
27+
- AST cleanup: Remove `@res.partial` attribute from the internal representation, and add a flag to untyped and typed ASTs instead. https://github.com/rescript-lang/rescript/pull/7238 https://github.com/rescript-lang/rescript/pull/7240
2728

2829
# 12.0.0-alpha.7
2930

analysis/src/CompletionFrontEnd.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,14 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
262262
pexp_loc;
263263
pexp_attributes;
264264
};
265-
args = [(_, lhs); (_, {pexp_desc = Pexp_apply {funct = d; args}})];
265+
args =
266+
[(_, lhs); (_, {pexp_desc = Pexp_apply {funct = d; args; partial}})];
266267
} ->
267268
(* Transform away pipe with apply call *)
268269
exprToContextPath
269270
{
270-
pexp_desc = Pexp_apply {funct = d; args = (Nolabel, lhs) :: args};
271+
pexp_desc =
272+
Pexp_apply {funct = d; args = (Nolabel, lhs) :: args; partial};
271273
pexp_loc;
272274
pexp_attributes;
273275
}
@@ -278,6 +280,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
278280
[
279281
(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes});
280282
];
283+
partial;
281284
} ->
282285
(* Transform away pipe with identifier *)
283286
exprToContextPath
@@ -287,6 +290,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
287290
{
288291
funct = {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes};
289292
args = [(Nolabel, lhs)];
293+
partial;
290294
};
291295
pexp_loc;
292296
pexp_attributes;

compiler/frontend/ast_compatible.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,28 @@ let apply_simple ?(loc = default_loc) ?(attrs = []) (fn : expression)
4040
pexp_attributes = attrs;
4141
pexp_desc =
4242
Pexp_apply
43-
{funct = fn; args = Ext_list.map args (fun x -> (Asttypes.Nolabel, x))};
43+
{
44+
funct = fn;
45+
args = Ext_list.map args (fun x -> (Asttypes.Nolabel, x));
46+
partial = false;
47+
};
4448
}
4549

4650
let app1 ?(loc = default_loc) ?(attrs = []) fn arg1 : expression =
4751
{
4852
pexp_loc = loc;
4953
pexp_attributes = attrs;
50-
pexp_desc = Pexp_apply {funct = fn; args = [(Nolabel, arg1)]};
54+
pexp_desc =
55+
Pexp_apply {funct = fn; args = [(Nolabel, arg1)]; partial = false};
5156
}
5257

5358
let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
5459
{
5560
pexp_loc = loc;
5661
pexp_attributes = attrs;
5762
pexp_desc =
58-
Pexp_apply {funct = fn; args = [(Nolabel, arg1); (Nolabel, arg2)]};
63+
Pexp_apply
64+
{funct = fn; args = [(Nolabel, arg1); (Nolabel, arg2)]; partial = false};
5965
}
6066

6167
let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
@@ -64,7 +70,11 @@ let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
6470
pexp_attributes = attrs;
6571
pexp_desc =
6672
Pexp_apply
67-
{funct = fn; args = [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)]};
73+
{
74+
funct = fn;
75+
args = [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)];
76+
partial = false;
77+
};
6878
}
6979

7080
let fun_ ?(loc = default_loc) ?(attrs = []) ?(async = false) ~arity pat exp =
@@ -108,6 +118,7 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn
108118
{
109119
funct = fn;
110120
args = Ext_list.map args (fun (l, a) -> (Asttypes.Labelled l, a));
121+
partial = false;
111122
};
112123
}
113124

compiler/frontend/ast_exp_apply.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
8888
{f with pexp_desc = Pexp_variant (label, Some a); pexp_loc = e.pexp_loc}
8989
| Pexp_construct (ctor, None) ->
9090
{f with pexp_desc = Pexp_construct (ctor, Some a); pexp_loc = e.pexp_loc}
91-
| Pexp_apply {funct = fn1; args} ->
91+
| Pexp_apply {funct = fn1; args; partial} ->
9292
Bs_ast_invariant.warn_discarded_unused_attributes fn1.pexp_attributes;
9393
{
94-
pexp_desc = Pexp_apply {funct = fn1; args = (Nolabel, a) :: args};
94+
pexp_desc =
95+
Pexp_apply {funct = fn1; args = (Nolabel, a) :: args; partial};
9596
pexp_loc = e.pexp_loc;
9697
pexp_attributes = e.pexp_attributes @ f.pexp_attributes;
9798
}
@@ -116,6 +117,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
116117
{
117118
funct = fn;
118119
args = (Nolabel, bounded_obj_arg) :: args;
120+
partial = false;
119121
};
120122
pexp_attributes = [];
121123
pexp_loc = fn.pexp_loc;

compiler/frontend/ast_uncurry_gen.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label
7474
}
7575
[Typ.any ~loc ()]) );
7676
];
77+
partial = false;
7778
}

compiler/frontend/bs_ast_mapper.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,9 @@ module E = struct
320320
fun_ ~loc ~attrs ~arity ~async lab
321321
(map_opt (sub.expr sub) def)
322322
(sub.pat sub p) (sub.expr sub e)
323-
| Pexp_apply {funct = e; args = l} ->
324-
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
323+
| Pexp_apply {funct = e; args = l; partial} ->
324+
apply ~loc ~attrs ~partial (sub.expr sub e)
325+
(List.map (map_snd (sub.expr sub)) l)
325326
| Pexp_match (e, pel) ->
326327
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)
327328
| Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)

compiler/ml/ast_helper.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ module Exp = struct
154154
let fun_ ?loc ?attrs ?(async = false) ~arity a b c d =
155155
mk ?loc ?attrs
156156
(Pexp_fun {arg_label = a; default = b; lhs = c; rhs = d; arity; async})
157-
let apply ?loc ?attrs funct args = mk ?loc ?attrs (Pexp_apply {funct; args})
157+
let apply ?loc ?attrs ?(partial = false) funct args =
158+
mk ?loc ?attrs (Pexp_apply {funct; args; partial})
158159
let match_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_match (a, b))
159160
let try_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_try (a, b))
160161
let tuple ?loc ?attrs a = mk ?loc ?attrs (Pexp_tuple a)

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ module Exp : sig
148148
val apply :
149149
?loc:loc ->
150150
?attrs:attrs ->
151+
?partial:bool ->
151152
expression ->
152153
(arg_label * expression) list ->
153154
expression

compiler/ml/ast_mapper.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ module E = struct
283283
fun_ ~loc ~attrs ~arity ~async lab
284284
(map_opt (sub.expr sub) def)
285285
(sub.pat sub p) (sub.expr sub e)
286-
| Pexp_apply {funct = e; args = l} ->
287-
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
286+
| Pexp_apply {funct = e; args = l; partial} ->
287+
apply ~loc ~attrs ~partial (sub.expr sub e)
288+
(List.map (map_snd (sub.expr sub)) l)
288289
| Pexp_match (e, pel) ->
289290
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)
290291
| Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)

compiler/ml/ast_mapper_from0.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,18 @@ module E = struct
310310
(sub.pat sub p) (sub.expr sub e)
311311
| Pexp_function _ -> assert false
312312
| Pexp_apply (e, l) ->
313-
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
313+
let process_partial_app_attribute attrs =
314+
let rec process partial_app acc attrs =
315+
match attrs with
316+
| [] -> (partial_app, List.rev acc)
317+
| ({Location.txt = "res.partial"}, _) :: rest -> process true acc rest
318+
| attr :: rest -> process partial_app (attr :: acc) rest
319+
in
320+
process false [] attrs
321+
in
322+
let partial, attrs = process_partial_app_attribute attrs in
323+
apply ~loc ~attrs ~partial (sub.expr sub e)
324+
(List.map (map_snd (sub.expr sub)) l)
314325
| Pexp_match (e, pel) ->
315326
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)
316327
| Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)

0 commit comments

Comments
 (0)