René's URL Explorer Experiment


Title: Fix unbound variable references produced by inlining (#37) by Unisay · Pull Request #43 · purescript-lua/purescript-lua · GitHub

Open Graph Title: Fix unbound variable references produced by inlining (#37) by Unisay · Pull Request #43 · purescript-lua/purescript-lua

X Title: Fix unbound variable references produced by inlining (#37) by Unisay · Pull Request #43 · purescript-lua/purescript-lua

Description: The IR refers to locals by name plus a De Bruijn-style index, and the scoping rule for Let was inconsistent across the codebase. renameShadowedNames, DCE and the Lua codegen all treat let bindings sequentially: a standalone binding's RHS sees the earlier siblings of the same let, while the binding's own name points at an outer binder. The last part is the subtle bit. Standalone bindings are non-recursive, so a binding's own name is not in scope in its own RHS; if the same name is also bound further out, a self-reference there resolves to that outer binder: let x = 1 -- outer binder in let x = x + 1 -- this `x` is the outer one (1), not the binding itself in x -- this `x` is the inner one (2) The index disambiguates which x is meant. shift, substitute and countFreeRefs implemented the opposite rule: they bumped the index for the binding's own name and ignored siblings. So when the optimizer inlined a non-exported binding whose body contained a let with a sibling-bound reference (Bind1 in the issue), substituting it under a binder with the same name shifted that reference past its binder. DCE then dropped the binder as unused, and the codegen printed the dangling Ref (Local Bind1) 1 as Bind11, a variable that exists nowhere. This is also why #38 could not reproduce the problem: without an export list nothing gets inlined, since every top-level binding becomes an export. What changed: shift, substitute and countFreeRefs now thread the scope through let groupings left to right (mapAccumL), matching the convention used everywhere else. The codegen no longer renders a local reference with a non-zero index by gluing the index onto the name. After renameShadowedNames such a reference is never valid, so compilation now fails with UnexpectedRefBound instead of emitting broken Lua. Regression coverage: the golden test from #38 with the export list change from #39 applied, unit tests pinning the sequential scoping convention for all three functions, and an optimizer test that inlines through shadowing lets and asserts no reference is left unbound. No other golden files changed. Closes #37. Supersedes #38 and #39. Thanks @Renegatto for the repro and for spotting that the export list is what triggers it.

Open Graph Description: The IR refers to locals by name plus a De Bruijn-style index, and the scoping rule for Let was inconsistent across the codebase. renameShadowedNames, DCE and the Lua codegen all treat let bindings ...

X Description: The IR refers to locals by name plus a De Bruijn-style index, and the scoping rule for Let was inconsistent across the codebase. renameShadowedNames, DCE and the Lua codegen all treat let bindings ...

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

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:8e53517f-a67e-5d51-2220-e8ee9e4dbbb6
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id988C:26ECEB:9A36BB:C7E71A:6B00DFDF
html-safe-nonceeca2b322a63e654da1b5e0d89db57ad4cd695c133acda70d1a039adf62ffdffd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODhDOjI2RUNFQjo5QTM2QkI6QzdFNzFBOjZCMDBERkRGIiwidmlzaXRvcl9pZCI6IjYwMDIyMjQ4MzgxMzM5OTc1MzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc0d332cd1f9abcef832c49b0bdbdff6e99cd3c6758b8afed7ae79bae4294745a
hovercard-subject-tagpull_request:3853741023
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/43/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:altThe IR refers to locals by name plus a De Bruijn-style index, and the scoping rule for Let was inconsistent across the codebase. renameShadowedNames, DCE and the Lua codegen all treat let bindings ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf
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
release5425dc24e8bd8d6fca9641a12afc984825a43875
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/pull/43/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F43%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%2F43%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/43/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/43/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/43/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
yura/fix-issue-37https://github.com/purescript-lua/purescript-lua/tree/yura/fix-issue-37
Conversation 1 https://github.com/purescript-lua/purescript-lua/pull/43
Commits 5 https://github.com/purescript-lua/purescript-lua/pull/43/commits
Checks 1 https://github.com/purescript-lua/purescript-lua/pull/43/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/43/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/43/files
Fix unbound variable references produced by inlining (#37) https://github.com/purescript-lua/purescript-lua/pull/43/files#top
Show all changes 5 commits https://github.com/purescript-lua/purescript-lua/pull/43/files
47b3316 test: reproduce issue #37 (undefined variable in compiled code) Unisay Jun 12, 2026 https://github.com/purescript-lua/purescript-lua/pull/43/commits/47b3316bf3e82a5758485d7953b0b304dbd56623
51d1b79 test: pin sequential (let*) scoping convention for shift/substitute/c… Unisay Jun 12, 2026 https://github.com/purescript-lua/purescript-lua/pull/43/commits/51d1b794dbcd71010c6829a86c163d83e394d112
3c64f5a fix: align shift/substitute/countFreeRefs with sequential Let scoping… Unisay Jun 12, 2026 https://github.com/purescript-lua/purescript-lua/pull/43/commits/3c64f5ae4fed3a6d1629d0c6f8f46dd2ab6b5411
55a7574 chore(test): fix typo in golden spec progress message Unisay Jun 12, 2026 https://github.com/purescript-lua/purescript-lua/pull/43/commits/55a75747b984a3504f80b135ea06527b1061eed5
69bd23c docs: add Note [Sequential scoping of Let bindings]; fix same defect … Unisay Jun 12, 2026 https://github.com/purescript-lua/purescript-lua/pull/43/commits/69bd23c11c074f28fa3ae78e439d3dc6716b1b36
Clear filters https://github.com/purescript-lua/purescript-lua/pull/43/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/43/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/43/files
DCE.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
Linker.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-114e667388f6a8a686b7993566e51078f236daa12b3d6da94e4935c60f7c3400
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Types.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
Lua.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-11295f6f97401e5cc1fdfa2a8caa3fc80edc56cd58262d3de010e803f8d3640f
pslua.cabal https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-cf0302393cf6443df4429c19c0fc326753a83405d0366075a98ac2753e5e1ab2
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-48105ebdce501cd50056cda7f2bee222ce1dc3192559f041c3a40b5035c9b68b
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-bc1fa00b08aad14838a06a1bfed8842087ce893a8b977678c68deea85c0610a4
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-e10bc6586bdc2afb3eed89cc8935f6ff0059d32a82668123ce53808a6046c019
Main.hs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-9e8bdd24d557cfe94781d844e68e97f4b626c833420d18df4e04619a54273b34
Test.purs https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-cc42cc1083485f584643391dd9676e738b0b74b10f193402374aef214e27c947
corefn.json https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-dcca3e2e036963352c61e6b6127568fa63872b25a707fc3a5923e7a0e90c9e0c
golden.ir https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-214ade9cc7aa9bbbaeb07927c013dfa7eeb9f9e2f12ed14f5d31fc98a446bd13
golden.lua https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-67e4dcf4711ce34fdb0ed8a2c23c4b638cf54c282818689a85be15ec720ace60
lib/Language/PureScript/Backend/IR/DCE.hshttps://github.com/purescript-lua/purescript-lua/pull/43/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
View file https://github.com/purescript-lua/purescript-lua/blob/69bd23c11c074f28fa3ae78e439d3dc6716b1b36/lib/Language/PureScript/Backend/IR/DCE.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/43/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
lib/Language/PureScript/Backend/IR/Linker.hshttps://github.com/purescript-lua/purescript-lua/pull/43/files#diff-114e667388f6a8a686b7993566e51078f236daa12b3d6da94e4935c60f7c3400
View file https://github.com/purescript-lua/purescript-lua/blob/69bd23c11c074f28fa3ae78e439d3dc6716b1b36/lib/Language/PureScript/Backend/IR/Linker.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/43/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-114e667388f6a8a686b7993566e51078f236daa12b3d6da94e4935c60f7c3400
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-114e667388f6a8a686b7993566e51078f236daa12b3d6da94e4935c60f7c3400
lib/Language/PureScript/Backend/IR/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
View file https://github.com/purescript-lua/purescript-lua/blob/69bd23c11c074f28fa3ae78e439d3dc6716b1b36/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/43/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
lib/Language/PureScript/Backend/IR/Types.hshttps://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
View file https://github.com/purescript-lua/purescript-lua/blob/69bd23c11c074f28fa3ae78e439d3dc6716b1b36/lib/Language/PureScript/Backend/IR/Types.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/43/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/43/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/43/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/43/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.