Async JavaScript interop - #554
Merged
Merged
Conversation
LPTK
approved these changes
Aug 27, 2026
LPTK
left a comment
Contributor
There was a problem hiding this comment.
Otherwise LGTM. Nice little feature, thanks!
It's nice that we can call await anywhere and just add @async wrappers at the places we want them to be handled.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds effect-backed JavaScript Promise interop through await and @async.
Changes:
- Adds async annotation elaboration and lowering.
- Implements Promise/effect runtime bridging.
- Adds diff-test support and async integration tests.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
hkmc2DiffTests/src/test/scala/hkmc2/JSBackendDiffMaker.scala |
Adds :await test directive. |
hkmc2/shared/src/test/mlscript/invalml/InvalMLPrelude.mls |
Declares async annotation. |
hkmc2/shared/src/test/mlscript/handlers/Async.mls |
Tests async interop and failures. |
hkmc2/shared/src/test/mlscript/decls/Prelude.mls |
Declares async annotation. |
hkmc2/shared/src/test/mlscript-compile/Runtime.mls |
Implements async effect runtime. |
hkmc2/shared/src/test/mlscript-compile/Runtime.mjs |
Updates generated runtime. |
hkmc2/shared/src/test/mlscript-compile/Predef.mls |
Exposes await. |
hkmc2/shared/src/test/mlscript-compile/Predef.mjs |
Updates generated prelude. |
hkmc2/shared/src/main/scala/hkmc2/semantics/Term.scala |
Adds the async annotation model. |
hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala |
Resolves @async. |
hkmc2/shared/src/main/scala/hkmc2/codegen/Lowering.scala |
Lowers async expressions. |
hkmc2/shared/src/main/scala/hkmc2/codegen/CompilationPipeline.scala |
Registers async lowering. |
hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala |
Tracks async function metadata. |
hkmc2/shared/src/main/scala/hkmc2/AsyncLowering.scala |
Generates Promise-returning wrappers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements two-sided interop for JavaScript async.
To consume a JavaScript promise/async function, the
Predef.await()function will convert a promise into an effect.To produce a JavaScript promise/async function, the
@asyncannotation can be used.@async <computation>will result in a JavaScript promise and@async fun f() = ...will define an async function effectively.