René's URL Explorer Experiment


Title: fix: lower De Bruijn indices when a binder is removed (#56) by Unisay · Pull Request #70 · purescript-lua/purescript-lua · GitHub

Open Graph Title: fix: lower De Bruijn indices when a binder is removed (#56) by Unisay · Pull Request #70 · purescript-lua/purescript-lua

X Title: fix: lower De Bruijn indices when a binder is removed (#56) by Unisay · Pull Request #70 · purescript-lua/purescript-lua

Description: Closes #56. Compiling Data.Array aborted with Unexpected bound reference: Ref Nothing (Local (Name "b")) 1, which blocked the purescript-lua-arrays port entirely. The single declaration Data.Array.foldRecM was enough to trigger it. Root cause The IR addresses locals with per-name De Bruijn indices: Ref (Local n) k means the k-th enclosing binder named n, counting from the innermost. When an optimizer pass removes a binder, every reference that pointed past that binder (index ≥ 1, because it was skipping over it) has to drop by one. Two passes removed a binder and skipped that repair: betaReduce drops the applied lambda. In foldRecM f b array = tailRecM2 go b 0, the outer parameter b collides with tailRecM2's own third parameter b. Inlining tailRecM2 (a single-use dictionary accessor) beta-reduces under that inner b; capture avoidance shifts the outer reference up to index 1, and removing the inner binder left it stranded there instead of lowering it back to 0. dead-code elimination blanks an unused named binder to ParamUnused. If an inner lambda's parameter is unused but its body still references an outer binder of the same name (at index 1, skipping the inner one), blanking the binder must lower that reference to 0. This is the same class of bug; the well-scopedness property below found it. Both sites now repair the survivors with a new unshift, the inverse of shift 1. To keep the two from drifting apart, shift is refactored to share its scope-tracking traversal (overFreeIndex) with unshift; the strict minIndex < index guard leaves genuine inner references alone and keeps the Natural index from underflowing. Tests There was no unit coverage for the De Bruijn primitives at all, so the original bug could only surface as an integration crash. This adds a layer that exercises them directly: Types spec: round-trip unshift . shift 1 ≡ id and a substitute-identity law as properties, plus the classic capture-avoiding substitution examples (capture under a same-named binder, pass-through of an unrelated binder, a shadowing binder stopping the substitution, a reference reaching past one). Optimizer spec: a well-scopedness invariant (optimizing a well-scoped expression must never produce an unbound local) run over a generator of well-scoped terms through the full pipeline. This is what surfaced the DCE sibling bug. Deterministic regressions pin both passes: the foldRecM shape for beta reduction, a shadowing unused binder for DCE. Golden: Golden.TailRecM2Shadow, an eval golden over a tailRecM2-based foldRecM paraphrase whose accumulator parameter is named b to reproduce the original collision. Verified: cabal test is green, and pslua --entry Data.Array now compiles purescript-lua-arrays to luacheck-clean Lua.

Open Graph Description: Closes #56. Compiling Data.Array aborted with Unexpected bound reference: Ref Nothing (Local (Name "b")) 1, which blocked the purescript-lua-arrays port entirely. The single declaration D...

X Description: Closes #56. Compiling Data.Array aborted with Unexpected bound reference: Ref Nothing (Local (Name &quot;b&quot;)) 1, which blocked the purescript-lua-arrays port entirely. The single decla...

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

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:ae418724-305a-6233-eba9-98e320b0165f
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idCA54:27E5CD:8665AA:AF8EA1:6B00DBBA
html-safe-noncebb58117125f44a001a03c38deb132f930fbf4536e6d8f6b599f02e495e8aecbe
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTU0OjI3RTVDRDo4NjY1QUE6QUY4RUExOjZCMDBEQkJBIiwidmlzaXRvcl9pZCI6IjM2NjEzNzQwNDAxMTY4NzgyNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaca4ab0fb615b81aaa9cfbc25cd2c6161dc1d0178aa81d9171f232401e24236562
hovercard-subject-tagpull_request:3863045550
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/70/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 #56. Compiling Data.Array aborted with Unexpected bound reference: Ref Nothing (Local (Name "b")) 1, which blocked the purescript-lua-arrays port entirely. The single declaration D...
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/70/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F70%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%2F70%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/70/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/70/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/70/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-56/beta-reduce-unshifthttps://github.com/purescript-lua/purescript-lua/tree/issue-56/beta-reduce-unshift
Conversation 1 https://github.com/purescript-lua/purescript-lua/pull/70
Commits 1 https://github.com/purescript-lua/purescript-lua/pull/70/commits
Checks 1 https://github.com/purescript-lua/purescript-lua/pull/70/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/70/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/70/files
fix: lower De Bruijn indices when a binder is removed (#56) https://github.com/purescript-lua/purescript-lua/pull/70/files#top
Show all changes 1 commit https://github.com/purescript-lua/purescript-lua/pull/70/files
7e1a852 fix: lower De Bruijn indices when a binder is removed (#56) Unisay Jun 14, 2026 https://github.com/purescript-lua/purescript-lua/pull/70/commits/7e1a8529bbe90961249ba026cac26d8ef19a50cb
Clear filters https://github.com/purescript-lua/purescript-lua/pull/70/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/70/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/70/files
DCE.hs https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Types.hs https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
Gen.hs https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-77a425583fc22a69b2aab27d1e2226e67dc605610d4b723925e81fe69638da28
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-bc1fa00b08aad14838a06a1bfed8842087ce893a8b977678c68deea85c0610a4
Test.purs https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-cd6a8ea75eb1a5f4c4c4d2cb139f1288a5b37af43bf75a66c780a01e9d2d7095
corefn.json https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-8aa953ec94ad599fe2b93db4a28890606cb02b844253705cde04781ab57bcf06
.gitignore https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-ab61c5b56a8643955de03b0f996b1148b7d44558e0f0162fdf0fa553a777f8c5
golden.txt https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-926254ed2a1e7edfec7bed1145442fee4afdd8e63258ab2315cd1db5c23665ab
golden.ir https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-943a6e999776e2a06a4d4209af7f89e9a8d977d6000c31c70ed84e781da2e2ff
golden.lua https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
spago.dhall https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-f530eb9e6c28647654321ce547bc67f1dbf801c1a072a16bf4463cd6f83531ce
lib/Language/PureScript/Backend/IR/DCE.hshttps://github.com/purescript-lua/purescript-lua/pull/70/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
View file https://github.com/purescript-lua/purescript-lua/blob/7e1a8529bbe90961249ba026cac26d8ef19a50cb/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/70/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-a109a10f5eb1daf399873d5f872423b876fe04a88668660f01506076cefe8f78
lib/Language/PureScript/Backend/IR/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/70/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
View file https://github.com/purescript-lua/purescript-lua/blob/7e1a8529bbe90961249ba026cac26d8ef19a50cb/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/70/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
lib/Language/PureScript/Backend/IR/Types.hshttps://github.com/purescript-lua/purescript-lua/pull/70/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
View file https://github.com/purescript-lua/purescript-lua/blob/7e1a8529bbe90961249ba026cac26d8ef19a50cb/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/70/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-c628fb950daac01f47dc80a039e24b8b452f9d578ab0d55483d10758027b4884
test/Language/PureScript/Backend/IR/Gen.hshttps://github.com/purescript-lua/purescript-lua/pull/70/files#diff-77a425583fc22a69b2aab27d1e2226e67dc605610d4b723925e81fe69638da28
View file https://github.com/purescript-lua/purescript-lua/blob/7e1a8529bbe90961249ba026cac26d8ef19a50cb/test/Language/PureScript/Backend/IR/Gen.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/70/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-77a425583fc22a69b2aab27d1e2226e67dc605610d4b723925e81fe69638da28
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-77a425583fc22a69b2aab27d1e2226e67dc605610d4b723925e81fe69638da28
https://github.com/purescript-lua/purescript-lua/pull/70/files#diff-77a425583fc22a69b2aab27d1e2226e67dc605610d4b723925e81fe69638da28
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/70/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/70/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.