René's URL Explorer Experiment


Title: Splice a tail-position application of a function literal into the enclosing body · Issue #295 · purescript-lua/purescript-lua · GitHub

Open Graph Title: Splice a tail-position application of a function literal into the enclosing body · Issue #295 · purescript-lua/purescript-lua

X Title: Splice a tail-position application of a function literal into the enclosing body · Issue #295 · purescript-lua/purescript-lua

Description: Problem #293 and #294 eliminated the scope-call closures, but the trailing-call fold stops one step short: when the scope call's tail returned a function literal, the pushed application lands on that literal and stays there. From Golden....

Open Graph Description: Problem #293 and #294 eliminated the scope-call closures, but the trailing-call fold stops one step short: when the scope call's tail returned a function literal, the pushed application lands on th...

X Description: Problem #293 and #294 eliminated the scope-call closures, but the trailing-call fold stops one step short: when the scope call's tail returned a function literal, the pushed application lands o...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Splice a tail-position application of a function literal into the enclosing body","articleBody":"## Problem\n\n#293 and #294 eliminated the scope-call closures, but the trailing-call fold stops one step short: when the scope call's tail returned a function literal, the pushed application lands on that literal and stays there. From `Golden.LongApplyChain.Test` on current main, `applySecond = lift2 (const identity)` compiles to:\n\n```lua\nlocal Golden_LongApplyChain_Test_applySecond_S_w = function(a_S_133, b_S_134)\n  local v_S_625 = (function()\n    ...\n  end)()\n  return (function(v1_S_626)\n    if \"Data.Maybe∷Maybe.Just\" == v_S_625[1] then\n      ...\n    end\n  end)(b_S_134)\nend\n```\n\nThe `(function(v1_S_626) … end)(b_S_134)` tail is a beta-redex in Lua clothing: one closure allocation and one extra call per invocation — per chain node in the 40-deep apply chain of that golden. The same shape sits in `Golden.BugListGenericEq.Test`'s `eq` (per list-element comparison), in `Golden.StringCodePoints.Test`'s `unsafeCodePointAt0` ordering scope (`(function(y_S_1601) … end)(1)`), and in `Golden.Issue37.Test` / `Golden.ArrayOfUnits.Test`.\n\n### Why the pipeline cannot fix this today\n\n`collapseTailScopeCall` (#230) pattern-matches a nullary callee — `FunctionCall (Function [] …) []` — because splicing a parameterized call needs a binding for the parameters, not just a statement splice. `foldCallThroughScopeCall` (#294) is what builds these shapes: it moves the application inward onto the returned literal, but it does not reduce it. And the IR's own beta reduction cannot see them — these literals only materialize during lowering and Lua-level rewriting.\n\n## Approach\n\nGeneralize `collapseTailScopeCall`: when the last statement of a function body is `return (function(p1, …, pn) \u003cstmts> end)(a1, …, an)` and every parameter is named, splice as a single simultaneous binding followed by the body:\n\n```lua\nlocal p1, …, pn = a1, …, an\n\u003cstmts>\n```\n\nThe one-statement `local` is the exact translation of Lua's call binding: the whole right-hand list is evaluated before any name binds (so an argument reading an outer `x` can never see a parameter named `x`), a multi-valued expression last in the list expands, missing values fill with `nil`, and extra values are evaluated then discarded — the same adjustment rules a call performs. And unlike #294's fold, the arguments do not move across any scope boundary: the call site already was the parent's tail return, so they are evaluated in the same environment at the same program point. The tail-position safety argument from #230 carries over verbatim for `\u003cstmts>`.\n\nConditions on top of the existing rule:\n\n- every parameter is `ParamNamed`: a `ParamVararg` cannot be bound by a `local`, and `ParamUnused` has no name to bind (IR-derived literals always name their parameters, so declining costs nothing);\n- zero parameters with nonempty arguments declines (`local = a1` does not exist); zero parameters with zero arguments is exactly the current rule, so the natural implementation is a generalization where the binding statement degenerates to nothing;\n- the local budget from #230 additionally counts the n parameter locals;\n- the vararg check on `\u003cstmts>` and the self-re-application after the merge are inherited unchanged.\n\nA duplicate parameter name (`function(x, x)`) binds the last occurrence in Lua, and `local x, x = a, b` reproduces exactly that; still, declining on duplicates is one `ordNub` away and removes the need to reason about it.\n\nThe alias local this leaves behind (`local v1_S_626 = b_S_134` above) is an accepted cost: one register slot inside the budget, no allocation, no call. Cleaning single-use aliases is a separate (IR- or Lua-level copy-propagation) concern.\n\n## Prerequisites / Relations\n\nBuilds directly on #230 (PR #293) and PR #294 — the fold is what exposes the redex in tail position. Independent of the magic-do redesign tracked in #228. Non-tail occurrences (a literal application in a `local` initializer, e.g. the `v_S_625` header above) are out of scope: splicing those needs return-to-assignment rewriting, a different transform.\n\n## Verification / Measurement\n\n`applySecond_S_w` becomes straight-line (zero closures per invocation):\n\n```lua\nlocal Golden_LongApplyChain_Test_applySecond_S_w = function(a_S_133, b_S_134)\n  local v_S_625 = (function()\n    ...\n  end)()\n  local v1_S_626 = b_S_134\n  if \"Data.Maybe∷Maybe.Just\" == v_S_625[1] then\n    ...\n  end\nend\n```\n\nThe splice is visible in the `LongApplyChain`, `BugListGenericEq`, `StringCodePoints`, `Issue37` and `ArrayOfUnits` goldens; eval goldens unchanged. The `bench/ci` FNEW census should drop wherever the shape sits in a function body, with the corresponding trace-abort sites disappearing from the trace reports.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-24T09:55:42Z","url":"https://github.com/purescript-lua/purescript-lua/issues/295"}

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:ca004cbf-5b25-28c5-3598-b225f8d211ad
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB0A6:34EA7D:CF1CFF:109FC4E:6B00EF29
html-safe-nonce34ef1a8b9dc6896ff0f7f5eac291d168c0a243328f089c4434b5eb897ce2e6f5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEE2OjM0RUE3RDpDRjFDRkY6MTA5RkM0RTo2QjAwRUYyOSIsInZpc2l0b3JfaWQiOiI2MDkwMjEyMDkyMjEwNjM4NjM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmace667d85055c59160cc750a6956915d0ba7953d0461559a767e63feedfcf5c431
hovercard-subject-tagissue:4967330594
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/295/issue_layout
twitter:imagehttps://opengraph.githubassets.com/552b814885fb1fb6bee6ca974f09a55669c2b7f9d5ddef04301dbf671d48099e/purescript-lua/purescript-lua/issues/295
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/552b814885fb1fb6bee6ca974f09a55669c2b7f9d5ddef04301dbf671d48099e/purescript-lua/purescript-lua/issues/295
og:image:altProblem #293 and #294 eliminated the scope-call closures, but the trailing-call fold stops one step short: when the scope call's tail returned a function literal, the pushed application lands on th...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameUnisay
hostnamegithub.com
expected-hostnamegithub.com
None4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc
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
release9983dd5da06943f833c971dd5b6bc988e2858be5
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/issues/295#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2F295
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%2F295
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/295
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/295
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/295
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/295
New issuehttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/295
#296https://github.com/purescript-lua/purescript-lua/pull/296
Splice a tail-position application of a function literal into the enclosing bodyhttps://github.com/purescript-lua/purescript-lua/issues/295#top
#296https://github.com/purescript-lua/purescript-lua/pull/296
https://github.com/Unisay
OptimisationA Compiler Optimisationhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22Optimisation%22
area: codegenLua code generation / printinghttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20codegen%22
enhancementNew feature or requesthttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com/Unisay
Unisayhttps://github.com/Unisay
on Jul 24, 2026https://github.com/purescript-lua/purescript-lua/issues/295#issue-4967330594
#293https://github.com/purescript-lua/purescript-lua/pull/293
#294https://github.com/purescript-lua/purescript-lua/pull/294
#230https://github.com/purescript-lua/purescript-lua/issues/230
#294https://github.com/purescript-lua/purescript-lua/pull/294
#294https://github.com/purescript-lua/purescript-lua/pull/294
#230https://github.com/purescript-lua/purescript-lua/issues/230
Collapse a tail-position IIFE into the enclosing function body #230https://github.com/purescript-lua/purescript-lua/issues/230
#230https://github.com/purescript-lua/purescript-lua/issues/230
#293https://github.com/purescript-lua/purescript-lua/pull/293
#294https://github.com/purescript-lua/purescript-lua/pull/294
#228https://github.com/purescript-lua/purescript-lua/issues/228
Unisayhttps://github.com/Unisay
on Jul 24, 2026https://github.com/purescript-lua/purescript-lua/issues/295#event-28429672928
Unisayhttps://github.com/Unisay
enhancementNew feature or requesthttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22enhancement%22
area: codegenLua code generation / printinghttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20codegen%22
OptimisationA Compiler Optimisationhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22Optimisation%22
on Jul 24, 2026https://github.com/purescript-lua/purescript-lua/issues/295#event-28429673539
Unisayhttps://github.com/Unisay
completedhttps://github.com/purescript-lua/purescript-lua/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#296https://github.com/purescript-lua/purescript-lua/pull/296
on Jul 24, 2026https://github.com/purescript-lua/purescript-lua/issues/295#event-28440544257
Sign up for freehttps://github.com/signup?return_to=https://github.com/purescript-lua/purescript-lua/issues/295
Sign in to commenthttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/295
Unisayhttps://github.com/Unisay
OptimisationA Compiler Optimisationhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22Optimisation%22
area: codegenLua code generation / printinghttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20codegen%22
enhancementNew feature or requesthttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22enhancement%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.