René's URL Explorer Experiment


Title: IR DCE mishandles Let bindings: no unshift after dropping a dead shadowing binder, body scope resolved in reverse · Issue #134 · purescript-lua/purescript-lua · GitHub

Open Graph Title: IR DCE mishandles Let bindings: no unshift after dropping a dead shadowing binder, body scope resolved in reverse · Issue #134 · purescript-lua/purescript-lua

X Title: IR DCE mishandles Let bindings: no unshift after dropping a dead shadowing binder, body scope resolved in reverse · Issue #134 · purescript-lua/purescript-lua

Description: Two defects in the Let handling of Language.PureScript.Backend.IR.DCE, the same bug class as #37 and #56 (De Bruijn index bookkeeping under Note [Sequential scoping of Let bindings]). Bug 1: dropping a dead Let binder leaves references p...

Open Graph Description: Two defects in the Let handling of Language.PureScript.Backend.IR.DCE, the same bug class as #37 and #56 (De Bruijn index bookkeeping under Note [Sequential scoping of Let bindings]). Bug 1: droppi...

X Description: Two defects in the Let handling of Language.PureScript.Backend.IR.DCE, the same bug class as #37 and #56 (De Bruijn index bookkeeping under Note [Sequential scoping of Let bindings]). Bug 1: droppi...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"IR DCE mishandles Let bindings: no unshift after dropping a dead shadowing binder, body scope resolved in reverse","articleBody":"Two defects in the `Let` handling of `Language.PureScript.Backend.IR.DCE`, the same bug class as #37 and #56 (De Bruijn index bookkeeping under Note [Sequential scoping of Let bindings]).\n\n## Bug 1: dropping a dead `Let` binder leaves references pointing one binder too far\n\nWhen `dceAnnotatedExp` blanks an unused `Abs` parameter it lowers the body references with `unshift` (that was the #56 fix). The `Let` case has the same obligation and skips it: a dead binding is removed from the group, but references with index >= 1 that skipped over it are left as they were.\n\n### Repro\n\n```haskell\n-- let x = 1 in (let x = \u003cdead> in x@1)     -- x@1 refers to the outer x\neliminateDeadCode $ UberModule [] [] $ pure . (Name \"main\",) $\n  lets (Standalone (noAnn, x, literalInt 1) :| [])\n       (lets (Standalone (noAnn, x, exception \"dead\") :| [])\n             (refLocal x 1))\n```\n\nActual: `let x = 1 in x@1`. The inner binding is gone but the reference still has index 1, and only one `x` binder remains. Expected: `let x = 1 in x@0`.\n\nIn the full pipeline the dangling reference survives `renameShadowedNames` (index 1 with a single binder in scope means no rename) and the Lua codegen rejects it with `UnexpectedRefBound`, so the compiler crashes on valid input. When more same-name binders remain above the removed one, the reference instead resolves to the wrong binder and the miscompile is silent. Reachable the same way #56 was: inlining shifts a reference past a shadowing binder (creating `x@1`), and a later pass kills that binder's uses.\n\nFix: when a binder is dropped from a `Let`, apply `unshift name 0` to the body and to the RHSs of the groupings that follow it in the same `Let`, mirroring the `Abs` case.\n\n## Bug 2: the scope for the `Let` body is built in reverse order\n\n`adjacencyListForExpr` builds the scope the body's references are resolved against with a right fold:\n\n```haskell\nscope' = foldr addToScope scope (listGrouping =\u003c\u003c toList groupings)\n```\n\n`addLocalToScope` puts the most recently added binder at index 0, so with `foldr` the *first* binding of a name lands at index 0. The convention (Note [Sequential scoping of Let bindings]) is the opposite: the body's index 0 picks the *last* binding, like `let*`. Every other walker (`countFreeRefs`, `substitute`, `qualifyTopRefs`, `renameShadowedNamesInExpr`, and the RHS-side `adjacencyListForGrouping` right next to this code) implements the convention correctly; only the body scope of the DCE pass disagrees.\n\n### Repro\n\n```haskell\n-- let x = 1; x = 2 in x@0     -- by convention x@0 is the second binding\neliminateDeadCode $ UberModule [] [] $ pure . (Name \"main\",) $\n  lets (Standalone (noAnn, x, literalInt 1) :| [Standalone (noAnn, x, literalInt 2)])\n       (refLocal x 0)\n```\n\nActual: `let x = 1 in x@0`, i.e. reachability marked the first binding live and eliminated the second, so the expression now evaluates to 1 instead of 2. Expected: `let x = 2 in x@0`.\n\nSame-name siblings in one `Let` cannot currently be produced from PureScript source (CoreFn conversion uses source names, which are unique per let block, or fresh generated names), so this is a latent landmine rather than a live miscompile, but it directly contradicts the documented convention that issue #37 established as load-bearing.\n\nFix: the correctly threaded scope already exists one line below; the body should use `fst (foldl' adjacencyListForGrouping (scope, mempty) groupings)` instead of the separate `foldr`.\n\n## Tests\n\nRed-first regression tests for both belong in `test/Language/PureScript/Backend/IR/DCE/Spec.hs` next to the existing `dceExpression` helper; the repros above drop in as-is. Bug 1 additionally deserves an end-to-end case once a source-level reproduction is pinned down (the #56 golden shows the shape to imitate).\n\nFound during a backend audit on 2026-07-02; bug 1 was first noted during the #37 work and now has a confirmed reproduction.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-02T08:22:02Z","url":"https://github.com/purescript-lua/purescript-lua/issues/134"}

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:cd570144-1867-02eb-5cab-e8983b3db863
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9EA6:19E4BB:945625:BF0C54:6B00EF33
html-safe-nonce72846d4ba208d11dd988736da2b537148f9c6ecfa733a29f3df7b2ceaae61cf9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUE2OjE5RTRCQjo5NDU2MjU6QkYwQzU0OjZCMDBFRjMzIiwidmlzaXRvcl9pZCI6IjU1NjE2Nzk5MTA3NTU0MzAxOTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac419e1e246d5954a3186091b7a0eafc1fef905004a02ccf5da903f935c07f4c91
hovercard-subject-tagissue:4792612220
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/134/issue_layout
twitter:imagehttps://opengraph.githubassets.com/798e9cc8186d204a41fa82e0db20a90c09d61d04c0bf3d1407712217a523ba22/purescript-lua/purescript-lua/issues/134
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/798e9cc8186d204a41fa82e0db20a90c09d61d04c0bf3d1407712217a523ba22/purescript-lua/purescript-lua/issues/134
og:image:altTwo defects in the Let handling of Language.PureScript.Backend.IR.DCE, the same bug class as #37 and #56 (De Bruijn index bookkeeping under Note [Sequential scoping of Let bindings]). Bug 1: droppi...
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/134#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2F134
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%2F134
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/134
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/134
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/134
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/134
New issuehttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/134
#148https://github.com/purescript-lua/purescript-lua/pull/148
IR DCE mishandles Let bindings: no unshift after dropping a dead shadowing binder, body scope resolved in reversehttps://github.com/purescript-lua/purescript-lua/issues/134#top
#148https://github.com/purescript-lua/purescript-lua/pull/148
bugSomething isn't workinghttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/Unisay
Unisayhttps://github.com/Unisay
on Jul 2, 2026https://github.com/purescript-lua/purescript-lua/issues/134#issue-4792612220
#37https://github.com/purescript-lua/purescript-lua/issues/37
#56https://github.com/purescript-lua/purescript-lua/issues/56
#56https://github.com/purescript-lua/purescript-lua/issues/56
#56https://github.com/purescript-lua/purescript-lua/issues/56
#37https://github.com/purescript-lua/purescript-lua/issues/37
#56https://github.com/purescript-lua/purescript-lua/issues/56
#37https://github.com/purescript-lua/purescript-lua/issues/37
Unisayhttps://github.com/Unisay
bugSomething isn't workinghttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22bug%22
on Jul 2, 2026https://github.com/purescript-lua/purescript-lua/issues/134#event-27468418328
Unisayhttps://github.com/Unisay
completedhttps://github.com/purescript-lua/purescript-lua/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#148https://github.com/purescript-lua/purescript-lua/pull/148
on Jul 2, 2026https://github.com/purescript-lua/purescript-lua/issues/134#event-27502134233
Sign up for freehttps://github.com/signup?return_to=https://github.com/purescript-lua/purescript-lua/issues/134
Sign in to commenthttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/134
bugSomething isn't workinghttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22bug%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.