Skip to content

Various Bug Fixes and Tailrec Cleanup - #553

Merged
LPTK merged 15 commits into
hkust-taco:hkmc2from
CAG2Mark:bug-fixes
Aug 28, 2026
Merged

Various Bug Fixes and Tailrec Cleanup#553
LPTK merged 15 commits into
hkust-taco:hkmc2from
CAG2Mark:bug-fixes

Conversation

@CAG2Mark

Copy link
Copy Markdown
Contributor
  • Fixed two possible dormant bugs in the handler runtime where the continuation chain was not unlinked/relinked properly. (I only discovered these bugs when re-using the handler runtime for the shadow stack handler experimentation.) CC @AnsonYeung
  • Made the tailrec pass idempotent by rewriting known calls to functions within each SCC into calls to the merged loop definition and added the corresponding tests.
  • Cleaned up and refactored some logic in the tailrec pass to make it less error-prone.

@CAG2Mark CAG2Mark changed the title Various Bug Fixes Various Bug Fixes and Tailrec Cleanup Aug 27, 2026
@CAG2Mark

Copy link
Copy Markdown
Contributor Author

Typo in the latest commit, it should be "make worker private". It seems making the worker private actually enables some optimizations.

@CAG2Mark
CAG2Mark requested a review from LPTK August 27, 2026 09:19
@LPTK
LPTK requested a review from AnsonYeung August 27, 2026 12:47
Comment thread hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls
Comment thread hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls Outdated
@CAG2Mark

Copy link
Copy Markdown
Contributor Author

It seems the wrappers for the mutually tail-recursive function definitions were never given the inline annotation, so I've added that now

@LPTK
LPTK requested a balanced review from Copilot August 27, 2026 13:59

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

Fixes handler continuation-chain bookkeeping and makes tail-recursion optimization idempotent.

Changes:

  • Corrects handler frame unlinking and relinking.
  • Rewrites recursive SCC calls to merged loop functions.
  • Adds and updates tail-recursion golden tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Block.scala Adds flattened function parameter symbols.
TailRecOpt.scala Refactors argument handling and SCC rewriting.
Runtime.mls Fixes continuation-chain bookkeeping.
Runtime.mjs Regenerates compiled runtime output.
TailRecOpt.mls Adds idempotence coverage and snapshots.
MultiArgLists.mls Adds curried/spread-call coverage and snapshots.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala Outdated
Comment thread hkmc2/shared/src/test/mlscript-compile/Runtime.mls
Comment thread hkmc2/shared/src/test/mlscript/tailrec/MultiArgLists.mls Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala Outdated
Comment thread hkmc2/shared/src/main/scala/hkmc2/codegen/TailRecOpt.scala Outdated

@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.

LGTM, thanks!

@LPTK
LPTK merged commit 375553a into hkust-taco:hkmc2 Aug 28, 2026
1 check passed
@LPTK
LPTK deleted the bug-fixes branch August 28, 2026 06:30
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.

4 participants