Skip to content

Preserve callable signatures through IR transformations - #600

Merged
LPTK merged 8 commits into
hkust-taco:hkmc2from
LPTK:codex/pr575-callable-signatures
Oct 30, 2026
Merged

LPTK merged 8 commits into
hkust-taco:hkmc2from
LPTK:codex/pr575-callable-signatures

Conversation

@LPTK

@LPTK LPTK commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

[GPT-6 Astra]

Compiler rewrites could leave a function symbol's erased signature describing its old parameter lists or result convention. This keeps signatures consistent through function generation, capture lifting, eta expansion, dead-parameter elimination, specialization, and tail-call optimization.

  • Store parameters and erasure in a plain FunDefn.Signature. The private FunDefn constructor initializes an unset symbol or checks that it shares the same erasure object; copy enforces the same rule. Body-only rewrites reuse the signature. Copies refresh parameter and definition symbols together, and calling-convention changes use fresh symbols with updated references.
  • Preserve async/generator payload descriptors when only parameters change. Lifted capture wrappers (in the worker-wrapper transformation) forward a Promise, Iterator, or remaining curried function directly, avoiding a second async/generator wrapper.
  • Fix the erased parameter list for lowered variadic functions. For example, f(x, y?, ...xs, z) lowers to f(x, ...args); y, xs, and z become local variables initialized from args. The erased signature must list only x as a fixed parameter; it previously listed both x and y.
  • Give deforestation branch and continuation functions complete signatures before rewriting calls, and preserve the enclosing function's return coercions.

Adds runtime and typed-IR regressions for simple and curried async capture wrappers, generator wrappers, nested specialization, recursive and forward calls, binding refresh during tail-call conversion, and optional/variadic captures. The unsupported unboxed result of an indirect deforestation call remains an explicit :fixme.

Ports the callable-signature changes from #575 (B04: E13, E25–E26, E28).

Validation: Metals compilation and hkmc2AllTests/test — 1,163 tests passed, including the compile-test prerequisites and JS/Wasm regressions. Golden outputs are updated and committed; the complete PR diff was checked for accidental whitespace changes.

codex and others added 5 commits October 30, 2026 19:35
Give generated functions physical signatures and freshen lifted, specialized,
and eta-expanded definitions when their parameter lists change. Preserve
complete result descriptors for parameter-only rewrites, and give capture
wrappers their own direct result. A generator forwarding wrapper must not
wrap the iterator a second time.

Publish deforestation branch and continuation signatures after captures are
known, type nullary closure temporaries, and preserve the enclosing return
boundary when fusion replaces a return with a call. Keep the unsupported
unboxed closure-result case as an explicit regression.

Extract B04 (E13, E25-E26, E28) from hkust-taco#575. E12 constructor typing is deferred
to the optimizer-safety batch because it exposes unsafe optional-field fusion.

Validation: Metals; ctest and cwtest; focused eta, DPE and signature suites;
hkmc2AllTests/test (1,161 tests). Also checked capturing, eta and handler cases
with the separate IR-representation checker temporarily applied. Reviewed the
complete diff and committed regenerated golden outputs.
# Conflicts:
#	hkmc2/shared/src/test/mlscript/basics/MultiParamListClasses.mls
Remove the async annotation from lifted forwarding wrappers so their direct-result signatures match their behavior. Preserve the remaining function for curried async calls.

Add simple and curried capture regressions with runtime expectations and typed IR snapshots. Both fail before the fix and pass afterward.

Validation: Metals compilation; ctest; sdtest CallableSignatures; hkmc2AllTests/test (1,162 tests).

@LPTK LPTK left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM now except for these more minor points.

@LPTK

LPTK commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Once again, some smelly designs were averted. Simplicity must be fought for again and again... Trying to maintain signature info separately from the construction of function definitions was silly, as it required keeping two distant things in sync with thoughts and prayers. FYI @ychenfo.

@LPTK
LPTK merged commit 5091705 into hkust-taco:hkmc2 Oct 30, 2026
1 check passed
@LPTK
LPTK deleted the codex/pr575-callable-signatures branch October 30, 2026 16:02
LPTK pushed a commit to LPTK/mlscript that referenced this pull request Oct 30, 2026
Integrate hkust-taco#599 and hkust-taco#600 while preserving inferred erasure and
representation-changing deforestation. Reconcile shared function signatures
with retyped and refreshed bindings, retain inferred wrapper regressions,
and adapt the cast-comment fixtures to inference and cast elimination.

Update the extraction plan and include regenerated golden outputs.

Validation: Metals hkmc2JVM compilation and hkmc2AllTests/test (1,172 tests).
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.

2 participants