Skip to content

Async JavaScript interop - #554

Merged
LPTK merged 14 commits into
hkust-taco:hkmc2from
AnsonYeung:js-async
Aug 29, 2026
Merged

Async JavaScript interop#554
LPTK merged 14 commits into
hkust-taco:hkmc2from
AnsonYeung:js-async

Conversation

@AnsonYeung

Copy link
Copy Markdown
Contributor

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 @async annotation can be used. @async <computation> will result in a JavaScript promise and @async fun f() = ... will define an async function effectively.

@LPTK LPTK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread hkmc2/shared/src/test/mlscript/handlers/Async.mls
@LPTK
LPTK requested a balanced review from Copilot August 28, 2026 02:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread hkmc2/shared/src/test/mlscript-compile/Runtime.mls Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/CompilationPipeline.scala
Comment thread hkmc2/shared/src/test/mlscript/handlers/Async.mls Outdated
Comment thread hkmc2/shared/src/test/mlscript-compile/Runtime.mjs Outdated
@LPTK
LPTK merged commit cb2ce85 into hkust-taco:hkmc2 Aug 29, 2026
1 check passed
@LPTK
LPTK deleted the js-async branch August 29, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants