Skip to content

Commit c90f3d9

Browse files
committed
wip: await AST
1 parent 41e41b9 commit c90f3d9

24 files changed

+90
-71
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,12 @@ let rec exprToContextPathInner ~(inJsxContext : bool) (e : Parsetree.expression)
312312
if List.length exprs = List.length exprsAsContextPaths then
313313
Some (CTuple exprsAsContextPaths)
314314
else None
315+
| Pexp_await e -> exprToContextPathInner ~inJsxContext e
315316
| _ -> None
316317

317318
and exprToContextPath ~(inJsxContext : bool) (e : Parsetree.expression) =
318319
match
319-
( Res_parsetree_viewer.has_await_attribute e.pexp_attributes,
320+
( Res_parsetree_viewer.has_await_attribute e,
320321
exprToContextPathInner ~inJsxContext e )
321322
with
322323
| true, Some ctxPath -> Some (CPAwait ctxPath)

analysis/src/Utils.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ let identifyPexp pexp =
111111
| Pexp_pack _ -> "Pexp_pack"
112112
| Pexp_extension _ -> "Pexp_extension"
113113
| Pexp_open _ -> "Pexp_open"
114+
| Pexp_await _ -> "Pexp_await"
114115

115116
let identifyPpat pat =
116117
match pat with

compiler/frontend/bs_ast_mapper.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ module E = struct
366366
| Pexp_open (ovf, lid, e) ->
367367
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
368368
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
369+
| Pexp_await e -> await ~loc ~attrs (sub.expr sub e)
369370
end
370371

371372
module P = struct

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 12 additions & 9 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_attribute pmod_attributes ->
180+
when Res_parsetree_viewer.has_await_attribute2 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_attribute attrs1
205-
|| Res_parsetree_viewer.has_await_attribute attrs2 ->
204+
when Res_parsetree_viewer.has_await_attribute2 attrs1
205+
|| Res_parsetree_viewer.has_await_attribute2 attrs2 ->
206206
{
207207
e with
208208
pexp_desc =
@@ -242,10 +242,12 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
242242
|| Ast_attributes.has_await_payload attrs2 ->
243243
check_await ();
244244
result
245-
| _ when Ast_attributes.has_await_payload e.pexp_attributes ->
246-
check_await ();
247-
Ast_await.create_await_expression result
248-
| _ -> result
245+
| _ -> (
246+
match result.pexp_desc with
247+
| Pexp_await e ->
248+
check_await ();
249+
Ast_await.create_await_expression e
250+
| _ -> result)
249251

250252
let typ_mapper (self : mapper) (typ : Parsetree.core_type) =
251253
Ast_core_type_class_type.typ_mapper self typ
@@ -493,7 +495,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
493495
| Pstr_module
494496
({pmb_expr = {pmod_desc = Pmod_ident {txt; loc}; pmod_attributes} as me}
495497
as mb)
496-
when Res_parsetree_viewer.has_await_attribute pmod_attributes ->
498+
when Res_parsetree_viewer.has_await_attribute2 pmod_attributes ->
497499
let item = self.structure_item self item in
498500
let safe_module_type_name = local_module_type_name txt in
499501
let has_local_module_name =
@@ -544,7 +546,8 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
544546
( _,
545547
({pmod_desc = Pmod_ident {txt; loc}; pmod_attributes} as me),
546548
expr )
547-
when Res_parsetree_viewer.has_await_attribute pmod_attributes -> (
549+
when Res_parsetree_viewer.has_await_attribute2 pmod_attributes
550+
-> (
548551
let safe_module_type_name = local_module_type_name txt in
549552
let has_local_module_name =
550553
Hashtbl.find_opt !await_context safe_module_type_name

compiler/ml/ast_helper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module Exp = struct
180180
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
181181
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))
182182
let extension ?loc ?attrs a = mk ?loc ?attrs (Pexp_extension a)
183-
183+
let await ?loc ?attrs a = mk ?loc ?attrs (Pexp_await a)
184184
let case lhs ?guard rhs = {pc_lhs = lhs; pc_guard = guard; pc_rhs = rhs}
185185
end
186186

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ module Exp : sig
210210
val extension : ?loc:loc -> ?attrs:attrs -> extension -> expression
211211

212212
val case : pattern -> ?guard:expression -> expression -> case
213+
val await : ?loc:loc -> ?attrs:attrs -> expression -> expression
213214
end
214215

215216
(** Value declarations *)

compiler/ml/ast_iterator.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ module E = struct
344344
iter_loc sub lid;
345345
sub.expr sub e
346346
| Pexp_extension x -> sub.extension sub x
347+
| Pexp_await e -> sub.expr sub e
347348
end
348349

349350
module P = struct

compiler/ml/ast_mapper.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ module E = struct
329329
| Pexp_open (ovf, lid, e) ->
330330
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
331331
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
332+
| Pexp_await e -> await ~loc ~attrs (sub.expr sub e)
332333
end
333334

334335
module P = struct

compiler/ml/ast_mapper_to0.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ module E = struct
407407
| Pexp_open (ovf, lid, e) ->
408408
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
409409
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
410+
| Pexp_await _ -> (* TODO *) assert false
410411
end
411412

412413
module P = struct

compiler/ml/depend.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ let rec add_expr bv exp =
289289
| Pstr_eval ({pexp_desc = Pexp_construct (c, None)}, _) -> add bv c
290290
| _ -> handle_extension e)
291291
| Pexp_extension e -> handle_extension e
292+
| Pexp_await e -> add_expr bv e
292293

293294
and add_cases bv cases = List.iter (add_case bv) cases
294295

0 commit comments

Comments
 (0)