René's URL Explorer Experiment


Title: feat(optimizer): fold a trailing call through a scope call by Unisay · Pull Request #294 · purescript-lua/purescript-lua · GitHub

Open Graph Title: feat(optimizer): fold a trailing call through a scope call by Unisay · Pull Request #294 · purescript-lua/purescript-lua

X Title: feat(optimizer): fold a trailing call through a scope call by Unisay · Pull Request #294 · purescript-lua/purescript-lua

Description: Stacked on #293 (merge that first; this PR's base is issue-230/collapse-tail-scope-call). Problem #293 collapses a scope call sitting directly in tail position, but the corpus's dominant residual shape is one step removed: a scope call whose result is immediately applied — "pick a thunk, then run it". From Golden.UncurryEffect.Test: return (function() if not(n < 1) and n ~= 1 then return Golden_UncurryEffect_Test_countdown(n - 1) else return Effect_Console_log("done") end end)()() Here the applied call (…)()(), not the scope call itself, is the tail expression, so the #293 rule correctly declines, and every invocation still pays a closure allocation and an extra call. The rule foldCallThroughScopeCall rewrites (function() …; return e end)()(args) to (function() …; return e(args) end)(), pushing the trailing application into the tail returns — recursively through a branching tail (IfThenElse/Do), which is exactly where thunk selection lives. Evaluation order is preserved: the leading statements run first, the returned expression is evaluated before the arguments in both forms, and return e(args) is a tail call, so even the activation depth at the moment the result runs is unchanged. The rule declines on: an early return among leading statements (a path the fold would not cover); a fall-off path in the tail chain (the original calls nil and errors, a partial fold would return nil); a multi-valued tail return (the call consumes the first value only, but the fold cannot drop the other results' effects); arguments mentioning ... (rebound inside the no-parameter callee); an argument free name that a body local would capture (checked via the new declaredNamesInActivation against namesInBlock, now imported from Localize); and non-atomic arguments on a branching tail — they are duplicated syntactically into every return site (still evaluated at most once, since a single branch runs), so only names and literals keep that duplication trivial. The exposed plain scope call is then spliced away by collapseTailScopeCall from #293. That required one amendment: the fold builds tail scope calls at depths the bottom-up driver has already passed, so collapseTailScopeCall now re-applies itself to the merged function, re-checking the vararg and budget conditions each round. Without it, Golden.UncurryCtor.Test's main body kept one residual IIFE level; with it, the shape above becomes: 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 not(n < 1) and n ~= 1 then return Golden_UncurryEffect_Test_countdown(n - 1)() else return Effect_Console_log("done")() end end containsReturn is factored out of foldFieldProjectionThroughScopeCall's where clause to the module level, since both folds need the same early-return test. Golden churn Thirteen golden.lua files shrink; .ir and eval goldens are untouched. Highlights: UncurryEffect.countdown_S_w (above) reaches a zero-closure tail; TailRecM2Shadow's untilE predicate drops its per-iteration selection closure; LongApplyChain.applySecond_S_w and BugListGenericEq.eq lose the wrapping scope call around their curried result (the remaining (function(v1) … end)(b) beta-redex is a candidate for a separate literal-application splice, not attempted here); the long-bind family (LongEitherBind, LongExceptBind, LongStackBind, LongWriterBind, RecGroupOrder, UncurryCtor, ArrayOfUnits, Issue37, StringCodePoints) runs its final effect directly instead of through a returned thunk. Verification 11 new unit tests in Optimizer/Spec.hs covering the fold (plain tail, branching tail, nested re-fold, and each decline), plus a bare-rule test for the collapseTailScopeCall self-re-application and an end-to-end composition test through optimizeStatement. cabal test all passes clean twice (fresh Hedgehog seeds), 1037 examples, 0 failures — eval goldens byte-identical, luacheck and the luac/interpreter differential specs green; fourmolu and hlint clean.

Open Graph Description: Stacked on #293 (merge that first; this PR's base is issue-230/collapse-tail-scope-call). Problem #293 collapses a scope call sitting directly in tail position, but the corpus's dominant re...

X Description: Stacked on #293 (merge that first; this PR&#39;s base is issue-230/collapse-tail-scope-call). Problem #293 collapses a scope call sitting directly in tail position, but the corpus&#39;s dom...

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

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:49f0a4d1-bb47-e805-b06b-cec851009212
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC4A8:17FB7:1D6411:25092C:6B00FC5C
html-safe-noncecae9367b4e2c523b6505bc9919446fbf73175368859b8116133cca457e0abaeb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEE4OjE3RkI3OjFENjQxMToyNTA5MkM6NkIwMEZDNUMiLCJ2aXNpdG9yX2lkIjoiNDczMjUyMTkxNzU5NTYzODY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmace4c2b1b32f2591cce31af316dbe78aafec615a47d2f1a6b2dfc99827cf6addb5
hovercard-subject-tagpull_request:4123568755
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/294/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:altStacked on #293 (merge that first; this PR's base is issue-230/collapse-tail-scope-call). Problem #293 collapses a scope call sitting directly in tail position, but the corpus's dominant re...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonee208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187
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
release7dafd017fb7809a839c443dba08622af38e63c09
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/pull/294/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F294%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%2F294%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/294/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/294/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/294/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
feat/fold-call-through-scope-callhttps://github.com/purescript-lua/purescript-lua/tree/feat/fold-call-through-scope-call
Conversation 0 https://github.com/purescript-lua/purescript-lua/pull/294
Commits 2 https://github.com/purescript-lua/purescript-lua/pull/294/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/294/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/294/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/294/files
feat(optimizer): fold a trailing call through a scope call https://github.com/purescript-lua/purescript-lua/pull/294/files#top
Show all changes 2 commits https://github.com/purescript-lua/purescript-lua/pull/294/files
aeb6bf6 feat(optimizer): fold a trailing call through a scope call Unisay Jul 24, 2026 https://github.com/purescript-lua/purescript-lua/pull/294/commits/aeb6bf6a9fa289eb2a95313d487ab9af9a94707c
7d87eb8 bench: accept EffectStep counter oracles after the trailing-call fold Unisay Jul 24, 2026 https://github.com/purescript-lua/purescript-lua/pull/294/commits/7d87eb896f0b0b6f1aad0710fa6d484550b540ca
Clear filters https://github.com/purescript-lua/purescript-lua/pull/294/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/294/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/294/files
fnew_Bench.EffectStep.txt https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-d142955d9df01a6142e53c498a86ac3e67dee7806b0eb7268fac26fa7d3a33f6
tnew_Bench.EffectStep.txt https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-198c2a5de2bf3bdd0d29086b079576aa01f7d2f1aef830a27972d9bb6854612b
trace_effect_step.txt https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-7904b97af15917900da64d4eced661d2fe5064da227bec607e8f39eccdf80f49
20260724_140000_unisay_fold_call_through_scope_call.md https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-ca6f94dca98344cf310495bb904d71689b1ad19b3319c006b617729bf9d4b502
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-0cf3bacadac71b36286d45fe27adeb3db6839bc38502708722e8552067effd2a
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-d14061e081c835eadc7c359ed265bb765b321b458d478c3ba1cd2706ffc1b91f
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-0c90c2d7623d39f887ed98803e0198ce7532cb955c04690d5c518a02bb16d0e1
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-67e4dcf4711ce34fdb0ed8a2c23c4b638cf54c282818689a85be15ec720ace60
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-3058caa776257034fc5c6caf6cdcd1823934a0ed43d330ebdb6e26da662cf83e
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-fca93d3cfc4a9e907e10d93afc283a6d0c09351dbb80b3273e71fef56851d43c
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-f943719d3e54c980d05ce8d70c52e063d34f21edfe9181c6eb2163757d0c686a
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-6c83dcd06227adf985a117c26f276373f15f72bb8d3a61a5673aba8e54d83e58
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-7cb40758f0c4fe0117dcb551a917aaa5a04ec2c37fa895f3a24434fbda6f5d17
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-72af85a05100e41c0bb4d21b300777c481629f733f4af789195ba61dd84c1b9b
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-8f846c962c84e2efb0046e7848c15b3bac3e044be37a2d2ee0620f823f2e9b0f
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-bdd6a9511df955f4252a051367856128627b9e22888fff57be1d79cdfa336503
golden.lua https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-ac5bf4ca9d458346d8eadd0865c78e8f31b6e180153f1aee53f9874d2313eb8e
bench/goldens/fnew_Bench.EffectStep.txthttps://github.com/purescript-lua/purescript-lua/pull/294/files#diff-d142955d9df01a6142e53c498a86ac3e67dee7806b0eb7268fac26fa7d3a33f6
View file https://github.com/purescript-lua/purescript-lua/blob/7d87eb896f0b0b6f1aad0710fa6d484550b540ca/bench/goldens/fnew_Bench.EffectStep.txt
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/294/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-d142955d9df01a6142e53c498a86ac3e67dee7806b0eb7268fac26fa7d3a33f6
bench/goldens/tnew_Bench.EffectStep.txthttps://github.com/purescript-lua/purescript-lua/pull/294/files#diff-198c2a5de2bf3bdd0d29086b079576aa01f7d2f1aef830a27972d9bb6854612b
View file https://github.com/purescript-lua/purescript-lua/blob/7d87eb896f0b0b6f1aad0710fa6d484550b540ca/bench/goldens/tnew_Bench.EffectStep.txt
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/294/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-198c2a5de2bf3bdd0d29086b079576aa01f7d2f1aef830a27972d9bb6854612b
bench/goldens/trace_effect_step.txthttps://github.com/purescript-lua/purescript-lua/pull/294/files#diff-7904b97af15917900da64d4eced661d2fe5064da227bec607e8f39eccdf80f49
View file https://github.com/purescript-lua/purescript-lua/blob/7d87eb896f0b0b6f1aad0710fa6d484550b540ca/bench/goldens/trace_effect_step.txt
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/294/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-7904b97af15917900da64d4eced661d2fe5064da227bec607e8f39eccdf80f49
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-7904b97af15917900da64d4eced661d2fe5064da227bec607e8f39eccdf80f49
changelog.d/20260724_140000_unisay_fold_call_through_scope_call.mdhttps://github.com/purescript-lua/purescript-lua/pull/294/files#diff-ca6f94dca98344cf310495bb904d71689b1ad19b3319c006b617729bf9d4b502
View file https://github.com/purescript-lua/purescript-lua/blob/7d87eb896f0b0b6f1aad0710fa6d484550b540ca/changelog.d/20260724_140000_unisay_fold_call_through_scope_call.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/294/{{ revealButtonHref }}
lib/Language/PureScript/Backend/Lua/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
View file https://github.com/purescript-lua/purescript-lua/blob/7d87eb896f0b0b6f1aad0710fa6d484550b540ca/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/294/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/294/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/294/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.