René's URL Explorer Experiment


Title: feat(optimizer): distribute an accessor or application into if branches by Unisay · Pull Request #334 · purescript-lua/purescript-lua · GitHub

Open Graph Title: feat(optimizer): distribute an accessor or application into if branches by Unisay · Pull Request #334 · purescript-lua/purescript-lua

X Title: feat(optimizer): distribute an accessor or application into if branches by Unisay · Pull Request #334 · purescript-lua/purescript-lua

Description: Closes #243. Adds pushEliminatorIntoIfBranches to the IR optimizer's rewrite chain: an eliminator applied to a conditional scrutinee — a record field read (ObjectProp), an array read or length (ArrayIndex/ArrayLength), a constructor tag or field read (ReflectCtor/DataArgumentByIndex), or a saturated call (AppN) — distributes into both arms, (if p then a else b).f ==> if p then a.f else b.f and (if p then f else g) x ==> if p then f x else g x. Without the push the conditional sits in expression position, which codegen wraps in an immediately-invoked function (IIFE) allocated and called per evaluation, and the eliminator never reaches the arms where the constructor, projection, and beta folds fire. The new golden Golden.DistributeIntoIf shows all the shapes. A projection over a conditional of known records used to compile to an IIFE plus a field read off its result: local Golden_DistributeIntoIf_Test_pickName = function(b) return ((function() if b then return { name = "big" } else return { name = "small" } end end)()).name end and now distributes, folds each arm's read, and lands in statement position: local Golden_DistributeIntoIf_Test_pickName = function(b) if b then return "big" else return "small" end end A call over a conditional of lambdas was already handled late, at the Lua level, by foldCallThroughScopeCall (the backstop that pushes an applied scope call into its return sites) — but that runs after all IR folds, so it left un-reduced beta redexes allocating a closure per call: local Golden_DistributeIntoIf_Test_applyPicked = function(b) return function(n) if b then return (function(v) return v + 1 end)(n) else return (function(v0) return v0 * 2 end)(n) end end end Distributed at the IR level instead, the pushed call meets betaReduce in the arms: local Golden_DistributeIntoIf_Test_applyPicked = function(b) return function(n) if b then return n + 1 else return n * 2 end end end The arms themselves are never duplicated — each receives one copy of the eliminator — so no gate on the arms is needed. The only syntactically duplicated operands are an application's arguments, admitted by isInlinableValue (references, scalar literals, cheap projection chains: pure and bounded to re-emit, and binder-free, so the copies cannot break the unique-binders invariant). Only the arm that runs evaluates its argument copy, and evaluation order — condition, then arm, then arguments — is the same in both forms. A call whose argument does real work is declined, pinned by the golden's applyExpensive (its argument is a call, weigh(n)), which keeps its IIFE verbatim. The unrestricted transformation (arbitrary consumer contexts) needs the join points of #234 to avoid duplicating the consumer; this rewrite is deliberately the duplication-free subset. The rule subsumes the fold-gated tag-read distribution that reduceKnownConstructor carried since #180 (fire only when every branch folds to a tag string): a tag read now distributes over any conditional and folds in whichever arms turn out to be constructors, so the reflectFoldsThrough guard is deleted. The Eq-against-literal push of #203 keeps its own rule and fold gate unchanged. Golden fallout, all with eval outputs unchanged: NativeLoopsGuard and TailRecM2Shadow move only in IR — their effect-run applications (if b then act else pure unit)(run) now distribute at the IR level, producing exactly the Lua the late backstop already produced. UncurryEffect genuinely improves: distributing the effect-run application turns each arm into a direct tail call, and loopification (which requires the self call in tail position) now converts countdown into a while true loop: local Golden_UncurryEffect_Test_countdown_S_w = function(n) while true do local _ = (function() local _ = Effect_Console_log("tick")() return Effect_Console_log(Data_Show_showIntImpl(n))() end)() if n >= 1 and n ~= 1 then n = n - 1 else return Effect_Console_log("done")() end end end where before the recursion hid behind the conditional-callee shape and stayed a stack-consuming self call: local Golden_UncurryEffect_Test_countdown local Golden_UncurryEffect_Test_countdown_S_w = function(n) local _ = (function() local _ = Effect_Console_log("tick")() return Effect_Console_log(Data_Show_showIntImpl(n))() end)() if n >= 1 and n ~= 1 then return Golden_UncurryEffect_Test_countdown(n - 1)() else return Effect_Console_log("done")() end end Verification: ten focused unit specs (written and confirmed red first) cover each eliminator kind, the fold cascades, and the declined non-trivial argument both through the pipeline and as a direct guard pin; the new golden carries a hand-written eval oracle checked against real execution; the full suite is green, the IR Optimizer group was seed-stressed 12 runs without a failure or hang, and bench/ci counters are unchanged against the committed oracles.

Open Graph Description: Closes #243. Adds pushEliminatorIntoIfBranches to the IR optimizer's rewrite chain: an eliminator applied to a conditional scrutinee — a record field read (ObjectProp), an array read or length ...

X Description: Closes #243. Adds pushEliminatorIntoIfBranches to the IR optimizer's rewrite chain: an eliminator applied to a conditional scrutinee — a record field read (ObjectProp), an array read or len...

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

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:057300ef-2af7-6021-ff51-e3669b3b8e0c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idEC8C:10DACD:9233A0:C439CB:6B00E484
html-safe-nonce31c4b1c69415b4353674b8e00bedb16af346dce4450ae2429f4dc5e9473ab6bb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzhDOjEwREFDRDo5MjMzQTA6QzQzOUNCOjZCMDBFNDg0IiwidmlzaXRvcl9pZCI6IjYxNTU5MzM5MDA4MTczNjAwMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac744259840f4cc407c157d5c57980c4752db093d88a07d7a62849e9be895b466a
hovercard-subject-tagpull_request:4150654895
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/334/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 #243. Adds pushEliminatorIntoIfBranches to the IR optimizer's rewrite chain: an eliminator applied to a conditional scrutinee — a record field read (ObjectProp), an array read or length ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14
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
release624179fb8b88d26ba5bba08894eb60a1c5a1d93d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/pull/334/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F334%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%2F334%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/334/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/334/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/334/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-243/distribute-into-if-brancheshttps://github.com/purescript-lua/purescript-lua/tree/issue-243/distribute-into-if-branches
Conversation 0 https://github.com/purescript-lua/purescript-lua/pull/334
Commits 1 https://github.com/purescript-lua/purescript-lua/pull/334/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/334/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/334/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/334/files
feat(optimizer): distribute an accessor or application into if branches https://github.com/purescript-lua/purescript-lua/pull/334/files#top
Show all changes 1 commit https://github.com/purescript-lua/purescript-lua/pull/334/files
eb950a5 feat(optimizer): distribute an accessor or application into if branch… Unisay Jul 28, 2026 https://github.com/purescript-lua/purescript-lua/pull/334/commits/eb950a5f098ec6827383dc414408e912a9dd11c0
Clear filters https://github.com/purescript-lua/purescript-lua/pull/334/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/334/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/334/files
20260728_140000_unisay_distribute_eliminator_into_if.md https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-f5d5ed907ff1f1455ca0b4d5ae59af314e43b4f7bb7204205a992b83b799e58b
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
corefn.json https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-5f14e51a7eaaa0ea27861890fc96c0acc696e70cb7d993b2b4757cd296c58add
.gitignore https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-8136a8e122fac40f6225415c80b966a5d8f92be55948ed4524236ccff0135e35
golden.txt https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-ca11116959b6b1f45df525a3cd00021bdfc47c89fc929e452a2b2bc539835b84
golden.ir https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-6b2095789db9cfd87a0ccf02bba903057167efa047564fe46a7d734a1cf985d2
golden.lua https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-a270511ed997a56220f1068bc06b097e3fdd068781ab1b358e6fc02678f4aafe
golden.ir https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-a7c115737c237f06d6f1ecc65eb41f0c79a6ea1bf8f45f9b0e0139fcf0acaf43
golden.ir https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-943a6e999776e2a06a4d4209af7f89e9a8d977d6000c31c70ed84e781da2e2ff
golden.ir https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-afce6b8baac1ba8767363e541803baa37fca9f4bbabbf612d91769ec36efc412
golden.lua https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-ac5bf4ca9d458346d8eadd0865c78e8f31b6e180153f1aee53f9874d2313eb8e
Test.lua https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-25efe56f3cbf9cdfcfe9da4936f5ebdee10a4cd0d941538f2542d09cf700fb83
Test.purs https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-af169c7190ee2a5e4709c68a7773ca9972bdc27ed223fcd4a13ee6420990ebb5
changelog.d/20260728_140000_unisay_distribute_eliminator_into_if.mdhttps://github.com/purescript-lua/purescript-lua/pull/334/files#diff-f5d5ed907ff1f1455ca0b4d5ae59af314e43b4f7bb7204205a992b83b799e58b
View file https://github.com/purescript-lua/purescript-lua/blob/eb950a5f098ec6827383dc414408e912a9dd11c0/changelog.d/20260728_140000_unisay_distribute_eliminator_into_if.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/334/{{ revealButtonHref }}
lib/Language/PureScript/Backend/IR/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
View file https://github.com/purescript-lua/purescript-lua/blob/eb950a5f098ec6827383dc414408e912a9dd11c0/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/334/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
test/Language/PureScript/Backend/IR/Optimizer/Spec.hshttps://github.com/purescript-lua/purescript-lua/pull/334/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
View file https://github.com/purescript-lua/purescript-lua/blob/eb950a5f098ec6827383dc414408e912a9dd11c0/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/334/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
https://github.com/purescript-lua/purescript-lua/pull/334/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
test/ps/output/Golden.DistributeIntoIf.Test/corefn.jsonhttps://github.com/purescript-lua/purescript-lua/pull/334/files#diff-5f14e51a7eaaa0ea27861890fc96c0acc696e70cb7d993b2b4757cd296c58add
View file https://github.com/purescript-lua/purescript-lua/blob/eb950a5f098ec6827383dc414408e912a9dd11c0/test/ps/output/Golden.DistributeIntoIf.Test/corefn.json
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/334/files
test/ps/output/Golden.DistributeIntoIf.Test/eval/.gitignorehttps://github.com/purescript-lua/purescript-lua/pull/334/files#diff-8136a8e122fac40f6225415c80b966a5d8f92be55948ed4524236ccff0135e35
View file https://github.com/purescript-lua/purescript-lua/blob/eb950a5f098ec6827383dc414408e912a9dd11c0/test/ps/output/Golden.DistributeIntoIf.Test/eval/.gitignore
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/334/{{ revealButtonHref }}
test/ps/output/Golden.DistributeIntoIf.Test/eval/golden.txthttps://github.com/purescript-lua/purescript-lua/pull/334/files#diff-ca11116959b6b1f45df525a3cd00021bdfc47c89fc929e452a2b2bc539835b84
View file https://github.com/purescript-lua/purescript-lua/blob/eb950a5f098ec6827383dc414408e912a9dd11c0/test/ps/output/Golden.DistributeIntoIf.Test/eval/golden.txt
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/334/{{ revealButtonHref }}
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/334/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.