Title: Fold `Eq` through a conditional of literals to fully collapse inlined comparisons · Issue #220 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Fold `Eq` through a conditional of literals to fully collapse inlined comparisons · Issue #220 · purescript-lua/purescript-lua
X Title: Fold `Eq` through a conditional of literals to fully collapse inlined comparisons · Issue #220 · purescript-lua/purescript-lua
Description: Follow-up from #180. Once a dictionary method is inlined, an inlined comparison (compare, >=, <) leaves a residual Eq lit (if ...) that no rule folds, so a guard that should reduce to a single primitive stays a verbose Ordering if-tree. ...
Open Graph Description: Follow-up from #180. Once a dictionary method is inlined, an inlined comparison (compare, >=, <) leaves a residual Eq lit (if ...) that no rule folds, so a guard that should reduce to a single prim...
X Description: Follow-up from #180. Once a dictionary method is inlined, an inlined comparison (compare, >=, <) leaves a residual Eq lit (if ...) that no rule folds, so a guard that should reduce to a singl...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/220
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fold `Eq` through a conditional of literals to fully collapse inlined comparisons","articleBody":"Follow-up from #180. Once a dictionary method is inlined, an inlined comparison\n(`compare`, `>=`, `\u003c`) leaves a residual `Eq lit (if ...)` that no rule folds, so\na guard that should reduce to a single primitive stays a verbose `Ordering`\nif-tree.\n\n## Example\n\n`Golden.TailRecM2Shadow` has the guard `go acc i | i >= n = ...`. `i >= n` goes\nthrough the `Ord Int` dictionary as `compare i n` followed by a tag test.\nAfter #180 inlines `compare` and pushes the tag read into the branches (the\n`reflectCtor`-through-`if` fold added in #180), the guard is left as:\n\n```\nEq \"Ordering.LT\" (if i \u003c n then \"Ordering.LT\" else if i == n then \"Ordering.EQ\" else \"Ordering.GT\")\n```\n\n`constantFolding` handles `Eq lit lit`, but here the second operand is an `if`,\nnot a literal, so nothing fires. The three-way `Ordering` conditional survives\ninto the generated Lua. This is the residual growth in `TailRecM2Shadow`\n(+112 lines) noted on #180.\n\n## Proposed fix\n\nA commuting conversion that distributes `Eq` over a conditional, guarded (as the\n`reflectCtor`-through-`if` fold is) to fire only when the branches are literals\nso the pushed `Eq lit lit` folds and no conditional is grown over\nnon-literal branches:\n\n```\nEq lit (IfThenElse c t e) ==> IfThenElse c (Eq lit t) (Eq lit e) -- when t, e fold\n```\n\nThe existing rules then finish the job:\n\n```\nEq \"LT\" (if i\u003cn then \"LT\" else if i==n then \"EQ\" else \"GT\")\n -> if i\u003cn then Eq \"LT\" \"LT\" else if i==n then Eq \"LT\" \"EQ\" else Eq \"LT\" \"GT\"\n -> if i\u003cn then True else if i==n then False else False -- constantFolding\n -> if i\u003cn then True else False -- removeIfWithEqualBranches\n -> i \u003c n -- reduceBooleanIf\n```\n\nThe whole `Ordering` machinery collapses to one primitive `i \u003c n`.\n\n## Note\n\n`Eq` is one of the most common operations, so even guarded this fires on many\nsites and will move a fair number of goldens. Worth measuring the corpus churn\nbefore committing, which is why it is split out of #180 rather than riding along.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-10T07:58:16Z","url":"https://github.com/purescript-lua/purescript-lua/issues/220"}
| 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:9f34595c-f149-7951-98b0-40afdb3007f7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BDA4:33D24F:5EB51A:7B68D2:6B00DFBB |
| html-safe-nonce | 8c83f5fd6d07e17c2a82420a677c065f080fb856d7edef150803405e472231e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCREE0OjMzRDI0Rjo1RUI1MUE6N0I2OEQyOjZCMDBERkJCIiwidmlzaXRvcl9pZCI6IjI2ODY1NjM4MTEzNjc5MDMxNjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9f3d9776742859f285964f0979dfc1cf66f03f7fc1559e2dddacee8f05f72619 |
| hovercard-subject-tag | issue:4853184319 |
| 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/220/issue_layout |
| twitter:image | https://opengraph.githubassets.com/51526b801c731095cd4fcc9dc665b7b489024936f8dc1c165126454cae98f46f/purescript-lua/purescript-lua/issues/220 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/51526b801c731095cd4fcc9dc665b7b489024936f8dc1c165126454cae98f46f/purescript-lua/purescript-lua/issues/220 |
| og:image:alt | Follow-up from #180. Once a dictionary method is inlined, an inlined comparison (compare, >=, <) leaves a residual Eq lit (if ...) that no rule folds, so a guard that should reduce to a single prim... |
| 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