Title: General case-of-case: distribute an accessor/application into the branches it is applied to · Issue #243 · purescript-lua/purescript-lua · GitHub
Open Graph Title: General case-of-case: distribute an accessor/application into the branches it is applied to · Issue #243 · purescript-lua/purescript-lua
X Title: General case-of-case: distribute an accessor/application into the branches it is applied to · Issue #243 · purescript-lua/purescript-lua
Description: Problem #203 pushes an if sitting in the condition of another if down into its branches. The dual is not handled: an accessor or application applied to an if ((if p then a else b).field, (if p then f else g) x) stays outside, so the proj...
Open Graph Description: Problem #203 pushes an if sitting in the condition of another if down into its branches. The dual is not handled: an accessor or application applied to an if ((if p then a else b).field, (if p then...
X Description: Problem #203 pushes an if sitting in the condition of another if down into its branches. The dual is not handled: an accessor or application applied to an if ((if p then a else b).field, (if p then...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/243
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"General case-of-case: distribute an accessor/application into the branches it is applied to","articleBody":"## Problem\n\n#203 pushes an `if` sitting in the *condition* of another `if` down into its branches. The dual is not handled: an accessor or application *applied to* an `if` (`(if p then a else b).field`, `(if p then f else g) x`) stays outside, so the projection or call is never exposed to the branch bodies where a fold could fire. Distributing the application/accessor/primop into the branch arms exposes it, gated by cheapness of the other operands (`complexity ≤ Deref`) to avoid code blow-up. pslua has only the narrow #180 rule (a tag-read distributed into if-branches).\n\n## Approach\n\nA rewrite that pushes an accessor or a saturated application through an `IfThenElse` scrutinee into both arms: `(if p then a else b).f → if p then a.f else b.f`, `(if p then f else g) x → if p then f x else g x`. Gate on the pushed operation and any co-operands being cheap (the `Deref`/`Trivial` end of the Complexity lattice, or the `isInlinableExpr` test), so a branch is not duplicated with expensive work. The unrestricted form (arbitrary branch bodies) needs join points to avoid duplication and is out of scope until those exist.\n\n## Prerequisites / Relations\n\nRelates to #203 (the condition-position dual) and reuses its evaluation-order argument. The unrestricted version wants the join points from #234 (mutual TCO), so the safe distribution here is deliberately the duplication-free subset. Sharper with #231 (the cheapness gate is `complexity ≤ Deref`), but can ship on the `isInlinableExpr` test alone.\n\n## Verification / Measurement\n\n`(if p then a else b).f` distributes into the branches and the resulting `a.f`/`b.f` fold where `a`/`b` are known, in a focused test; a distribution over non-trivial co-operands is declined (the anti-blowup gate). Eval goldens unchanged; the IIFE/closure is removed where the pushed fold fires, visible in structural goldens and #172.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-11T12:04:31Z","url":"https://github.com/purescript-lua/purescript-lua/issues/243"}
| 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:852bd142-0938-414c-90e7-8ae7749900dd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D40E:14700E:58261B:71BC1F:6B00DB63 |
| html-safe-nonce | 702ab5fe2d64708e419179032792ecab3900452790a2485637b18d44e24b4b94 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDBFOjE0NzAwRTo1ODI2MUI6NzFCQzFGOjZCMDBEQjYzIiwidmlzaXRvcl9pZCI6IjU5MTA2MjIzODEyMzUyOTcxMjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3daaf2ce926ded027d274fe5a15d60cde25db7bf491df9ed41c1efeb55189504 |
| hovercard-subject-tag | issue:4862147770 |
| 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/243/issue_layout |
| twitter:image | https://opengraph.githubassets.com/74442e2d9cb25275b8dee035b69643a4d80b99dde22d40bce16a46b6054471fd/purescript-lua/purescript-lua/issues/243 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/74442e2d9cb25275b8dee035b69643a4d80b99dde22d40bce16a46b6054471fd/purescript-lua/purescript-lua/issues/243 |
| og:image:alt | Problem #203 pushes an if sitting in the condition of another if down into its branches. The dual is not handled: an accessor or application applied to an if ((if p then a else b).field, (if p 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