Skip to content

Commit 2511e48

Browse files
committed
cleanup
1 parent 8e62cd5 commit 2511e48

File tree

8 files changed

+27
-46
lines changed

8 files changed

+27
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367
2626
- Convert internal JavaScript codebase into ESM, ReScript package itself is now ESM (`"type": "module"`). https://github.com/rescript-lang/rescript/pull/6899
2727
- Add built-in support for the JavaScript `in` operator. https://github.com/rescript-lang/rescript/pull/7342
28+
- AST cleanup: add `Pexp_await` ast node instead of `res.await` attribute. (The attribute is still used for await on modules currently).
2829

2930
#### :nail_care: Polish
3031

analysis/src/CompletionFrontEnd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ let rec exprToContextPathInner ~(inJsxContext : bool) (e : Parsetree.expression)
317317

318318
and exprToContextPath ~(inJsxContext : bool) (e : Parsetree.expression) =
319319
match
320-
( Res_parsetree_viewer.has_await_attribute e,
320+
( Res_parsetree_viewer.expr_is_await e,
321321
exprToContextPathInner ~inJsxContext e )
322322
with
323323
| true, Some ctxPath -> Some (CPAwait ctxPath)

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
177177
(* module M = await Belt.List *)
178178
| Pexp_letmodule
179179
(lid, ({pmod_desc = Pmod_ident {txt}; pmod_attributes} as me), expr)
180-
when Res_parsetree_viewer.has_await_attribute2 pmod_attributes ->
180+
when Res_parsetree_viewer.has_await_attribute pmod_attributes ->
181181
let safe_module_type_lid : Ast_helper.lid =
182182
{txt = Lident (local_module_type_name txt); loc = me.pmod_loc}
183183
in
@@ -201,8 +201,8 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
201201
pmod_attributes = attrs2;
202202
} as me),
203203
expr )
204-
when Res_parsetree_viewer.has_await_attribute2 attrs1
205-
|| Res_parsetree_viewer.has_await_attribute2 attrs2 ->
204+
when Res_parsetree_viewer.has_await_attribute attrs1
205+
|| Res_parsetree_viewer.has_await_attribute attrs2 ->
206206
{
207207
e with
208208
pexp_desc =
@@ -495,7 +495,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
495495
| Pstr_module
496496
({pmb_expr = {pmod_desc = Pmod_ident {txt; loc}; pmod_attributes} as me}
497497
as mb)
498-
when Res_parsetree_viewer.has_await_attribute2 pmod_attributes ->
498+
when Res_parsetree_viewer.has_await_attribute pmod_attributes ->
499499
let item = self.structure_item self item in
500500
let safe_module_type_name = local_module_type_name txt in
501501
let has_local_module_name =
@@ -546,8 +546,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
546546
( _,
547547
({pmod_desc = Pmod_ident {txt; loc}; pmod_attributes} as me),
548548
expr )
549-
when Res_parsetree_viewer.has_await_attribute2 pmod_attributes
550-
-> (
549+
when Res_parsetree_viewer.has_await_attribute pmod_attributes -> (
551550
let safe_module_type_name = local_module_type_name txt in
552551
let has_local_module_name =
553552
Hashtbl.find_opt !await_context safe_module_type_name

compiler/ml/ast_uncurried.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,3 @@ let expr_is_uncurried_fun (expr : Parsetree.expression) =
1919
match expr.pexp_desc with
2020
| Pexp_fun {arity = Some _} -> true
2121
| _ -> false
22-
23-
let expr_extract_uncurried_fun (expr : Parsetree.expression) =
24-
match expr.pexp_desc with
25-
| Pexp_fun {arity = Some _} -> expr
26-
| _ -> assert false

compiler/syntax/src/res_parens.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let call_expr expr =
5656
} ->
5757
Parenthesized
5858
| _ when Ast_uncurried.expr_is_uncurried_fun expr -> Parenthesized
59-
| _ when ParsetreeViewer.has_await_attribute expr -> Parenthesized
59+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
6060
| _ -> Nothing)
6161

6262
let structure_expr expr =
@@ -108,7 +108,7 @@ let unary_expr_operand expr =
108108
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
109109
} ->
110110
Parenthesized
111-
| _ when ParsetreeViewer.has_await_attribute expr -> Parenthesized
111+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
112112
| _ -> Nothing)
113113

114114
let binary_expr_operand ~is_lhs expr =
@@ -131,7 +131,7 @@ let binary_expr_operand ~is_lhs expr =
131131
| expr when ParsetreeViewer.is_binary_expression expr -> Parenthesized
132132
| expr when ParsetreeViewer.is_ternary_expr expr -> Parenthesized
133133
| {pexp_desc = Pexp_lazy _ | Pexp_assert _} when is_lhs -> Parenthesized
134-
| _ when ParsetreeViewer.has_await_attribute expr -> Parenthesized
134+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
135135
| {Parsetree.pexp_attributes = attrs} ->
136136
if ParsetreeViewer.has_printable_attributes attrs then Parenthesized
137137
else Nothing)
@@ -226,7 +226,7 @@ let lazy_or_assert_or_await_expr_rhs ?(in_await = false) expr =
226226
| Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
227227
} ->
228228
Parenthesized
229-
| _ when (not in_await) && ParsetreeViewer.has_await_attribute expr ->
229+
| _ when (not in_await) && ParsetreeViewer.expr_is_await expr ->
230230
Parenthesized
231231
| _ -> Nothing)
232232

@@ -272,7 +272,7 @@ let field_expr expr =
272272
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
273273
} ->
274274
Parenthesized
275-
| _ when ParsetreeViewer.has_await_attribute expr -> Parenthesized
275+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
276276
| _ -> Nothing)
277277

278278
let set_field_expr_rhs expr =
@@ -333,7 +333,7 @@ let jsx_prop_expr expr =
333333
}
334334
when starts_with_minus x ->
335335
Parenthesized
336-
| _ when ParsetreeViewer.has_await_attribute expr -> Parenthesized
336+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
337337
| {
338338
Parsetree.pexp_desc =
339339
( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _
@@ -370,7 +370,7 @@ let jsx_child_expr expr =
370370
}
371371
when starts_with_minus x ->
372372
Parenthesized
373-
| _ when ParsetreeViewer.has_await_attribute expr -> Parenthesized
373+
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
374374
| {
375375
Parsetree.pexp_desc =
376376
( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,17 @@ let functor_type modtype =
6565
in
6666
process [] modtype
6767

68-
let has_await_attribute2 attrs =
68+
let has_await_attribute attrs =
6969
List.exists
7070
(function
7171
| {Location.txt = "res.await"}, _ -> true
7272
| _ -> false)
7373
attrs
7474

75-
let has_await_attribute e =
76-
(match e.pexp_desc with
75+
let expr_is_await e =
76+
match e.pexp_desc with
7777
| Pexp_await _ -> true
78-
| _ -> false)
79-
|| List.exists
80-
(function
81-
| {Location.txt = "res.await"}, _ -> true
82-
| _ -> false)
83-
e.pexp_attributes
78+
| _ -> false
8479

8580
let has_inline_record_definition_attribute attrs =
8681
List.exists
@@ -121,12 +116,7 @@ let collect_list_expressions expr =
121116

122117
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
123118
let rewrite_underscore_apply expr =
124-
let expr_fun =
125-
if Ast_uncurried.expr_is_uncurried_fun expr then
126-
Ast_uncurried.expr_extract_uncurried_fun expr
127-
else expr
128-
in
129-
match expr_fun.pexp_desc with
119+
match expr.pexp_desc with
130120
| Pexp_fun
131121
{
132122
arg_label = Nolabel;

compiler/syntax/src/res_parsetree_viewer.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ val functor_type :
1414
list
1515
* Parsetree.module_type
1616

17-
val has_await_attribute : Parsetree.expression -> bool
18-
val has_await_attribute2 : Parsetree.attributes -> bool
17+
val expr_is_await : Parsetree.expression -> bool
18+
val has_await_attribute : Parsetree.attributes -> bool
1919
val has_inline_record_definition_attribute : Parsetree.attributes -> bool
2020
val has_res_pat_variant_spread_attribute : Parsetree.attributes -> bool
2121
val has_dict_pattern_attribute : Parsetree.attributes -> bool

compiler/syntax/src/res_printer.ml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ and print_module_binding ~state ~is_rec module_binding cmt_tbl i =
700700
match module_binding.pmb_expr with
701701
| {pmod_desc = Pmod_constraint (mod_expr, mod_type)}
702702
when not
703-
(ParsetreeViewer.has_await_attribute2
703+
(ParsetreeViewer.has_await_attribute
704704
module_binding.pmb_expr.pmod_attributes) ->
705705
( print_mod_expr ~state mod_expr cmt_tbl,
706706
Doc.concat [Doc.text ": "; print_mod_type ~state mod_type cmt_tbl] )
@@ -2810,12 +2810,8 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
28102810
return_expr_doc;
28112811
])
28122812
in
2813-
let uncurried = Ast_uncurried.expr_is_uncurried_fun e in
2814-
let e_fun =
2815-
if uncurried then Ast_uncurried.expr_extract_uncurried_fun e else e
2816-
in
28172813
let printed_expression =
2818-
match e_fun.pexp_desc with
2814+
match e.pexp_desc with
28192815
| Pexp_fun
28202816
{
28212817
arg_label = Nolabel;
@@ -2825,7 +2821,7 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
28252821
} ->
28262822
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
28272823
print_expression_with_comments ~state
2828-
(ParsetreeViewer.rewrite_underscore_apply e_fun)
2824+
(ParsetreeViewer.rewrite_underscore_apply e)
28292825
cmt_tbl
28302826
| Pexp_fun _ | Pexp_newtype _ -> print_arrow e
28312827
| Parsetree.Pexp_constant c ->
@@ -3764,7 +3760,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
37643760
(match expr.pexp_desc with
37653761
| Pexp_await _ -> true
37663762
| _ -> false)
3767-
|| ParsetreeViewer.has_await_attribute expr
3763+
|| ParsetreeViewer.expr_is_await expr
37683764
in
37693765
let doc =
37703766
if is_await then
@@ -5301,7 +5297,7 @@ and print_expression_block ~state ~braces expr cmt_tbl =
53015297
match mod_expr.pmod_desc with
53025298
| Pmod_constraint (mod_expr2, mod_type)
53035299
when not
5304-
(ParsetreeViewer.has_await_attribute2 mod_expr.pmod_attributes)
5300+
(ParsetreeViewer.has_await_attribute mod_expr.pmod_attributes)
53055301
->
53065302
let name =
53075303
Doc.concat
@@ -5795,7 +5791,7 @@ and print_mod_expr ~state mod_expr cmt_tbl =
57955791
| Pmod_functor _ -> print_mod_functor ~state mod_expr cmt_tbl
57965792
in
57975793
let doc =
5798-
if ParsetreeViewer.has_await_attribute2 mod_expr.pmod_attributes then
5794+
if ParsetreeViewer.has_await_attribute mod_expr.pmod_attributes then
57995795
match mod_expr.pmod_desc with
58005796
| Pmod_constraint _ ->
58015797
Doc.concat [Doc.text "await "; Doc.lparen; doc; Doc.rparen]

0 commit comments

Comments
 (0)