Title: Foreign table-constructor exports are duplicated per use site (fresh identity and allocation per copy) · Issue #175 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Foreign table-constructor exports are duplicated per use site (fresh identity and allocation per copy) · Issue #175 · purescript-lua/purescript-lua
X Title: Foreign table-constructor exports are duplicated per use site (fresh identity and allocation per copy) · Issue #175 · purescript-lua/purescript-lua
Description: Problem The linker binds every foreign export name to an ObjectProp wrapper synthesized with Inline.Always (Note [Inline annotations and inlining heuristics]), the foreign module expression is then typically inlined by the used-once heur...
Open Graph Description: Problem The linker binds every foreign export name to an ObjectProp wrapper synthesized with Inline.Always (Note [Inline annotations and inlining heuristics]), the foreign module expression is then...
X Description: Problem The linker binds every foreign export name to an ObjectProp wrapper synthesized with Inline.Always (Note [Inline annotations and inlining heuristics]), the foreign module expression is then...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/175
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Foreign table-constructor exports are duplicated per use site (fresh identity and allocation per copy)","articleBody":"## Problem\n\nThe linker binds every foreign export name to an `ObjectProp` wrapper synthesized with `Inline.Always` (Note [Inline annotations and inlining heuristics]), the foreign module expression is then typically inlined by the used-once heuristic, and the Lua-level `reduceTableDefinitionAccessor` folds the projection at every use site. Net effect: the export's value expression is copied into each site.\n\nFor scalars and function literals this is the intended wrapper elimination. For a value that is a table constructor it is wrong twice:\n\n1. Allocation: `Data.Unit.unit = ({})` is a constructor, not a value — every pasted copy executes `TNEW` at runtime. The linked `Data.Array` output contains 7 inlined `{}` for unit, including `void = map(function() return {} end)`: an allocation per `void` step in Effect/ST code.\n2. Identity: sites that were supposed to share one table each get their own. `Eq Unit` in the prelude compares structurally (`true`), so unit survives by luck — but any FFI table export with identity or state semantics would be silently miscompiled by the same path.\n\n## Approach\n\n1. `reduceTableDefinitionAccessor` declines to fold when the projected value is a table constructor (scalars and function literals keep folding). The declined projection stays a field access into the shared foreign table, preserving the singleton; with #174 stage 1 the access cost drops to a local read. Note: pre-#173 the export values are verbatim text blobs, so the principled \"is a table constructor\" check needs the foreign parser; until then a conservative textual test can gate the fold.\n2. Make `@inline \u003cname> never` effective for foreign export names, overriding the linker-synthesized Always on the wrapper, so a fork can declare sharing intent explicitly. The annotation machinery has open bugs in this neighborhood (#169, #171) and prior history of `never` being ignored (#131) — the fix needs a regression test.\n\n## Prerequisites / Relations\n\nIndependent in the dependency graph — a correctness/identity defect standing on its own. Two relations shape the fix: the principled \"is a table constructor\" check in (1) wants the #173 foreign parser (pre-#173, a conservative textual test gates the fold instead), and the declined field access drops to a local read once #174 stage 1 lands. The `@inline never` work in (2) sits in the annotation-handling neighborhood with the open bugs #169 and #171 and the #131 \"`never` ignored\" history.\n\n## Verification / Measurement\n\nA golden linking unit-heavy code asserts the linked output contains exactly one `{}` constructor for unit (the one inside the foreign table); eval goldens unchanged. Allocation deltas are measurable with #172.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-06T09:54:07Z","url":"https://github.com/purescript-lua/purescript-lua/issues/175"}
| 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:80a8ec1e-1873-77cc-e1cb-40c65dedd0cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD9A:A7C8F:9A506D:C8103D:6B00DFBB |
| html-safe-nonce | d88d5eafb31f29b018c30b4647e710b4328233fc89ec30fb5298dff00abfa6d3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDlBOkE3QzhGOjlBNTA2RDpDODEwM0Q6NkIwMERGQkIiLCJ2aXNpdG9yX2lkIjoiNzAyNzc3MjU2MzUyMjY0MTg1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 11bd612718dd68be4be882c4c0d62a1a50a6250dfab7b2a65f2118536a275757 |
| hovercard-subject-tag | issue:4817971560 |
| 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/175/issue_layout |
| twitter:image | https://opengraph.githubassets.com/63bbf4e16f6e3e57f6f9ec5be8c5ad30282c6af104fabac0f391bd17aeab0850/purescript-lua/purescript-lua/issues/175 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/63bbf4e16f6e3e57f6f9ec5be8c5ad30282c6af104fabac0f391bd17aeab0850/purescript-lua/purescript-lua/issues/175 |
| og:image:alt | Problem The linker binds every foreign export name to an ObjectProp wrapper synthesized with Inline.Always (Note [Inline annotations and inlining heuristics]), the foreign module expression is then... |
| 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