René's URL Explorer Experiment


Title: freshenBinders renames a free reference sharing its Standalone Let binder's name · Issue #345 · purescript-lua/purescript-lua · GitHub

Open Graph Title: freshenBinders renames a free reference sharing its Standalone Let binder's name · Issue #345 · purescript-lua/purescript-lua

X Title: freshenBinders renames a free reference sharing its Standalone Let binder's name · Issue #345 · purescript-lua/purescript-lua

Description: Problem freshenBinders — the traversal that alpha-renames an expression's binders before a copy of it is pasted somewhere else — renames the binders of a Let by collecting every binder name of the Let into a rename map up front, then ren...

Open Graph Description: Problem freshenBinders — the traversal that alpha-renames an expression's binders before a copy of it is pasted somewhere else — renames the binders of a Let by collecting every binder name of the ...

X Description: Problem freshenBinders — the traversal that alpha-renames an expression's binders before a copy of it is pasted somewhere else — renames the binders of a Let by collecting every binder name of ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"freshenBinders renames a free reference sharing its Standalone Let binder's name","articleBody":"## Problem\n\n`freshenBinders` — the traversal that alpha-renames an expression's binders before a copy of it is pasted somewhere else — renames the binders of a `Let` by collecting every binder name of the `Let` into a rename map up front, then renaming all the right-hand sides and the body under that one map. It says so itself:\n\n```haskell\n    Let ann binds body → do\n      -- Under unique binders no Let name can be referenced before it is\n      -- bound, so all the groupings can enter the rename map up front.\n      renames' ← foldlM (…) renames (filter (/= discardName) (bindingNames =\u003c\u003c toList binds))\n      let renameBound (bindAnn, name, expr) =\n            (bindAnn, Map.findWithDefault name name renames',) \u003c$> go renames' expr\n      Let ann \u003c$> traverse (traverse renameBound) binds \u003c*> go renames' body\n```\n\nThat is sound only under the global uniqueness condition (GUC), which the comment names. The IR's scoping rule is sequential — `Note [Sequential scoping of Let bindings]` — and its first clause says a `Standalone` binding is non-recursive: its own name is *not* in scope in its right-hand side, so a reference to that name from its own RHS resolves to an outer binder. Under GUC no free variable can share a binder's name, so hoisting the map cannot capture anything. On input that is not GUC, it can: the binder's rename entry is already in the map when its own RHS is walked, so a *free* occurrence that happens to share the binder's name is renamed along with the binder, silently repointing it.\n\nThe minimal shape is `let x = x in l`, where the `x` on the right is free. Freshening it should rename only the binder, but renames both:\n\n```\n      Let\n-       Standalone ( Nothing , Name \"x$0\" , Ref Nothing (Local (Name \"x$0\")) )   -- actual\n+       Standalone ( Nothing , Name \"x\"   , Ref Nothing (Local (Name \"x\"))   )   -- expected\n        Ref Nothing (Local (Name \"l\"))\n```\n\n`freshenBinders` is the odd one out here. `alphaEq` implements the sequential rule explicitly — it compares a `Standalone` right-hand side *before* binding the name, with the comment `-- The RHS of a Standalone binding does not see its own binder:` — and `countFreeRefs` does the same. Even `freshenBinders`' own `LetValues` case threads the map correctly, for the same reason: `-- The RHS is renamed under the incoming map — the binders scope over the body only`. Only the `Let` case hoists.\n\n## How it shows up\n\nAs an intermittent failure of the property `IR Optimizer / inlines expressions referenced once`, at roughly 1 run in 100. That test feeds `optimizedExpression` generated expressions that are deliberately *not* uniquified, inlines a once-used binding, and compares the pasted copy to the original up to alpha-equivalence. It fails exactly when the generator happens to produce the degenerate self-shadowing shape above, which is why the rate is low.\n\nThe failure reproduces on unmodified `main` (245 examples, same test) at the same rate, so it is not new. It also needs the whole `IR Optimizer` group to run — 200 runs of the test in isolation never reproduced it, because the group's global seed drives which hedgehog seeds this test receives.\n\n## Impact\n\nNone on emitted code. `uniquifyNames` is the pipeline's entry pass and every pass declares `passRequires = guc`, so real compilation never presents non-GUC input to `freshenBinders`. The cost is a test suite that reddens ~1% of the time, which trains everyone to re-run rather than read.\n\n## Approach\n\nThread the rename map through the groupings instead of hoisting it, matching the scoping rule the rest of the codebase implements: a `Standalone` right-hand side is renamed under the incoming map and only then does its binder enter; a `RecursiveGroup`'s members all enter before any of their right-hand sides are walked.\n\n```haskell\n    Let ann binds body → do\n      (renames', binds') ← mapAccumM freshenGrouping renames binds\n      Let ann binds' \u003c$> go renames' body\n```\n\n```haskell\n  freshenGrouping renames = \\case\n    Standalone (bindAnn, name, expr) → do\n      expr' ← go renames expr                    -- before the binder is in scope\n      (renames', name') ← bindFresh renames name\n      pure (renames', Standalone (bindAnn, name', expr'))\n    RecursiveGroup members → do\n      (renames', names) ←\n        mapAccumM (\\rs (_, n, _) → bindFresh rs n) renames members\n      members' ← forM (NE.zip members names) \\((bindAnn, _, expr), name') →\n        (bindAnn, name',) \u003c$> go renames' expr\n      pure (renames', RecursiveGroup members')\n```\n\n`bindFresh` keeps the existing `discardName` exemption, which must survive: a magic-do-lowered thunk binds several `Let` statements to `_`, and a single name-keyed entry would send them all to the same fresh name. `mapAccumM` is already the idiom the `AbsN` case uses for parameters.\n\n## Verification\n\nThe change is a no-op on GUC input, where the two orders provably agree, so the whole golden corpus should stay byte-identical and the suite green — that is the check that no caller (`substituteCopyM` / `substituteMoveM`, the call-pattern specializer, and the five call-site inliners in the optimizer) relied on the hoisted behaviour.\n\nThe existing `prop \"is an alpha-renaming of GUC-shaped input\"` deliberately restricts itself to uniquified input, so it cannot catch this. A non-GUC sibling is the red-first test: assert that freshening `let x = x in l` leaves the free `x` alone.\n\n## Prerequisites / Relations\n\nIndependent — nothing needs to land first. Surfaced while implementing #251 (PR #344), but not caused by it: the flake reproduces identically on the `main` commit before that change. The fix touches `freshenBinders`, which every call-site inliner and the call-pattern specializer go through, so it wants its own diff rather than riding along with feature work.\n\n## Acceptance criteria\n\n- Freshening a `Standalone` binding renames the binder without touching a free reference of the same name in its own right-hand side.\n- The `discard` binder exemption still holds.\n- `IR Optimizer / inlines expressions referenced once` survives a few hundred consecutive runs of the whole spec group.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-29T08:25:24Z","url":"https://github.com/purescript-lua/purescript-lua/issues/345"}

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:1be31a7b-cdc6-a3a5-3ce0-c06628dabd2f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDFD6:BBAAA:7E960B:A91968:6B00DB6A
html-safe-noncefebc41d1917f6786a7b109a961e9e590ef9e5025ce643571a74c25b255cd1f7c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkQ2OkJCQUFBOjdFOTYwQjpBOTE5Njg6NkIwMERCNkEiLCJ2aXNpdG9yX2lkIjoiNDc2NzMxNjQyNzkzNTg5ODQ3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac48b79a79cf231ac819fda471262cde21e9ca26e7706091a45b6c1e903b54a349
hovercard-subject-tagissue:5007099645
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/345/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ac5a492d82e16601dadfd728cbfbcac4000882061312d08d6e133a17d2de4959/purescript-lua/purescript-lua/issues/345
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ac5a492d82e16601dadfd728cbfbcac4000882061312d08d6e133a17d2de4959/purescript-lua/purescript-lua/issues/345
og:image:altProblem freshenBinders — the traversal that alpha-renames an expression's binders before a copy of it is pasted somewhere else — renames the binders of a Let by collecting every binder name of the ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameUnisay
hostnamegithub.com
expected-hostnamegithub.com
None043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf
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
release5425dc24e8bd8d6fca9641a12afc984825a43875
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/issues/345#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2F345
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%2F345
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/345
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/345
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/345
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/345
New issuehttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/345
#347https://github.com/purescript-lua/purescript-lua/pull/347
freshenBinders renames a free reference sharing its Standalone Let binder's namehttps://github.com/purescript-lua/purescript-lua/issues/345#top
#347https://github.com/purescript-lua/purescript-lua/pull/347
area: irIR / optimizer / DCE / inlinerhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20ir%22
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 29, 2026https://github.com/purescript-lua/purescript-lua/issues/345#issue-5007099645
#251https://github.com/purescript-lua/purescript-lua/issues/251
#344https://github.com/purescript-lua/purescript-lua/pull/344
Unisayhttps://github.com/Unisay
bugSomething isn't workinghttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22bug%22
area: irIR / optimizer / DCE / inlinerhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20ir%22
on Jul 29, 2026https://github.com/purescript-lua/purescript-lua/issues/345#event-28646914068
Unisayhttps://github.com/Unisay
completedhttps://github.com/purescript-lua/purescript-lua/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#347https://github.com/purescript-lua/purescript-lua/pull/347
on Jul 29, 2026https://github.com/purescript-lua/purescript-lua/issues/345#event-28649613819
Sign up for freehttps://github.com/signup?return_to=https://github.com/purescript-lua/purescript-lua/issues/345
Sign in to commenthttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/345
area: irIR / optimizer / DCE / inlinerhttps://github.com/purescript-lua/purescript-lua/issues?q=state%3Aopen%20label%3A%22area%3A%20ir%22
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.