Title: Fold ctor/array through-let unpacking across trailing sibling groupings, as the record rules do · Issue #323 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Fold ctor/array through-let unpacking across trailing sibling groupings, as the record rules do · Issue #323 · purescript-lua/purescript-lua
X Title: Fold ctor/array through-let unpacking across trailing sibling groupings, as the record rules do · Issue #323 · purescript-lua/purescript-lua
Description: Problem The three through-a-let unpacking families now disagree on where they look for the binder's uses. The record rules of #240 (propagateKnownObjectThroughLet, propagateObjectUpdateThroughLet) fold occurrences across the trailing sib...
Open Graph Description: Problem The three through-a-let unpacking families now disagree on where they look for the binder's uses. The record rules of #240 (propagateKnownObjectThroughLet, propagateObjectUpdateThroughLet) ...
X Description: Problem The three through-a-let unpacking families now disagree on where they look for the binder's uses. The record rules of #240 (propagateKnownObjectThroughLet, propagateObjectUpdateThroughL...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/323
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fold ctor/array through-let unpacking across trailing sibling groupings, as the record rules do","articleBody":"## Problem\n\nThe three through-a-`let` unpacking families now disagree on where they look for the binder's uses. The record rules of #240 (`propagateKnownObjectThroughLet`, `propagateObjectUpdateThroughLet`) fold occurrences across the *trailing sibling groupings* of the same `Let` as well as its body — `Let` groupings scope sequentially, so a later binding's right-hand side legitimately reads an earlier binder. The constructor rule (`propagateKnownCtorThroughLet`, #214) and the array rule (`propagateKnownArrayThroughLet`, #225) instead decline outright when any sibling grouping references the binder:\n\n```haskell\n, all ((== 0) . countFreeRefGrouping name) (before \u003c> after)\n```\n\nFor records the sibling reach was load-bearing (the defaults pattern `let opts = {…}; chosen = opts { … } in …` puts the update use in a sibling), but the same multi-binding shape exists for the other aggregates — e.g. a `let`-bound array consumed by a later sibling binding's length/element reads, or a constructor scrutinized by a sibling — and today those decline even though every use is a foldable eliminating read:\n\n```purescript\nlet xs = [10, 20]\n total = xs !! 0 + xs !! 1 -- sibling grouping reads xs: rule declines\nin f total total\n```\n\n## Approach\n\nPort the #240 mechanics to the two older rules: split with the shared `findStandaloneBinding`, take `targets = body : (groupingExprs =\u003c\u003c after)` (both helpers already live in `Language.PureScript.Backend.IR.Optimizer`), run the existing census over `targets`, fold with `fmap (fmap (fmap foldReads)) after` alongside the body, and keep declining on any `before`-grouping reference (impossible under globally-unique-counters scoping, but `optimizedExpression` also runs on generated input). The field/element-binders already take the consumed binding's position, so they scope over the trailing siblings unchanged.\n\n## Prerequisites / Relations\n\nNo open blockers. Builds on #240 (closed), which introduced the sibling-reach mechanics and the shared `findStandaloneBinding`/`groupingExprs` helpers; touches the rules introduced by #214 and #225 (both closed).\n\n## Verification\n\nA unit spec per rule with the use in a trailing sibling grouping (mirroring the #240 spec \"unpacks a literal used from a later sibling binding\") goes from decline to fold; existing suites and goldens stay green, with any structural golden movement reviewed as legitimate extra folding.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-27T18:00:10Z","url":"https://github.com/purescript-lua/purescript-lua/issues/323"}
| 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:153c1c29-e5f3-adb8-ee58-f9123597b160 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C1AE:19114D:858CEC:ADE142:6B00D942 |
| html-safe-nonce | 996477ae85a70b227e3c9f012abba17015e5b15336d740a7253636ce1db7a882 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMUFFOjE5MTE0RDo4NThDRUM6QURFMTQyOjZCMDBEOTQyIiwidmlzaXRvcl9pZCI6IjMzNjM4Mjk1NDYzNDc0NTI3MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9f47fb10c45da4995cb873e3224c7f1c812364b73c9a3e811cf84b9cfd018ba1 |
| hovercard-subject-tag | issue:4990859202 |
| 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/323/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b8691d9c1c95526ccf7d124e20f22561377169b8bdbf2fd5f265947bb7f89787/purescript-lua/purescript-lua/issues/323 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b8691d9c1c95526ccf7d124e20f22561377169b8bdbf2fd5f265947bb7f89787/purescript-lua/purescript-lua/issues/323 |
| og:image:alt | Problem The three through-a-let unpacking families now disagree on where they look for the binder's uses. The record rules of #240 (propagateKnownObjectThroughLet, propagateObjectUpdateThroughLet) ... |
| 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