Title: Emission-time renumbering of compiler-minted locals: keep supply history out of artifacts · Issue #306 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Emission-time renumbering of compiler-minted locals: keep supply history out of artifacts · Issue #306 · purescript-lua/purescript-lua
X Title: Emission-time renumbering of compiler-minted locals: keep supply history out of artifacts · Issue #306 · purescript-lua/purescript-lua
Description: Problem Compiler-minted local names leak pipeline history into the emitted Lua text. Fresh names are drawn as x$N (rendered x_S_N by the Lua name mangler) from one monotone supply threaded through the whole IR pipeline — the uniquify pas...
Open Graph Description: Problem Compiler-minted local names leak pipeline history into the emitted Lua text. Fresh names are drawn as x$N (rendered x_S_N by the Lua name mangler) from one monotone supply threaded through ...
X Description: Problem Compiler-minted local names leak pipeline history into the emitted Lua text. Fresh names are drawn as x$N (rendered x_S_N by the Lua name mangler) from one monotone supply threaded through ...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/306
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Emission-time renumbering of compiler-minted locals: keep supply history out of artifacts","articleBody":"## Problem\n\nCompiler-minted local names leak pipeline history into the emitted Lua text. Fresh names are drawn as `x$N` (rendered `x_S_N` by the Lua name mangler) from one monotone supply threaded through the whole IR pipeline — the uniquify pass, freshening on inline pastes, CSE, uncurrying all consume it — so any change that shifts the *count* of names consumed early in a module renames every later binder by a constant offset, even in code the change never touched. PR #304 showed the cost at review time: of the 26 golden modules that moved, several changed in nothing but indices (e.g. `Golden.NativeLoopsGuard`'s `v_S_1437 → v_S_1440` — the modules merely import `unsafe-coerce` transitively, and the newly lifted `λx. x` binder consumes supply indices where the binder-free accessor consumed none). This alpha-only churn is pure noise in golden diffs, inflates every optimizer PR's review surface, and forces `PSLUA_GOLDEN_ACCEPT` runs for changes that are semantically identity.\n\n## Approach\n\nNormalize at emission, not in the IR: the supply must stay global — the pipeline's unique-binders invariant (GUC) depends on it — so quarantine the fix in a late `Chunk → Chunk` pass that runs after every name-minting Lua-level transform (localization/promotion, loopification) and immediately before the printer. The pass walks the chunk and renumbers every `$N`-suffixed local binder in first-occurrence order, rewriting its references; unsuffixed names are untouched. The domain is well-defined because PureScript identifiers cannot contain `$`, so a `$`-suffix marks a compiler-minted name exclusively; sequential renumbering preserves uniqueness, so the pre-existing no-capture property carries over unchanged. Emitted names thereby become a function of the artifact's own structure — byte-stable under any upstream change that only perturbs supply consumption. Nothing semantic reads these names: FFI tables key exports by export name, the runtime-lazy factory is keyed by a string literal, and the locals/upvalue budget counting is name-agnostic. Landing the pass causes a one-time whole-corpus golden renumbering, accepted once; a possible follow-up (out of scope here) is dropping the suffix entirely where the base name is unambiguous in scope, which needs real shadowing analysis rather than renumbering.\n\n## Prerequisites / Relations\n\nIndependent. Sibling of the emission-ergonomics issues #276 (no width bound on emitted lines) and #273 (lua-language-server diagnostics on call sites); reduces the golden-churn class that #303 discusses from the harness side.\n\n## Verification / Measurement\n\nThe red is demonstrable as a differential: burn a synthetic offset of supply indices at pipeline start (a test-only knob or a prepended dummy binder) and recompile the golden corpus — today every module's `golden.lua` churns in indices; with the pass, all artifacts are byte-identical under the perturbation. Plus: the pass is idempotent (normalizing twice equals once), `luacheck` stays clean, and every hand-verified eval oracle is unchanged — renumbering is alpha-renaming by construction, and the eval goldens prove it on the corpus.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-26T15:54:59Z","url":"https://github.com/purescript-lua/purescript-lua/issues/306"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:239a534c-69b6-a29a-eb29-22601acf700c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C94C:21AC3F:A05DD6:CEDBE8:6B00DFB6 |
| html-safe-nonce | 73cfce426af93a04b46d4c77a6b4323ae26ae242a6c917e9ec9484fc79acf6b0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOTRDOjIxQUMzRjpBMDVERDY6Q0VEQkU4OjZCMDBERkI2IiwidmlzaXRvcl9pZCI6IjY1NzM3NzU3ODEzOTMxMjkzOTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e609e975f611a159a33c1916c0f45258d47ee66448ce7d6f821228b83366846b |
| hovercard-subject-tag | issue:4981336690 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/306/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6f2388907cb7ea46945d84fe41948ee3fcd2ff7261b4ca5060215e256e30ae3d/purescript-lua/purescript-lua/issues/306 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6f2388907cb7ea46945d84fe41948ee3fcd2ff7261b4ca5060215e256e30ae3d/purescript-lua/purescript-lua/issues/306 |
| og:image:alt | Problem Compiler-minted local names leak pipeline history into the emitted Lua text. Fresh names are drawn as x$N (rendered x_S_N by the Lua name mangler) from one monotone supply threaded through ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Unisay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 587200487 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 587200487 |
| octolytics-dimension-repository_network_root_nwo | purescript-lua/purescript-lua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width