Title: Codegen: foreign-body helper functions survive export tree-shaking as dead code · Issue #274 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Codegen: foreign-body helper functions survive export tree-shaking as dead code · Issue #274 · purescript-lua/purescript-lua
X Title: Codegen: foreign-body helper functions survive export tree-shaking as dead code · Issue #274 · purescript-lua/purescript-lua
Description: Problem Found while linting pslua-generated Lua in a downstream application (OpenResty, with luacheck and lua-language-server). Cosmetic only: the code runs and passes luac -p. Re-confirmed on current main. pslua correctly narrows a fore...
Open Graph Description: Problem Found while linting pslua-generated Lua in a downstream application (OpenResty, with luacheck and lua-language-server). Cosmetic only: the code runs and passes luac -p. Re-confirmed on curr...
X Description: Problem Found while linting pslua-generated Lua in a downstream application (OpenResty, with luacheck and lua-language-server). Cosmetic only: the code runs and passes luac -p. Re-confirmed on curr...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/274
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Codegen: foreign-body helper functions survive export tree-shaking as dead code","articleBody":"## Problem\n\nFound while linting pslua-generated Lua in a downstream application (OpenResty, with luacheck and lua-language-server). Cosmetic only: the code runs and passes `luac -p`. Re-confirmed on current `main`.\n\npslua correctly narrows a foreign module's exported table to the fields actually used, but the top-level `local function` helpers in the FFI file body are emitted verbatim even when only the dropped exports referenced them. A module that uses only `Data.Int.toNumber` emits:\n\n```lua\nlocal Data_Int_foreign = (function()\n local function toInt32(n) … end -- dead: only fromStringAsImpl/toStringAs used it\n local function digitValue(c) … end -- dead: same\n return { toNumber = function(n) return n end } -- export table narrowed to the one used field\nend)()\n```\n\nThe return table is narrowed (good), but `toInt32` and `digitValue` are now unreachable and still shipped. Root cause: export-table narrowing does not drive a DCE pass over the foreign body's own `local` bindings.\n\n## Approach\n\nAfter narrowing the export table, drop foreign-body locals unreachable from the retained exports.\n\n## Prerequisites / Relations\n\nNone. Extends the existing foreign export-table narrowing.\n\n## Verification / Measurement\n\nThe `Data.Int` example ships without `toInt32`/`digitValue` when only `toNumber` is used; generated output is smaller and still passes `luac -p`. Low priority: dead code plus a little size bloat, not incorrect.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-14T10:52:31Z","url":"https://github.com/purescript-lua/purescript-lua/issues/274"}
| 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:2dee23da-2bf4-a95f-30ec-0f76d626ba71 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFE2:D0E46:7C33C1:A60DD6:6B00DB6B |
| html-safe-nonce | b27fbc32719e2e2b1259b7ccad709381479177c097655918a48ebc2a8d578424 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkUyOkQwRTQ2OjdDMzNDMTpBNjBERDY6NkIwMERCNkIiLCJ2aXNpdG9yX2lkIjoiODk4MDk3MzkwMjc1ODk5Mjc0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7ce3f8c1e04ce791948756b088722954b4a029d4009ce2d09bc048a16f513972 |
| hovercard-subject-tag | issue:4882350673 |
| 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/274/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3faabc2d1ba9ad093b0fa7358b9a40d837e39880ddea53ebbac1b95a8c640b4c/purescript-lua/purescript-lua/issues/274 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3faabc2d1ba9ad093b0fa7358b9a40d837e39880ddea53ebbac1b95a8c640b4c/purescript-lua/purescript-lua/issues/274 |
| og:image:alt | Problem Found while linting pslua-generated Lua in a downstream application (OpenResty, with luacheck and lua-language-server). Cosmetic only: the code runs and passes luac -p. Re-confirmed on curr... |
| 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