René's URL Explorer Experiment


Title: Collapse Boolean pattern matches (including inlined show) to a two-way if · Issue #223 · purescript-lua/purescript-lua · GitHub

Open Graph Title: Collapse Boolean pattern matches (including inlined show) to a two-way if · Issue #223 · purescript-lua/purescript-lua

X Title: Collapse Boolean pattern matches (including inlined show) to a two-way if · Issue #223 · purescript-lua/purescript-lua

Description: What A pattern match on a Boolean compiles to a three-way if with a synthesized, unreachable default: if a then return "true" elseif false == a then return "false" else return error("No patterns matched") end a is a Boolean, so true/fals...

Open Graph Description: What A pattern match on a Boolean compiles to a three-way if with a synthesized, unreachable default: if a then return "true" elseif false == a then return "false" else return error("No patterns ma...

X Description: What A pattern match on a Boolean compiles to a three-way if with a synthesized, unreachable default: if a then return "true" elseif false == a then return "false" else return e...

Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/223

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Collapse Boolean pattern matches (including inlined show) to a two-way if","articleBody":"## What\n\nA pattern match on a `Boolean` compiles to a three-way `if` with a synthesized, unreachable default:\n\n```lua\nif a then\n  return \"true\"\nelseif false == a then\n  return \"false\"\nelse\n  return error(\"No patterns matched\")\nend\n```\n\n`a` is a `Boolean`, so `true`/`false` already cover it. The `elseif false == a` guard is always taken once reached, and the `else` default is dead. The whole thing should reduce to:\n\n```lua\nif a then return \"true\" else return \"false\" end\n```\n\nThe canonical source is the `Show Boolean` instance, so this is the shape every inlined `show` or `logShow` of a boolean produces. Since #180 inlines the boolean `show` dictionary at call sites, it now appears more often.\n\n## Where\n\nThe idiom (signature `elseif false ==`) occurs 16 times across 6 goldens:\n\n- `Golden.RecursiveBindings.Test`: 4\n- `Golden.GenericEqTwoTypes.Test`: 4\n- `Golden.Primops.Test`: 3\n- `Golden.BugListGenericEq.Test`: 3\n- `Golden.StringCodePoints.Test`: 1\n- `Golden.CharLiterals.Test`: 1\n\n## Why it is not folded today\n\nThe IR shape is:\n\n```\nIfThenElse c \"true\" (IfThenElse (Eq (LitBool False) c) \"false\" (Exception \"No patterns matched\"))\n```\n\nNone of the existing if/boolean rules apply:\n\n- `reduceBooleanIf` (#178) collapses `if p then True else False`, but here the branches are the strings `\"true\"`/`\"false\"`, not boolean literals.\n- `constantFolding` folds `Eq True b → b` but has no `Eq False b → not b` counterpart, so `false == c` stays opaque.\n- `removeUnreachableThenBranch` / `removeUnreachableElseBranch` need a literal `if True` / `if False`.\n\nSo the optimizer has no handle on the shape and prints it verbatim.\n\n## Proposed transformations\n\nTwo pieces, both reusing the existing folds.\n\n1. Complete the boolean-equality fold in `constantFolding` (cheap and independently useful):\n\n```haskell\nEq _ (LiteralBool _ False) b → Just (primNot b)   -- b : Bool, see Note [IR is assumed well-typed]\nEq _ b (LiteralBool _ False) → Just (primNot b)\nEq _ b (LiteralBool _ True)  → Just b              -- mirror the existing left-literal case\n```\n\n2. Propagate a branch condition's known value into its branches, the Boolean sibling of the existing `propagateKnownCtorThroughLet`: inside `if c then t else e`, `c` is `True` throughout `t` and `False` throughout `e`. Substituting `c := False` into the else branch lets the existing folds finish the job:\n\n```\nif c then \"true\" else (if (False == c) then \"false\" else Exc)\n  -- propagation: in the else branch, c is known False\nif c then \"true\" else (if (False == False) then \"false\" else Exc)\n  -- constantFolding (existing): Eq (LitBool False) (LitBool False) → True\nif c then \"true\" else (if True then \"false\" else Exc)\n  -- removeUnreachableElseBranch (existing)\nif c then \"true\" else \"false\"\n```\n\nA smaller, more local alternative to (2) is a dominated-condition rule, `if c then t else (if c then _dead else e) → if c then t else e`, which composes with the existing `flipNegatedIf` (after fold (1) turns `false == c` into `not c`) to the same result. Either works. Propagation is the more general choice and matches the constructor propagation the optimizer already does; the dominated-condition rule is the lower-risk one. Both need `c` to be a variable so re-testing it is free and sound.\n\n## Test\n\nWork test-first. A focused `Optimizer` unit test on the IR shape above proves it reduces to the two-way if, including a guard that a genuinely partial match keeps its default. The 16 goldens listed also shrink, since the `elseif false ==` guard and the `error` default disappear. The eval goldens do not move, which is the semantic safety net: runtime output is identical, only the shape changes.\n\n## Out of scope\n\nConstructor-tag matches on closed sums produce a similar dead `error(\"No patterns matched\")` default (the other ~48 of the 64 such defaults in the corpus, for example `genericEqPrime` in `Golden.BugListGenericEq.Test`). Eliminating those is a separate, larger change: proving a tag chain exhaustive needs the complete constructor set per type, which the IR and `UberModule` do not carry today (a `Ctor` node knows its own `TyName` and `CtorName`, not its siblings). That is a plumbing feature rather than a local rewrite, tracked on its own.\n\n## Payoff\n\nModest per site but recurring. This is the shape of every `show` or `logShow` of a boolean, so it turns up in real code as well as across the eval-heavy goldens, and it removes a dead `error` call from otherwise-total code.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-10T09:22:02Z","url":"https://github.com/purescript-lua/purescript-lua/issues/223"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d5e04b54-4210-e9b0-cfee-653052a8ea82
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBDF2:14700E:66F3AE:84935C:6B00DFBD
html-safe-nonce6aad8f7b1a2d28e139e320338142f0fb2b92f27cb8c6f0b5741da97a2b20bdf9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCREYyOjE0NzAwRTo2NkYzQUU6ODQ5MzVDOjZCMDBERkJEIiwidmlzaXRvcl9pZCI6IjQ3MjE4MTYxNDk5OTI0NjQzMTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacab86c6456594109b6a0f670632958eeff2ff4f3a9c112013c4ffc574e152446a
hovercard-subject-tagissue:4853744740
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/223/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f5a8e6936f482396067ce7647955bf61488214b704983f541ffcfb6149339ea2/purescript-lua/purescript-lua/issues/223
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f5a8e6936f482396067ce7647955bf61488214b704983f541ffcfb6149339ea2/purescript-lua/purescript-lua/issues/223
og:image:altWhat A pattern match on a Boolean compiles to a three-way if with a synthesized, unreachable default: if a then return "true" elseif false == a then return "false" else return error("No patterns ma...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameUnisay
hostnamegithub.com
expected-hostnamegithub.com
None043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf
turbo-cache-controlno-preview
go-importgithub.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git
octolytics-dimension-user_id131581790
octolytics-dimension-user_loginpurescript-lua
octolytics-dimension-repository_id587200487
octolytics-dimension-repository_nwopurescript-lua/purescript-lua
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id587200487
octolytics-dimension-repository_network_root_nwopurescript-lua/purescript-lua
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5425dc24e8bd8d6fca9641a12afc984825a43875
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/issues/223#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2F223
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2F223
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=purescript-lua%2Fpurescript-lua
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/223
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/223
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/223
purescript-luahttps://github.com/purescript-lua
purescript-luahttps://github.com/purescript-lua/purescript-lua
Codehttps://github.com/purescript-lua/purescript-lua
Issues48 (48)https://github.com/purescript-lua/purescript-lua/issues
Pull requestshttps://github.com/purescript-lua/purescript-lua/pulls
Discussionshttps://github.com/purescript-lua/purescript-lua/discussions
Actionshttps://github.com/purescript-lua/purescript-lua/actions
Projectshttps://github.com/purescript-lua/purescript-lua/projects
Security and qualityhttps://github.com/purescript-lua/purescript-lua/security
Insightshttps://github.com/purescript-lua/purescript-lua/insights
https://github.com/purescript-lua/purescript-lua
New issuehttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/223
New issuehttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/223
#290https://github.com/purescript-lua/purescript-lua/pull/290
Collapse Boolean pattern matches (including inlined show) to a two-way ifhttps://github.com/purescript-lua/purescript-lua/issues/223#top
#290https://github.com/purescript-lua/purescript-lua/pull/290
OptimisationA Compiler Optimisationhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22Optimisation%22
area: irIR / optimizer / DCE / inlinerhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20ir%22
https://github.com/Unisay
Unisayhttps://github.com/Unisay
on Jul 10, 2026https://github.com/purescript-lua/purescript-lua/issues/223#issue-4853744740
#180https://github.com/purescript-lua/purescript-lua/issues/180
Lift the pure subset of foreign values into the IR: primop nodes and an allowlist-driven lifter #178https://github.com/purescript-lua/purescript-lua/issues/178
Unisayhttps://github.com/Unisay
area: irIR / optimizer / DCE / inlinerhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20ir%22
OptimisationA Compiler Optimisationhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22Optimisation%22
on Jul 10, 2026https://github.com/purescript-lua/purescript-lua/issues/223#event-27808760985
Unisayhttps://github.com/Unisay
on Jul 23, 2026https://github.com/purescript-lua/purescript-lua/issues/223#event-28381852915
Merge pull request #290 from purescript-lua/issue-223/collapse-boolea…https://github.com/purescript-lua/purescript-lua/commit/62b0213850d09c997ee093b9994bf2bb06de8467
#290https://github.com/purescript-lua/purescript-lua/pull/290
62b0213https://github.com/purescript-lua/purescript-lua/commit/62b0213850d09c997ee093b9994bf2bb06de8467
Unisayhttps://github.com/Unisay
completedhttps://github.com/purescript-lua/purescript-lua/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#290https://github.com/purescript-lua/purescript-lua/pull/290
on Jul 23, 2026https://github.com/purescript-lua/purescript-lua/issues/223#event-28381853005
Sign up for freehttps://github.com/signup?return_to=https://github.com/purescript-lua/purescript-lua/issues/223
Sign in to commenthttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/223
OptimisationA Compiler Optimisationhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22Optimisation%22
area: irIR / optimizer / DCE / inlinerhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20ir%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.