René's URL Explorer Experiment


Title: feat(optimizer): collapse a tail-position IIFE into the enclosing function body (#230) by Unisay · Pull Request #293 · purescript-lua/purescript-lua · GitHub

Open Graph Title: feat(optimizer): collapse a tail-position IIFE into the enclosing function body (#230) by Unisay · Pull Request #293 · purescript-lua/purescript-lua

X Title: feat(optimizer): collapse a tail-position IIFE into the enclosing function body (#230) by Unisay · Pull Request #293 · purescript-lua/purescript-lua

Description: Closes #230. Problem #227 left one residual closure on the mk half: an effectful uncurried definition whose body is a statement sequence runs its magic-do chunk through a tail IIFE. From Golden.UncurriedLift.Test: local Golden_UncurriedLift_Test_logTwice = function(a_S_673, b_S_674) return (function() local _ = Effect_Console_log(a_S_673)() return Effect_Console_log(b_S_674)() end)() end The IR cannot fix this (beta reduction refuses effect-run redexes by design to protect magic-do's chunking, and the #226 codegen fusion covers only single-AppN thunk bodies), so this lands as a Lua-level rewrite. The rule collapseTailScopeCall in Language.PureScript.Backend.Lua.Optimizer: when a function body's last statement is return (function() end)(), splice in place of the return: local Golden_UncurriedLift_Test_logTwice = function(a_S_673, b_S_674) local _ = Effect_Console_log(a_S_673)() return Effect_Console_log(b_S_674)() end Tail position is what makes the splice safe. The parent's return call forwarded all of the call's results (an explicit Paren would adjust them to one and correctly fails the match), so after the splice the inner returns — or falling off the end, for zero results — produce the same values directly. Early returns among the leading statements exit the parent on their own paths either way, so unlike foldFieldProjectionThroughScopeCall the rule needs no early-return decline. The issue's name-collision condition is discharged by construction: the splice point is the parent's last statement, so no parent code follows it, and Lua's positional local scoping keeps every spliced reference resolving exactly as it did inside the closure — a re-declaration of a name the parent already binds is legal and shadows only from that point on. Two conditions are checked. The spliced statements must not mention ... in their own scope — a no-parameter function cannot legally do so, but on such (only ever hand-written) input the splice would rebind ... to the parent's varargs instead of failing to load; the check reuses chunkScopeUsesVararg, now exported from Lua.Linker.Foreign. And a local budget (#19): the splice undoes exactly the chunking with which magic-do bounds any single function's locals, so the merged body (parameters plus activationLocalSlots, a proto-boundary-respecting over-approximation) must fit the same workingLocalCeiling the storage passes budget against. LuaLimits is threaded through the rewrite chain for this, which is why foldFieldProjectionThroughScopeCall and optimizeExpression now take the parameter. Applied bottom-up by the existing driver, nested chunk chains collapse as far as the budget allows and no further: in Golden.LongDoBlock.Test the two adjacent magic-do chunks (150 + 149 locals against a ceiling of 180) keep their boundary, so that golden is unchanged. Golden churn Exactly one golden moves — Golden.UncurriedLift.Test/golden.lua, the diff shown above. Every other tail IIFE in the corpus is a correct decline: the remaining shapes are result-consuming double calls where the callee is not a function literal, e.g. from Golden.LongApplyChain.Test: return (function() ... return function(v1_S_626) ... end end)()(b_S_134) Eval goldens and .ir goldens are untouched. Verification 8 new unit tests in Optimizer/Spec.hs: the splice, bottom-up cascading, splicing past a leading early return, zero-value fall-off, and declines for parameterized callees, budget overflow (asserted on both sides of a tiny custom LuaLimits), and activation-scope varargs (with the nested-proto non-decline counterpart). cabal test all passes clean twice (fresh Hedgehog seeds), 1026 examples, 0 failures; fourmolu and hlint clean.

Open Graph Description: Closes #230. Problem #227 left one residual closure on the mk half: an effectful uncurried definition whose body is a statement sequence runs its magic-do chunk through a tail IIFE. From Golden.Unc...

X Description: Closes #230. Problem #227 left one residual closure on the mk half: an effectful uncurried definition whose body is a statement sequence runs its magic-do chunk through a tail IIFE. From Golden.Unc...

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

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:b363e1c4-d14d-0a02-bf83-1d294b6409f7
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB468:1EC9BC:94F182:BF47FE:6B00EF7B
html-safe-nonce2227ddb6a7b1dc6f8a6cb3bcc4e866682fba04529110166f4dd8b28145d24e37
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDY4OjFFQzlCQzo5NEYxODI6QkY0N0ZFOjZCMDBFRjdCIiwidmlzaXRvcl9pZCI6IjcyMzMwMjEyNTUyMzI4NDM2NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac48dee2f7161891cc11f04578b836f7f18710457011d801270391d8cbc66691dc
hovercard-subject-tagpull_request:4123383812
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/293/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 #230. Problem #227 left one residual closure on the mk half: an effectful uncurried definition whose body is a statement sequence runs its magic-do chunk through a tail IIFE. From Golden.Unc...
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/293/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F293%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%2F293%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/293/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/293/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/293/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-230/collapse-tail-scope-callhttps://github.com/purescript-lua/purescript-lua/tree/issue-230/collapse-tail-scope-call
Conversation 0 https://github.com/purescript-lua/purescript-lua/pull/293
Commits 1 https://github.com/purescript-lua/purescript-lua/pull/293/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/293/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/293/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/293/files
feat(optimizer): collapse a tail-position IIFE into the enclosing function body (#230) https://github.com/purescript-lua/purescript-lua/pull/293/files#top
Show all changes 1 commit https://github.com/purescript-lua/purescript-lua/pull/293/files
981ce01 feat(optimizer): collapse a tail-position IIFE into the enclosing fun… Unisay Jul 24, 2026 https://github.com/purescript-lua/purescript-lua/pull/293/commits/981ce012136a32c8de944685aaad3d9565caeb2e
Clear filters https://github.com/purescript-lua/purescript-lua/pull/293/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/293/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/293/files
20260724_130000_unisay_collapse_tail_scope_call.md https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-982960231d67078c44e9c4f1207647d2eb42811fb175345c7b4e82d307207335
Foreign.hs https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-db9f6275e54091ae1d1bb56227c508bb91ce74f5b7beca417f7d52549450ef09
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-0cf3bacadac71b36286d45fe27adeb3db6839bc38502708722e8552067effd2a
golden.lua https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-5921e666a0348af0dd78380b07fead46422cafb2d7dadb38988ae54c01af9164
changelog.d/20260724_130000_unisay_collapse_tail_scope_call.mdhttps://github.com/purescript-lua/purescript-lua/pull/293/files#diff-982960231d67078c44e9c4f1207647d2eb42811fb175345c7b4e82d307207335
View file https://github.com/purescript-lua/purescript-lua/blob/981ce012136a32c8de944685aaad3d9565caeb2e/changelog.d/20260724_130000_unisay_collapse_tail_scope_call.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/293/{{ revealButtonHref }}
lib/Language/PureScript/Backend/Lua/Linker/Foreign.hshttps://github.com/purescript-lua/purescript-lua/pull/293/files#diff-db9f6275e54091ae1d1bb56227c508bb91ce74f5b7beca417f7d52549450ef09
View file https://github.com/purescript-lua/purescript-lua/blob/981ce012136a32c8de944685aaad3d9565caeb2e/lib/Language/PureScript/Backend/Lua/Linker/Foreign.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/293/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-db9f6275e54091ae1d1bb56227c508bb91ce74f5b7beca417f7d52549450ef09
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-db9f6275e54091ae1d1bb56227c508bb91ce74f5b7beca417f7d52549450ef09
lib/Language/PureScript/Backend/Lua/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
View file https://github.com/purescript-lua/purescript-lua/blob/981ce012136a32c8de944685aaad3d9565caeb2e/lib/Language/PureScript/Backend/Lua/Optimizer.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/293/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/293/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/293/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.