Title: Sweep dead module-scope bindings stranded by codegen-level rewrites · Issue #316 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Sweep dead module-scope bindings stranded by codegen-level rewrites · Issue #316 · purescript-lua/purescript-lua
X Title: Sweep dead module-scope bindings stranded by codegen-level rewrites · Issue #316 · purescript-lua/purescript-lua
Description: Problem Codegen-level rewrites can strand module-scope bindings that nothing reads anymore. The IR-level dead-code elimination runs before code generation, so a binding it kept alive can lose its last reference when a later lowering rewr...
Open Graph Description: Problem Codegen-level rewrites can strand module-scope bindings that nothing reads anymore. The IR-level dead-code elimination runs before code generation, so a binding it kept alive can lose its l...
X Description: Problem Codegen-level rewrites can strand module-scope bindings that nothing reads anymore. The IR-level dead-code elimination runs before code generation, so a binding it kept alive can lose its l...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/316
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sweep dead module-scope bindings stranded by codegen-level rewrites","articleBody":"## Problem\n\nCodegen-level rewrites can strand module-scope bindings that nothing reads anymore. The IR-level dead-code elimination runs before code generation, so a binding it kept alive can lose its last reference when a later lowering rewrites the use sites away: the native-loop lowering (#233) absorbs loop-combinator calls, and the cell unboxing (#239) absorbs `read`/`write`/`modify` calls and drops the discarded `unit` value of the `void` wrapper. The emitted chunk then still carries the accessor binding — and the module-scope table `M` it lives in — as pure load-time dead weight. From `test/ps/output/Golden.NativeLoopsST.Test/golden.lua` after #239, where `M.Data_Unit_unit` has zero remaining reads in the whole artifact:\n\n```lua\nlocal M = {}\nlocal Data_Unit_foreign = { unit = {} }\nM.Data_Unit_unit = Data_Unit_foreign.unit\n```\n\nThe same artifact previously bound `local Data_Unit_unit = …` and read it once per loop iteration; after the unboxing the read is gone but the binding (and now the `M` table that exists only to hold it) remains.\n\n## Approach\n\nA Lua-level sweep after code generation and the storage passes: count references to each module-scope binding (both the `M.name` field form and the localized `local name` form) in the finished chunk, drop assignments whose target is never read, and drop the `local M = {}` declaration itself when no field of it survives. The reference counting must treat the module export table (the final `return { … }`) and entry-point call as roots. Repeat to a fixpoint, since dropping one binding can orphan the bindings only it referenced.\n\n## Relations\n\nSurfaced by #239 (cell unboxing) and applies equally to shapes left by #233 (native loops). Purely an output-cleanliness/load-time win; steady-state performance is unaffected.\n\n## Verification\n\nThe `Golden.NativeLoopsST.Test`, `Golden.MixedDiscardFloat.Test` and `Golden.RefUnbox.Test` goldens lose their stranded accessor lines (and, where nothing else uses it, the `local M = {}` header); eval goldens are byte-identical.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-27T12:27:25Z","url":"https://github.com/purescript-lua/purescript-lua/issues/316"}
| 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:f3baf22c-1277-30be-b01a-0064538169dc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC52:272DC0:50ECCE:68B563:6B00D952 |
| html-safe-nonce | b871fb689582e6ad1120bb54e23f649084f133c90810a4fdd0e0c207efed01e3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzUyOjI3MkRDMDo1MEVDQ0U6NjhCNTYzOjZCMDBEOTUyIiwidmlzaXRvcl9pZCI6IjczMzg4MjgwNTM3NDI2NzIyMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a9b84f50c689ccf7b5fa1b47772ac2cd6c0b6274c0bf1258f95df26f28b6237e |
| hovercard-subject-tag | issue:4987859089 |
| 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/316/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ca945ab5040686d6a7604039d6bc19a884967eccb2c17d6df282f53e5a965f2/purescript-lua/purescript-lua/issues/316 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ca945ab5040686d6a7604039d6bc19a884967eccb2c17d6df282f53e5a965f2/purescript-lua/purescript-lua/issues/316 |
| og:image:alt | Problem Codegen-level rewrites can strand module-scope bindings that nothing reads anymore. The IR-level dead-code elimination runs before code generation, so a binding it kept alive can lose its l... |
| 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 | a481f62a1e04c9b9bdcb5628230682c66d59006f5b13b080f79cba84a176905b |
| 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 | 84c8c5cc25e2fb7f2308428458538436baecc6d2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width