Skip to content

Commit 29f7bc5

Browse files
cknittclaude
andcommitted
Share the module await removal
Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6f30758 commit 29f7bc5

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎compiler/frontend/bs_builtin_ppx.ml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,8 @@ let structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t) =
849849
shapes specially, e.g. a module path in [module type of] or [()] as the
850850
argument of a generative functor. *)
851851
let module_expr_mapper (self : mapper) (me : Parsetree.module_expr) =
852-
match me.pmod_desc with
853-
| Pmod_await inner ->
854-
self.module_expr self
855-
{inner with pmod_attributes = me.pmod_attributes @ inner.pmod_attributes}
856-
| _ -> default_mapper.module_expr self me
852+
let _, me = Ast_await.remove_awaits false me in
853+
default_mapper.module_expr self me
857854

858855
let mapper : mapper =
859856
{

‎compiler/ml/ast_await.ml‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ let is_await_expr (e : Parsetree.expression) =
2525
true
2626
| _ -> false
2727

28+
(* [m] without its outer awaits, e.g. [await (await M)], whose attributes
29+
(e.g. [@warning]) stay on the module they wrap, and whether it had any
30+
([awaited] for the awaits already removed) *)
31+
let rec remove_awaits awaited (m : Parsetree.module_expr) =
32+
match m.pmod_desc with
33+
| Pmod_await inner ->
34+
remove_awaits true
35+
{inner with pmod_attributes = m.pmod_attributes @ inner.pmod_attributes}
36+
| _ -> (awaited, m)
37+
2838
(* An awaited module path: [await M], and [await (M: S)] or [(await M: S)],
2939
where [await] may be repeated, e.g. [await (await M)]. Returns the path of
3040
[M]; the module to import, which is [e] without its awaits, whose
3141
attributes (e.g. [@warning]) stay on the module they wrap; and [S] for the
3242
constrained forms. It is a dynamic import when [S] is absent or a module
3343
type path. *)
3444
let awaited_module_path (e : Parsetree.module_expr) =
35-
let rec remove_awaits awaited (m : Parsetree.module_expr) =
36-
match m.pmod_desc with
37-
| Pmod_await inner ->
38-
remove_awaits true
39-
{inner with pmod_attributes = m.pmod_attributes @ inner.pmod_attributes}
40-
| _ -> (awaited, m)
41-
in
4245
match remove_awaits false e with
4346
| true, ({pmod_desc = Pmod_ident lid} as imported) ->
4447
Some (lid, imported, None)

0 commit comments

Comments
 (0)