Skip to content

docs: Notes for the laziness runtime contract (#44)#127

Merged
Unisay merged 2 commits into
mainfrom
issue-44/notes-laziness
Jun 25, 2026
Merged

docs: Notes for the laziness runtime contract (#44)#127
Unisay merged 2 commits into
mainfrom
issue-44/notes-laziness

Conversation

@Unisay

@Unisay Unisay commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Continues #44, the laziness batch. The runtime-lazy path is the part of the compiler most exposed to silent breakage (the bug fixed in #126 lived here and went unnoticed because nothing documented or tested the contract). This batch documents that contract and corrects two stale comments. Comments only, so generated code, goldens, and eval oracles are unchanged.

  • Note [The runtimeLazy calling convention] in Backend.Lua.Fixture. The fixture side had no comment at all. The Note spells out the curried PSLUA_runtime_lazy(name)(init)(line) shape, and in particular why state and val must live in the function(init) closure rather than the forcing thunk (declaring them in the thunk is exactly what broke memoization in fix: PSLUA_runtime_lazy did not memoize (state reset on every force) #126). It also points back at the two transform sites that must keep the arity in step.

  • Note [Laziness transform for recursive binding groups] in CoreFn.Laziness. The module had a thorough overview comment but no titled anchor, so nothing could cite the transform by name. This adds a short anchor that points at the existing prose.

  • Corrected two comments inherited from the upstream JS backend that no longer match this port: the factory is applied to two arguments here (identifier, thunk), not three (the JS backend also threads the module name), and the Lua fixture ignores the line number passed to a force call (the JS backend uses it in the loop error message).

A note on scope

CoreFn.Laziness is adapted from the upstream purs compiler, and the issue asks to weigh divergence before retitling its comments. The delay/force and USE-INIT/USE-USE/USE-IMMEDIATE rules there are already documented thoroughly and are only cited from within the file, so I deliberately left that prose untouched rather than wrap it in Note blocks for marginal intra-file benefit. The cross-module contract (the runtime-lazy convention) is where the citable Note earns its keep, and the fixture half of it is our own code.

Checklist

  • Added a changelog.d/ fragment for any user-facing change (scriv create
    in the dev shell), or this change ships nothing releasable (CI, docs, or an
    internal refactor).
  • In the dev shell (nix develop), fourmolu -i lib/ exe/ test/ and
    hlint lib/ exe/ test/ are clean.
  • In the dev shell, cabal test all passes; structural goldens were
    re-accepted on purpose if codegen moved (PSLUA_GOLDEN_ACCEPT=1), and
    eval/golden.txt still holds.

- Note [The runtimeLazy calling convention] (Backend.Lua.Fixture): the
  curried name -> init -> force shape and why state/val must live in the
  function(init) closure (the scope error fixed in #126). Points at the
  two transform sites that must match the arity.
- Note [Laziness transform for recursive binding groups] (CoreFn.Laziness):
  a citable anchor for the transform; the detailed upstream-adapted prose is
  left untouched (delay/force and init-order rules) to avoid divergence.
- Correct two comments inherited from the JS backend: the Lua factory takes
  two arguments (not three; the JS one also threads the module name), and the
  Lua fixture ignores the force-call line number.

Comments only; no change to generated code. Continues #44.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the #44 “Notes” effort by documenting the cross-module laziness runtime contract (the ABI between the CoreFn laziness transform and the Lua runtime fixture) and updating a couple of previously-stale explanatory comments, with no intended change to generated code or goldens.

Changes:

  • Added Note [The runtimeLazy calling convention] to the Lua fixture to document the PSLUA_runtime_lazy curried convention and the memoization/cycle-detection scope invariant for state/val.
  • Added a citable anchor Note [Laziness transform for recursive binding groups] to CoreFn.Laziness.
  • Updated two existing comments to reflect Lua-vs-JS backend differences (factory arity and fixture line-number usage).

Reviewed changes

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

File Description
lib/Language/PureScript/CoreFn/Laziness.hs Adds a named Note anchor and updates commentary around runtimeLazy factory/force-call expectations.
lib/Language/PureScript/Backend/Lua/Fixture.hs Documents the runtime-lazy calling convention and the required closure scoping for memoization/cycle detection.
changelog.d/20260625_191608_unisay_notes_laziness.md Adds a changelog fragment describing the documentation additions/clarifications.

Comment thread lib/Language/PureScript/CoreFn/Laziness.hs Outdated
Comment thread lib/Language/PureScript/Backend/Lua/Fixture.hs Outdated
@Unisay Unisay marked this pull request as ready for review June 25, 2026 17:56
@Unisay Unisay merged commit a2832b4 into main Jun 25, 2026
2 checks passed
@Unisay Unisay deleted the issue-44/notes-laziness branch June 25, 2026 17:56
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