Title: Push an if in condition position into its branches (case-of-case over the IfThenElse decision tree) · Issue #203 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Push an if in condition position into its branches (case-of-case over the IfThenElse decision tree) · Issue #203 · purescript-lua/purescript-lua
X Title: Push an if in condition position into its branches (case-of-case over the IfThenElse decision tree) · Issue #203 · purescript-lua/purescript-lua
Description: Problem The IR compiles pattern matches to decision trees of nested IfThenElse. When a boolean-returning tree ends up in the condition of another IfThenElse (typically after inlining a predicate: an Ord/Eq comparison, isJust, a guard), t...
Open Graph Description: Problem The IR compiles pattern matches to decision trees of nested IfThenElse. When a boolean-returning tree ends up in the condition of another IfThenElse (typically after inlining a predicate: a...
X Description: Problem The IR compiles pattern matches to decision trees of nested IfThenElse. When a boolean-returning tree ends up in the condition of another IfThenElse (typically after inlining a predicate: a...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/203
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Push an if in condition position into its branches (case-of-case over the IfThenElse decision tree)","articleBody":"## Problem\n\nThe IR compiles pattern matches to decision trees of nested `IfThenElse`. When a boolean-returning tree ends up in the condition of another `IfThenElse` (typically after inlining a predicate: an `Ord`/`Eq` comparison, `isJust`, a guard), the inner tree sits in expression position and codegen wraps it in an IIFE:\n\n```lua\nif (function()\n if \"Data.Ordering∷Ordering.LT\" == (...)[\"$ctor\"] then\n return true\n else\n return false\n end\nend)() then\n return withInc(intAdd(n)(1))(k)\nelse\n return k(intAdd(n)(1))\nend\n```\n\nThis is `Golden.LongCallbackChain.Test/golden.lua` today: the closure is allocated and called on every iteration of a recursive function. `Golden.TailRecM2Shadow.Test` carries the same shape.\n\n## Approach\n\nThe case-of-case transformation, restricted to the shape where pushing cannot duplicate code:\n\n```\nIfThenElse (IfThenElse c a b) x y ==> IfThenElse c (IfThenElse a x y) (IfThenElse b x y)\n```\n\nGuard: `a` and `b` are boolean literals, so the residual ifs are folded right away by the existing `removeUnreachableThenBranch`/`removeUnreachableElseBranch` rules and each of `x`, `y` survives in exactly one copy. Alternatively, `x` and `y` are trivial by the `isInlinableExpr` test. The unrestricted transformation would need join points to avoid duplicating branches and is out of scope here.\n\nThe rewrite preserves evaluation order in a strict language: `c`, then `a` or `b`, then `x` or `y`, exactly as before the push.\n\n## Prerequisites / Relations\n\nNone to land. Feeds #177: pushing brings constructor applications into scrutinee position, where the `ReflectCtor` fold can fire.\n\n## Verification / Measurement\n\nThe IIFE in `Golden.LongCallbackChain.Test/golden.lua` disappears (the condition becomes a flat comparison) while eval goldens stay byte-identical. A unit test on the rewrite pins the guard: literal inner branches push, non-literal inner branches with non-trivial `x`/`y` stay put.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-07T19:11:43Z","url":"https://github.com/purescript-lua/purescript-lua/issues/203"}
| 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:82bbd5ae-f3e4-1964-5a1a-a5ff37bcdd6e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 87A6:29AEE8:73CC1D:9C67AC:6B00DB7F |
| html-safe-nonce | f05789e39d7f57c9ee5ad29e9fb1bd544b07ef3bbed2f0e88e8a836d420640dc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0E2OjI5QUVFODo3M0NDMUQ6OUM2N0FDOjZCMDBEQjdGIiwidmlzaXRvcl9pZCI6Ijg4NTA0MDAzNzcyMDAyMzc0NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b334e022e4ced86cd5851830792433869548d57979127fb4e528007c55d04911 |
| hovercard-subject-tag | issue:4831482272 |
| 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/203/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c9a2d98168aeee707dedc3ebca8c880c840ced0ff8649d499ad58c8bf67cb53d/purescript-lua/purescript-lua/issues/203 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c9a2d98168aeee707dedc3ebca8c880c840ced0ff8649d499ad58c8bf67cb53d/purescript-lua/purescript-lua/issues/203 |
| og:image:alt | Problem The IR compiles pattern matches to decision trees of nested IfThenElse. When a boolean-returning tree ends up in the condition of another IfThenElse (typically after inlining a predicate: a... |
| 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