You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 23a4197
Browse filesBrowse the repository at this point in the historyBrowse files
Represent await on module expressions with a Pmod_await node (#8738)
* Represent await on module expressions with a Pmod_await node
`await M` on a module expression was stored as a `res.await` attribute
on M, while expressions already have `Pexp_await`. Add `Pmod_await` and
have the parser produce it, so `res.await` only remains in the v0 PPX
wire representation: `Ast_mapper_to0` writes it like for `Pexp_await`
(the await node's attributes, the marker, then the inner module's) and
`Ast_mapper_from0` splits them again.
The frontend recognizes awaited module paths structurally
(`Ast_await.awaited_module_path`) for the dynamic import rewrite and the
async context check. Any other `await` on a module still has no effect:
the type checker types `Pmod_await M` as `M`. Errors on an awaited
module now point at the whole `await M`.
The printer no longer special-cases a `res.await` attribute: `await` is
printed by its own node, which also lets `await @w (await X)` and
`@w (await X)` round-trip. Formatting of existing code is unchanged.
Bump the current AST magic numbers for the new constructor.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Add CHANGELOG link for #8738
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Detect doc comments on awaited functor arguments
An await node's own attributes print before it, so a doc comment on it starts the printed argument: F((/** doc */ (await X))) printed as F(/** doc */ (await X)), which doesn't parse. Only a functor's attributes print elsewhere (on its first parameter).
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Keep await locations across v0 and attributes in dynamic imports
The v0 bridge folds an await node and its operand into one node, marked
with `res.await`. The marker was written without a location, so after a
round trip through an external PPX the await node took its operand's
location and lost the span of the `await` keyword. Store the await
node's location on the marker, like `res.braces` does, and restore it,
falling back to the node's location for markers without one. This also
applies to `Pexp_await`, which had the same problem.
The dynamic import rewrite replaced an await node with its operand and
dropped the await node's attributes, e.g. a `@warning` in
`(@warning("-3") (await List): ListT)` as a PPX may produce it. Keep them
on the imported module, as when await was an attribute.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Recognize nested awaits as dynamic imports
`module M = await (await List)` used to be a dynamic import: both awaits
became `res.await` attributes on the same node. With `Pmod_await` it is
two nested nodes, and the dynamic import forms only looked through one,
so it silently became a static module reference and skipped the async
context check. `Ast_await.awaited_module_path` now looks through any
number of awaits around the module path and around the constraint, and
the toplevel and local module type pre-scans use it too.
`create_await_module_expression` removes nested awaits as well.
Compiling 19 module await forms in 5 contexts gives the same JavaScript
and errors as master.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Simplify the module dynamic import rewrite
`awaited_module_path` and `create_await_module_expression` each removed
the awaits around a dynamic import, the second time keeping their
attributes. `awaited_module_path` now returns the module to import with
its awaits removed and their attributes kept, and
`create_await_module_expression` just packs it.
The toplevel and local module cases each declared
`module type __List__ = module type of List` once per module with the
same code; it is now `local_module_type_decl`. Both callers bind its
result before mapping the rest, since a later import of the same module
must find it already declared.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Respect @warning on the module in module type of
`type_module_type_of` looked a module path up without the warning scope
of the module's attributes, unlike `type_module`, so
`module type of @warning("-3") DeprecatedModule` still reported warning 3.
That includes the `module type __M__ = module type of M` a dynamic import
declares, so `module M = @warning("-3") (await DeprecatedModule)` reported
it too (also before `Pmod_await`). Look the module up in that scope.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove no-op module awaits before type checking
Outside the dynamic import forms, `await` on a module has no effect; as
a `res.await` attribute it was invisible to the type checker. As a
`Pmod_await` node it hid the module's shape where the type checker
treats shapes specially: `module type of await M` was strengthened
(abstract types became `M.t`) instead of taking the unstrengthened
module path, and `F(await {})` was rejected for a generative functor.
Like `Pexp_await`, which never reaches the type checker, the builtin
ppx now removes the remaining awaits after the dynamic import rewrite,
keeping their attributes on the module they wrap. The type checker's
`Pmod_await` case only remains for trees that bypass it.
Type checking every input of the module expression round-trip harness
(7950 cases) gives the same exit codes, JavaScript and errors as master.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Share the module await removal
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Keep the legacy v0 attribute order of module await
PPXs saw await on a module as the res.await attribute, after the module's
own attributes and before those written after await or around the await:
[await @b (@A M)] was [@A; res.await; @b]. The attributes after await now
belong to the Pmod_await node, as those of [@b (await M)] already did, and
the v0 bridge emits them in that order. The printer prints an await's
attributes after await and parenthesizes an attributed operand.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Name the module await helper Mod.await
The trailing underscore in Ast_helper is for OCaml keywords, as in
Mod.functor_ and Mod.constraint_; await isn't one, and the expression helper
is Exp.await.
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Signed-off-by: Christoph Knittel <christoph@knittel.cc>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@
23
23
24
24
#### :bug: Bug fix
25
25
26
+
- Respect `@warning` attributes on the module in `module type of`, e.g. `module type of @warning("-3") DeprecatedModule`, which still reported the warning. https://github.com/rescript-lang/rescript/pull/8738
26
27
- Fix the formatter dropping or moving attributes and `await` on module expressions, such as `module M = @attr F(X)`, and printing invalid code for module constraints and functors in some positions, such as `module M: T = (X: S)`. https://github.com/rescript-lang/rescript/pull/8735
27
28
- Make rewatch compile independent modules after an unrelated failure and recompile blocked dependents when a changed interface survives a failed implementation, including across full watcher rebuilds. https://github.com/rescript-lang/rescript/pull/8667
28
29
- Fix `RescriptTools.binaryPath` failing with `ERR_PACKAGE_IMPORT_NOT_DEFINED` when used from a user project. https://github.com/rescript-lang/rescript/pull/8694
@@ -44,6 +45,7 @@
44
45
45
46
#### :house: Internal
46
47
48
+
- Represent `await` on module expressions with a dedicated `Pmod_await` parsetree node instead of a `res.await` attribute, which remains only in the PPX wire representation. https://github.com/rescript-lang/rescript/pull/8738
47
49
- Remove dead compiler code: warning 24, the `J.String_index` JS IR node, the `Pisint` and `Parraysets` Lambda primitives with their unused `%` primitive names (`%obj_is_int`, `%obj_dup`, `%obj_field`, `%array_safe_set`, `%null_to_opt`, `%nullable_to_opt`), the no-op `-pp` bsc flag and unread `Clflags` fields (`-unsafe` stays accepted as an explicit no-op), and the unused `unit` slot of `Pexp_coerce`. https://github.com/rescript-lang/rescript/pull/8731
48
50
- Represent inline record definitions with an explicit parsetree origin while retaining the existing PPX wire representation. https://github.com/rescript-lang/rescript/pull/8686
49
51
- Make expression attributes immutable in the current parsetree, now that editor refactors construct new expression nodes. https://github.com/rescript-lang/rescript/pull/8685
0 commit comments