René's URL Explorer Experiment


Title: renameShadowedNames miscompiles local recursive groups: member order reversed, member RHSs renamed in the wrong scope · Issue #133 · purescript-lua/purescript-lua · GitHub

Open Graph Title: renameShadowedNames miscompiles local recursive groups: member order reversed, member RHSs renamed in the wrong scope · Issue #133 · purescript-lua/purescript-lua

X Title: renameShadowedNames miscompiles local recursive groups: member order reversed, member RHSs renamed in the wrong scope · Issue #133 · purescript-lua/purescript-lua

Description: Two related defects in renameShadowedNamesInExpr (lib/Language/PureScript/Backend/IR/Optimizer.hs), both in the RecursiveGroup branch of the Let case. Both produce wrong runtime behavior without any compile-time error. Bug 1: member orde...

Open Graph Description: Two related defects in renameShadowedNamesInExpr (lib/Language/PureScript/Backend/IR/Optimizer.hs), both in the RecursiveGroup branch of the Let case. Both produce wrong runtime behavior without an...

X Description: Two related defects in renameShadowedNamesInExpr (lib/Language/PureScript/Backend/IR/Optimizer.hs), both in the RecursiveGroup branch of the Let case. Both produce wrong runtime behavior without an...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"renameShadowedNames miscompiles local recursive groups: member order reversed, member RHSs renamed in the wrong scope","articleBody":"Two related defects in `renameShadowedNamesInExpr` (`lib/Language/PureScript/Backend/IR/Optimizer.hs`), both in the `RecursiveGroup` branch of the `Let` case. Both produce wrong runtime behavior without any compile-time error.\n\n## Bug 1: member order of every local `RecursiveGroup` is reversed\n\nThe fold over group members conses each processed member onto an accumulator and the result is never reversed back:\n\n```haskell\nRecursiveGroup (toList → recGroup) →\n  (: bs) . RecursiveGroup . NE.fromList \u003c$> foldl' g (sc, []) recGroup\n where\n  g (sc', recBinds) (ann', name, expr) =\n    ... (sc'', (ann', name', expr') : recBinds)   -- cons, no reverse afterwards\n```\n\nThe sibling code path for `Let` groupings does compensate (`NE.fromList (reverse binds')`); the member list inside a group does not. So every `RecursiveGroup` inside an expression comes out of `renameShadowedNames` with its members in reverse order, unconditionally.\n\nMember order is not cosmetic: it is the initialization order computed by the laziness transform (`Language.PureScript.CoreFn.Laziness.applyLazinessTransform` reorders the group so that statically orderable bindings initialize before their dependents), and the Lua codegen emits the group's assignments in member order. Reversing it undoes the laziness analysis.\n\n### Repro (full pipeline)\n\n```haskell\n-- A laziness-ordered eager group: x must initialize before y,\n-- because y reads x immediately (delay 0), while x only refers to y under a lambda.\nlet x = Name \"x\"; y = Name \"y\"\nlet recGroup = RecursiveGroup\n      (  (noAnn, x, abstraction paramUnused (refLocal y 0))\n      :| [(noAnn, y, literalObject [(PropName \"foo\", refLocal x 0)])] )\nlet uber = UberModule [] [] [(Name \"main\", lets (recGroup :| []) (refLocal y 0))]\nuberModuleExports (optimizedUberModule uber)\n```\n\nThe group comes out as `[y, x]`, so the generated Lua is:\n\n```lua\nlocal x\nlocal y\ny = { foo = x }              -- x is still nil here\nx = function() return y end\n```\n\n`y.foo` is `nil` at runtime. The corresponding PureScript shape is ordinary code, e.g. in a `let`/`where` block:\n\n```purescript\nx = \\_ -> y\ny = { foo: x }\n```\n\nThe reversal is already visible in a committed golden: `test/ps/output/Golden.RecursiveBindings.Test/golden.ir` has the `a`/`b` group in the reverse of the order the laziness transform emits. It happens to be harmless there because both members are lambdas, so their initialization order doesn't matter.\n\nTop-level recursive groups are not affected (`renameShadowedNames` maps over top-level binding expressions individually and never touches grouping order); only `Let ... RecursiveGroup` inside expressions.\n\n## Bug 2: member RHSs are renamed in a scope that lacks the group's own renames\n\n`g` renames each member's RHS with `sc'`, the scope accumulated over the *previous* members only. But recursive-group scoping (Note [Sequential scoping of Let bindings]) makes every member visible in every member's RHS, itself included. When a group member shadows an outer binder, self-references and forward references inside the group keep the old name while the binder gets renamed, so they quietly rebind to the outer binder.\n\n### Repro\n\n```haskell\n-- \\x -> let rec x = f x@0 in x@0     (the member's RHS refers to itself)\nrenameShadowedNamesInExpr mempty $\n  abstraction (paramNamed x) $\n    lets (RecursiveGroup ((noAnn, x, application (exception \"f\") (refLocal x 0)) :| []) :| [])\n         (refLocal x 0)\n```\n\nActual result: the binder becomes `x1` and the body reference follows, but the RHS still says `Ref (Local x) 0`, which now resolves to the outer lambda parameter. The recursion is severed:\n\n```haskell\nAbs (ParamNamed x) (Let (RecursiveGroup ((x1, App (Exception \"f\") (Ref x 0)) :| [])) (Ref x1 0))\n```\n\nForward references hit the same problem: with members `[(y, refLocal x 0), (x, literalInt 1)]` under an outer binder `x`, the member `x` is renamed to `x1` but `y`'s reference stays `x` and rebinds to the outer binder. A shadowing name in a local recursive group is common (`go`, `f` in nested `where` blocks), so this is reachable from ordinary source code.\n\n## Fix sketch\n\n- Bug 1: reverse the member list after the fold, symmetrically with the groupings fix-up.\n- Bug 2: process each group in two passes: first run `withScopedName` for all members to build the group's complete scope, then rename every member's RHS in that scope.\n\nBoth fixes should come with red-first regression tests in `test/Language/PureScript/Backend/IR/Optimizer/Spec.hs` (the repros above are ready to be turned into cases under the \"renames shadowed names\" describe block), plus an eval golden for the order-sensitive group so the runtime consequence stays pinned.\n\nFound during a backend audit on 2026-07-02; bug 2 confirms a hypothesis first noted during the issue #37 work.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-02T08:17:45Z","url":"https://github.com/purescript-lua/purescript-lua/issues/133"}

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:0df7959a-13c3-79d9-3724-b5f0fefc63d8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9EF2:2E7EBB:9EBCBA:C9CCDD:6B00EF35
html-safe-noncebb523866a5e81013f75b1fd55007e22bb5c4588e6ac8b206919798c8435dbc25
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUYyOjJFN0VCQjo5RUJDQkE6QzlDQ0REOjZCMDBFRjM1IiwidmlzaXRvcl9pZCI6IjQ4NjU3NzU2MTk3MzQwNDAzNzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaceacc6463398d1c58eb437b8332dbd947444428b4a149cead3d217fe8da0328b9
hovercard-subject-tagissue:4792582699
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/133/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b1d29479aeb1c4d6cbc7e412b8170a6f6a0c71537ce72ff8ee0f4b8bc1255d05/purescript-lua/purescript-lua/issues/133
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b1d29479aeb1c4d6cbc7e412b8170a6f6a0c71537ce72ff8ee0f4b8bc1255d05/purescript-lua/purescript-lua/issues/133
og:image:altTwo related defects in renameShadowedNamesInExpr (lib/Language/PureScript/Backend/IR/Optimizer.hs), both in the RecursiveGroup branch of the Let case. Both produce wrong runtime behavior without an...
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/133#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2F133
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%2F133
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/133
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/133
Reloadhttps://github.com/purescript-lua/purescript-lua/issues/133
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/133
New issuehttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/133
#147https://github.com/purescript-lua/purescript-lua/pull/147
renameShadowedNames miscompiles local recursive groups: member order reversed, member RHSs renamed in the wrong scopehttps://github.com/purescript-lua/purescript-lua/issues/133#top
#147https://github.com/purescript-lua/purescript-lua/pull/147
https://github.com/Unisay
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/133#issue-4792582699
#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/133#event-27468251797
Unisayhttps://github.com/Unisay
on Jul 2, 2026https://github.com/purescript-lua/purescript-lua/issues/133#event-27497606622
Unisayhttps://github.com/Unisay
completedhttps://github.com/purescript-lua/purescript-lua/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#147https://github.com/purescript-lua/purescript-lua/pull/147
on Jul 2, 2026https://github.com/purescript-lua/purescript-lua/issues/133#event-27498197284
Sign up for freehttps://github.com/signup?return_to=https://github.com/purescript-lua/purescript-lua/issues/133
Sign in to commenthttps://github.com/login?return_to=https://github.com/purescript-lua/purescript-lua/issues/133
Unisayhttps://github.com/Unisay
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.