René's URL Explorer Experiment


Title: feat(optimizer): collapse Boolean pattern matches to a two-way if (#223) by Unisay · Pull Request #290 · purescript-lua/purescript-lua · GitHub

Open Graph Title: feat(optimizer): collapse Boolean pattern matches to a two-way if (#223) by Unisay · Pull Request #290 · purescript-lua/purescript-lua

X Title: feat(optimizer): collapse Boolean pattern matches to a two-way if (#223) by Unisay · Pull Request #290 · purescript-lua/purescript-lua

Description: Closes #223. What A pattern match on a Boolean compiled to a three-way if with a synthesized, unreachable default — the shape every inlined show or logShow of a boolean produces: if a then return "true" elseif false == a then return "false" else return error("No patterns matched") end a is a Boolean, so true/false already cover it, but no existing rule had a handle on the shape: constantFolding knew only the left-literal true == b case, and the unreachable-branch rules need a literal condition. It now reduces to: if a then return "true" else return "false" end How Both pieces proposed in the issue, reusing the existing folds for the actual collapse: The boolean-equality fold in constantFolding is completed. false == b and b == false fold to not b, and b == true folds to b, mirroring the existing left-literal true == b case (sound per Note [IR is assumed well-typed]). New rule propagateKnownCondIntoBranches — the Boolean sibling of propagateKnownCtorThroughLet, the more general of the issue's two alternatives. Inside if c then t else e a variable condition c is true throughout t and false throughout e, so its free occurrences in the branches are replaced with the matching literal; the existing folds then finish the job: if c then "true" else (if (false == c) then "false" else Exc) -- propagation: in the else branch, c is known false if c then "true" else (if (false == false) then "false" else Exc) -- constantFolding (existing): false == false → true if c then "true" else (if true then "false" else Exc) -- removeUnreachableElseBranch (existing) if c then "true" else "false" The rule fires only on a variable condition (re-reading an immutable binding is free and yields the value the test just observed), leaves no free occurrence behind so it cannot re-fire on its own result, and never grows the tree (a Ref becomes a literal node-for-node). It is placed after removeIfWithEqualBranches in the rewrite chain: branches that are equal while still naming c collapse to a single copy, which substituting the two literals first would unequalize — a unit test pins this ordering. Tests Written test-first (red before the fix): unit tests pin the three new equality folds, the end-to-end three-way→two-way collapse, then-branch propagation (if a then a else e → a or e), and the guards — a genuinely partial match keeps its default, and a guard testing a different variable keeps the error arm. The randomized IR specs pass across 5 extra seeds. Goldens The elseif false == idiom disappears from every golden that carried it (9 sites across 6 goldens at current main; the issue counted 16 against an older corpus). Sample from Golden.RecursiveBindings.Test: yes_S_0 = function(v_S_2) - if v_S_2 then - return no_S_1(false) - elseif false == v_S_2 then - return no_S_1(true) - else - return error("No patterns matched") - end + if v_S_2 then return no_S_1(false) else return no_S_1(true) end end The collapse also cascades: the shrunk boolean show bodies now clear the call-site inline budget, so logShow pastes at its call sites in the GenericEq/NumberIsNaN goldens, and in Golden.NumberIsNaN.Test that dead-codes the whole Ring dictionary: -local Data_Semiring_foreign = { - numAdd = function(x) return function(y) return x + y end end, - numMul = function(x) return function(y) return x * y end end -} ... -local Data_Ring_sub = function(dict) return dict.sub end -local Data_Ring_ringNumber = { - sub = Data_Ring_foreign.numSub, - Semiring0 = function() - return { - add = Data_Semiring_foreign.numAdd, - zero = 0.0, - mul = Data_Semiring_foreign.numMul, - one = 1.0 - } - end -} Golden.GenericEqTwoTypes.Test keeps its 4 remaining error("No patterns matched") defaults — those are constructor-tag matches on closed sums, explicitly out of scope per the issue. Eval goldens are unchanged, which is the semantic safety net: runtime output is identical, only the shape moved.

Open Graph Description: Closes #223. What A pattern match on a Boolean compiled to a three-way if with a synthesized, unreachable default — the shape every inlined show or logShow of a boolean produces: if a then return...

X Description: Closes #223. What A pattern match on a Boolean compiled to a three-way if with a synthesized, unreachable default — the shape every inlined show or logShow of a boolean produces: if a then return...

Opengraph URL: https://github.com/purescript-lua/purescript-lua/pull/290

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:08b42ed5-c04b-ee16-3482-dc6d831538a2
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAFDA:2463BD:C7E65D:10254DC:6B00EF99
html-safe-nonce1bb0b688d5ebfe5b7ab3435a49741db99c3430588bfa2f52610ea949603287d2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkRBOjI0NjNCRDpDN0U2NUQ6MTAyNTREQzo2QjAwRUY5OSIsInZpc2l0b3JfaWQiOiI1MTAzODM0NjM2MDY1MjM4OTM3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac71688074d85031c004988e19382a708e3e2b2230fd6b116b9b280b3f337b0db0
hovercard-subject-tagpull_request:4116515981
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/purescript-lua/purescript-lua/pull/290/files
twitter:imagehttps://avatars.githubusercontent.com/u/1009751?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1009751?s=400&v=4
og:image:altCloses #223. What A pattern match on a Boolean compiled to a three-way if with a synthesized, unreachable default — the shape every inlined show or logShow of a boolean produces: if a then return...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9983dd5da06943f833c971dd5b6bc988e2858be5
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/pull/290/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F290%2Ffiles
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%2Fpull%2F290%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=purescript-lua%2Fpurescript-lua
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/290/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/290/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/290/files
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
Sign up for GitHub https://github.com/signup?return_to=%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2Fnew%2Fchoose
Unisayhttps://github.com/Unisay
mainhttps://github.com/purescript-lua/purescript-lua/tree/main
issue-223/collapse-boolean-matchhttps://github.com/purescript-lua/purescript-lua/tree/issue-223/collapse-boolean-match
Conversation 0 https://github.com/purescript-lua/purescript-lua/pull/290
Commits 1 https://github.com/purescript-lua/purescript-lua/pull/290/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/290/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/290/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/290/files
feat(optimizer): collapse Boolean pattern matches to a two-way if (#223) https://github.com/purescript-lua/purescript-lua/pull/290/files#top
Show all changes 1 commit https://github.com/purescript-lua/purescript-lua/pull/290/files
72ef420 feat(optimizer): collapse Boolean pattern matches to a two-way if (#223) Unisay Jul 23, 2026 https://github.com/purescript-lua/purescript-lua/pull/290/commits/72ef4201de973a181b6d67882379b42896ec2a45
Clear filters https://github.com/purescript-lua/purescript-lua/pull/290/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/290/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/290/files
20260723_150000_unisay_collapse_boolean_match.md https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-7442ba6b8d18596836e65c6360bfbc1ee35f0b448fdb24717e6f557ae51eb6d0
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
golden.ir https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-8529207f5726b1c4ce856b7d81dadbbbdc4b244d37e96f40d897c3acc69290b8
golden.lua https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-0c90c2d7623d39f887ed98803e0198ce7532cb955c04690d5c518a02bb16d0e1
golden.ir https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-d3c70e506ea822ff99389c6a4e383878df25de8723c47a01e91e7dc5792501dc
golden.lua https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-596c7cb04898e2e110885627fbe42de08e09aa38b253a73bf3a99c9cedfa6bec
golden.ir https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-9b91eb3b8f15ab20b15249ff4a331cf9f8922e57544c8a84939bf1118cde9f60
golden.lua https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-06897353084f92425d5d32a75137d3d06c5866a0510c5e2a93af252038456f8b
golden.ir https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-f9943d3f5555f061aef68809331d25271db2cdf83b9582b87d07ddc46f15a2ac
golden.lua https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-b59594d39ce0a26be09bceb807e448b130b409c99f1c39c673fb89e4fc6ae36d
golden.ir https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-8d033027fc53cb99d91b379e4ee2de7b079e1d3343fe598fba51211692d8cebf
golden.lua https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-1b0c45cacd09fb2b63dc94b7c30abbd79d0e933acd8f6c16b66594440df4f9a6
golden.ir https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-df535e1f7273af0cc86db20df55495de4552000d7bf2f3abb21f421d07947914
golden.lua https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-8f846c962c84e2efb0046e7848c15b3bac3e044be37a2d2ee0620f823f2e9b0f
changelog.d/20260723_150000_unisay_collapse_boolean_match.mdhttps://github.com/purescript-lua/purescript-lua/pull/290/files#diff-7442ba6b8d18596836e65c6360bfbc1ee35f0b448fdb24717e6f557ae51eb6d0
View file https://github.com/purescript-lua/purescript-lua/blob/72ef4201de973a181b6d67882379b42896ec2a45/changelog.d/20260723_150000_unisay_collapse_boolean_match.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/290/{{ revealButtonHref }}
lib/Language/PureScript/Backend/IR/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
View file https://github.com/purescript-lua/purescript-lua/blob/72ef4201de973a181b6d67882379b42896ec2a45/lib/Language/PureScript/Backend/IR/Optimizer.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/290/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
test/Language/PureScript/Backend/IR/Optimizer/Spec.hshttps://github.com/purescript-lua/purescript-lua/pull/290/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
View file https://github.com/purescript-lua/purescript-lua/blob/72ef4201de973a181b6d67882379b42896ec2a45/test/Language/PureScript/Backend/IR/Optimizer/Spec.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/290/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
https://github.com/purescript-lua/purescript-lua/pull/290/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/290/files
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.