Title: Scalar replacement: unpack records/arrays/updates read only field-wise · Issue #240 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Scalar replacement: unpack records/arrays/updates read only field-wise · Issue #240 · purescript-lua/purescript-lua
X Title: Scalar replacement: unpack records/arrays/updates read only field-wise · Issue #240 · purescript-lua/purescript-lua
Description: Problem A let-bound record, array, constructor, or record update that is only ever read by field, never used as a whole value, still allocates its table. pslua unpacks constructors through a let (propagateKnownCtorThroughLet) and folds a...
Open Graph Description: Problem A let-bound record, array, constructor, or record update that is only ever read by field, never used as a whole value, still allocates its table. pslua unpacks constructors through a let (p...
X Description: Problem A let-bound record, array, constructor, or record update that is only ever read by field, never used as a whole value, still allocates its table. pslua unpacks constructors through a let (p...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/240
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Scalar replacement: unpack records/arrays/updates read only field-wise","articleBody":"## Problem\n\nA `let`-bound record, array, constructor, or record update that is only ever read by field, never used as a whole value, still allocates its table. pslua unpacks constructors through a let (`propagateKnownCtorThroughLet`) and folds an in-place object projection (`reduceObjectProp`), but has no general rule for records, arrays, or updates. On the Lua target, where a table allocation costs more than in a JS engine with escape analysis, an aggregate that exists only to be projected is pure waste.\n\nThe unpacking rewrite explodes such a binding into a per-field let so the aggregate is never built, gated on an exact use equation: `total == access + case` for a constructor, `== access + update` for a record, `== access` for an array. A single whole-value use vetoes the rewrite, preserving sharing and identity.\n\n## Approach\n\nAdd an unpacking rewrite for `let x = \u003caggregate> in body` where `\u003caggregate>` is a record literal, array literal, constructor application, or record update and every occurrence of `x` in `body` is a field/element projection (or, for a constructor, a case reading its fields). Bind each read field to its own let and drop the aggregate. The exact-use equation is the gate; any use of `x` as a whole value (returned, passed, compared) turns it off.\n\n## Prerequisites / Relations\n\nBlocked by #231 (the Complexity/Capture analysis lattice): \"read only field-wise, never as a whole\" is the same exact-use accounting the lattice makes precise. The result-side dual is #206 (CPR: return components rather than a product); together they avoid materializing a box on either side of a call. Relates to #208 (SpecConstr), which removes the boxed accumulator this rule would otherwise unpack every iteration.\n\n## Verification / Measurement\n\nA let-bound record read at two fields compiles with no table allocation and two direct bindings in `golden.lua`; a record also used as a whole value keeps its allocation, the soundness guard, tested directly. Allocation-counter drop on a record-heavy benchmark through #172; eval goldens unchanged.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-11T12:04:27Z","url":"https://github.com/purescript-lua/purescript-lua/issues/240"}
| 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:2668bfae-1ac3-1cfe-6afa-830fc05e5a56 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 969C:C2718:80B1A0:A87F90:6B00DB74 |
| html-safe-nonce | 6d3733af4c717f6c7b837accb64318df5b142d0c22308fddd7e23bcb499da087 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjlDOkMyNzE4OjgwQjFBMDpBODdGOTA6NkIwMERCNzQiLCJ2aXNpdG9yX2lkIjoiOTA2ODM1MTg1OTg5MDExNzQ5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 268a9d9e42bb152c914991c5bdce3adf8385d15e058dd8a0aa91d8c1bba33463 |
| hovercard-subject-tag | issue:4862147580 |
| 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/240/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3ee0609c636411f8519db975c5f94e9fb8302eca875d57fd689f47f8eca89ef/purescript-lua/purescript-lua/issues/240 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3ee0609c636411f8519db975c5f94e9fb8302eca875d57fd689f47f8eca89ef/purescript-lua/purescript-lua/issues/240 |
| og:image:alt | Problem A let-bound record, array, constructor, or record update that is only ever read by field, never used as a whole value, still allocates its table. pslua unpacks constructors through a let (p... |
| 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