René's URL Explorer Experiment


Title: Fold a field projection through a foreign-header scope IIFE by Copilot · Pull Request #161 · purescript-lua/purescript-lua · GitHub

Open Graph Title: Fold a field projection through a foreign-header scope IIFE by Copilot · Pull Request #161 · purescript-lua/purescript-lua

X Title: Fold a field projection through a foreign-header scope IIFE by Copilot · Pull Request #161 · purescript-lua/purescript-lua

Description: A ForeignImport with a header lowers to a chunk [ForeignSourceStat fh, return exportsTable]. Projecting a field off it lowers to (function() ...; return exports end)().field — a shape neither the IR-level reduceObjectProp nor the Lua-level reduceTableDefinitionAccessor sees through, since the projected value is a function call, not a table constructor, at either level. Summary Added foldFieldProjectionThroughScopeCall, a Lua-AST rewrite rule that projects the field inside a no-arg immediately-invoked function whose last statement is a return, rather than after the call: (function() …; return e end)().foo → (function() …; return e.foo end)(). Sound because the projection happens within the same activation regardless of whether it's before or after the call returns, so no side effect crosses the boundary. The rewritten projection is immediately re-optimized, so it composes with reduceTableDefinitionAccessor in the same pass. For the Data.Eq.eqChar case from the issue, this fully collapses: ((function() local refEq = function(r1) return function(r2) return r1 == r2 end end return { eqCharImpl = refEq } end)()).eqCharImpl down to: (function() local refEq = function(r1) return function(r2) return r1 == r2 end end return refEq end)() Wired into rewriteRulesInOrder alongside the existing rules. Added unit tests covering full reduction, partial fold (when the returned value isn't an unambiguous table constructor), and decline (callee not a no-arg IIFE). Checklist Added a changelog.d/ fragment for any user-facing change (scriv create in the dev shell), or this change ships nothing releasable (CI, docs, or an internal refactor). In the dev shell (nix develop), fourmolu -i lib/ exe/ test/ and hlint lib/ exe/ test/ are clean. In the dev shell, cabal test all passes; structural goldens were re-accepted on purpose if codegen moved (PSLUA_GOLDEN_ACCEPT=1), and eval/golden.txt still holds.

Open Graph Description: A ForeignImport with a header lowers to a chunk [ForeignSourceStat fh, return exportsTable]. Projecting a field off it lowers to (function() ...; return exports end)().field — a shape neither the I...

X Description: A ForeignImport with a header lowers to a chunk [ForeignSourceStat fh, return exportsTable]. Projecting a field off it lowers to (function() ...; return exports end)().field — a shape neither the I...

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

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:9f48d5d8-12bd-696c-4071-b54db6c3efd3
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idEAC6:1087D4:88662F:B79FF5:6B00E4A9
html-safe-nonceab6687964e920584e1414d2ec03dff74af6b3dfbd0c978474119f238f3de3661
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUM2OjEwODdENDo4ODY2MkY6Qjc5RkY1OjZCMDBFNEE5IiwidmlzaXRvcl9pZCI6Ijg1MDA1NDg1MDMyMzAwMTQ2MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac6d3a39cbda21798c9265dfe253d6a7c957e43932c31348034f4d7af05208ac87
hovercard-subject-tagpull_request:3991711531
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/161/files
twitter:imagehttps://avatars.githubusercontent.com/in/1143301?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/in/1143301?s=400&v=4
og:image:altA ForeignImport with a header lowers to a chunk [ForeignSourceStat fh, return exportsTable]. Projecting a field off it lowers to (function() ...; return exports end)().field — a shape neither the I...
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/161/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F161%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%2F161%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/161/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/161/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/161/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
copilot/fold-field-projection-foreign-header-iifehttps://github.com/purescript-lua/purescript-lua/tree/copilot/fold-field-projection-foreign-header-iife
Conversation 0 https://github.com/purescript-lua/purescript-lua/pull/161
Commits 8 https://github.com/purescript-lua/purescript-lua/pull/161/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/161/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/161/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/161/files
Fold a field projection through a foreign-header scope IIFE https://github.com/purescript-lua/purescript-lua/pull/161/files#top
Show all changes 8 commits https://github.com/purescript-lua/purescript-lua/pull/161/files
16b7f57 Initial plan Copilot Jul 4, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/16b7f57d600e0a1413320e38d2949201bb47803d
b037048 Add foldFieldProjectionThroughScopeCall Lua optimizer rule Copilot Jul 4, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/b0370486f72f2dacb87c9314158496071608e817
9f06133 Add tests and polish foldFieldProjectionThroughScopeCall rule Copilot Jul 4, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/9f061332c0e110e844ba3d4aa4461774e69d8eca
e2c0f50 Refactor foldFieldProjectionThroughScopeCall and fix review comments Copilot Jul 4, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/e2c0f50cd152cd6893c3c1519565a61cff06f53e
d458a5e fix: decline the scope-call projection fold when a leading statement … Unisay Jul 5, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/d458a5ed7d3ea73d629c37bf4c39b40a9e6471ea
6554a51 test: accept goldens moved by the scope-call projection fold Unisay Jul 5, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/6554a51062c5dcd70f94113c8a5e7f3447786719
e804126 Merge remote-tracking branch 'origin/main' into pr161-work Unisay Jul 6, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/e8041266e11c3ea2f1302758e290ea70b178998b
31875aa test: regenerate the CharLiterals golden after merging main Unisay Jul 6, 2026 https://github.com/purescript-lua/purescript-lua/pull/161/commits/31875aa4addaad741402f747ac4eb13e4ba60278
Clear filters https://github.com/purescript-lua/purescript-lua/pull/161/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/161/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/161/files
20260705_231500_unisay_fold_projection_foreign_header.md https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-18daebabe00d007022373307ecb2e664a138c5ee165d258f239e57008c6fbf3f
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0cf3bacadac71b36286d45fe27adeb3db6839bc38502708722e8552067effd2a
golden.lua https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0c90c2d7623d39f887ed98803e0198ce7532cb955c04690d5c518a02bb16d0e1
golden.lua https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-33101f4068d284cd068f09a25c752d3e6d8287f96ae0b55f30ffa86fa165fa8e
golden.lua https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-596c7cb04898e2e110885627fbe42de08e09aa38b253a73bf3a99c9cedfa6bec
golden.lua https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0f80457c0b35d0736c4041d3b36ae67c88c3cce1cb9d8f8114bb21515291c8e2
golden.lua https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
changelog.d/20260705_231500_unisay_fold_projection_foreign_header.mdhttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-18daebabe00d007022373307ecb2e664a138c5ee165d258f239e57008c6fbf3f
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/changelog.d/20260705_231500_unisay_fold_projection_foreign_header.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/161/{{ revealButtonHref }}
lib/Language/PureScript/Backend/Lua/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/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/161/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-729235f45985a9f15089eee44d4ee219effa1f8365a3359452ff51c908fe5e41
test/Language/PureScript/Backend/Lua/Optimizer/Spec.hshttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0cf3bacadac71b36286d45fe27adeb3db6839bc38502708722e8552067effd2a
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/test/Language/PureScript/Backend/Lua/Optimizer/Spec.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/161/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0cf3bacadac71b36286d45fe27adeb3db6839bc38502708722e8552067effd2a
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0cf3bacadac71b36286d45fe27adeb3db6839bc38502708722e8552067effd2a
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0cf3bacadac71b36286d45fe27adeb3db6839bc38502708722e8552067effd2a
test/ps/output/Golden.BugListGenericEq.Test/golden.luahttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0c90c2d7623d39f887ed98803e0198ce7532cb955c04690d5c518a02bb16d0e1
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/test/ps/output/Golden.BugListGenericEq.Test/golden.lua
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/161/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0c90c2d7623d39f887ed98803e0198ce7532cb955c04690d5c518a02bb16d0e1
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0c90c2d7623d39f887ed98803e0198ce7532cb955c04690d5c518a02bb16d0e1
test/ps/output/Golden.CharLiterals.Test/golden.luahttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-33101f4068d284cd068f09a25c752d3e6d8287f96ae0b55f30ffa86fa165fa8e
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/test/ps/output/Golden.CharLiterals.Test/golden.lua
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/161/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-33101f4068d284cd068f09a25c752d3e6d8287f96ae0b55f30ffa86fa165fa8e
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-33101f4068d284cd068f09a25c752d3e6d8287f96ae0b55f30ffa86fa165fa8e
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-33101f4068d284cd068f09a25c752d3e6d8287f96ae0b55f30ffa86fa165fa8e
test/ps/output/Golden.GenericEqTwoTypes.Test/golden.luahttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-596c7cb04898e2e110885627fbe42de08e09aa38b253a73bf3a99c9cedfa6bec
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/test/ps/output/Golden.GenericEqTwoTypes.Test/golden.lua
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/161/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-596c7cb04898e2e110885627fbe42de08e09aa38b253a73bf3a99c9cedfa6bec
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-596c7cb04898e2e110885627fbe42de08e09aa38b253a73bf3a99c9cedfa6bec
test/ps/output/Golden.LongCallbackChain.Test/golden.luahttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0f80457c0b35d0736c4041d3b36ae67c88c3cce1cb9d8f8114bb21515291c8e2
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/test/ps/output/Golden.LongCallbackChain.Test/golden.lua
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/161/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0f80457c0b35d0736c4041d3b36ae67c88c3cce1cb9d8f8114bb21515291c8e2
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0f80457c0b35d0736c4041d3b36ae67c88c3cce1cb9d8f8114bb21515291c8e2
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-0f80457c0b35d0736c4041d3b36ae67c88c3cce1cb9d8f8114bb21515291c8e2
test/ps/output/Golden.TailRecM2Shadow.Test/golden.luahttps://github.com/purescript-lua/purescript-lua/pull/161/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
View file https://github.com/purescript-lua/purescript-lua/blob/31875aa4addaad741402f747ac4eb13e4ba60278/test/ps/output/Golden.TailRecM2Shadow.Test/golden.lua
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/161/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
https://github.com/purescript-lua/purescript-lua/pull/161/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/161/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.