René's URL Explorer Experiment


Title: fix(optimizer): canonicalize Effect/ST heads through top-level aliases (#297) by Unisay · Pull Request #298 · purescript-lua/purescript-lua · GitHub

Open Graph Title: fix(optimizer): canonicalize Effect/ST heads through top-level aliases (#297) by Unisay · Pull Request #298 · purescript-lua/purescript-lua

X Title: fix(optimizer): canonicalize Effect/ST heads through top-level aliases (#297) by Unisay · Pull Request #298 · purescript-lua/purescript-lua

Description: Fixes #297. What was broken A module that instantiates discard with two different Bind dictionaries — Effect or ST plus any second monad; the repro uses ST + Effect, and Effect + Maybe produces the same shape — miscompiled: purs CSE floats the shared partial application in two stages, a shape neither canonicalization tier of #182 matched, so the Effect/ST chains stayed nested past magic-do, and once post-magic-do call-site inlining exposed the canonical pair, tier 2 manufactured a reference to a foreign accessor binding DCE had already removed. The generated Lua read a never-assigned module-table field and crashed: local M = {} ... return M.Effect_bindE(Effect_Console_log("st:"))(...)() -- nil call at runtime The fix Tier 2 resolves head positions through top-level aliases (canonicalizeEffectAppInModule). A reference denotes a row's name if it is that name, or if the top-level binding it names has a right-hand side that denotes it (visited-bounded). This is closed under any CSE split of the structurally bounded spines (bind/pure: two nodes, discard: three), not just the observed two-stage float. Because tier 2 runs in the pre-magic-do fixpoints, the chains flatten again — the repro's stCount now compiles to a flat thunk: local Golden_MixedDiscardFloat_Test_stCount = Control_Monad_ST_Internal_foreign.run(function( ) local r = Control_Monad_ST_Internal_foreign.new(1)() local _ = Control_Monad_ST_Internal_foreign.map_(function() return Data_Unit_unit end)(Control_Monad_ST_Internal_foreign.write(2)(r))() return Control_Monad_ST_Internal_foreign.read(r)() end) Tier 2 declines a rewrite whose produced reference would dangle: the rule now consults the module's top-level bindings (CanonEnv, built per optimizeModule run from the Standalone bindings plus the foreigns) and leaves the dictionary application in place when the canonical accessor is gone — sound, since the application it leaves is executable. The compiler refuses to emit code for a non-closed module (lintDanglingImports, new ResultDanglingImports failure): any future resurrect-after-DCE fails the build instead of shipping Lua that nil-calls at runtime. The check runs unconditionally in compileModules and on every golden module in the harness. It is deliberately not a pass-boundary invariant: unit fixtures legitimately reference external names, so closedness is only meaningful for linked modules. Tests Golden.MixedDiscardFloat.Test — the minimal reproduction (ST discard + Effect discard in one module); its hand-written eval oracle crashed at baseline and passes now, and the goldens pin the flattened output. Optimizer.Spec: the canonicalization block now runs against a CanonEnv (the rule's new contract), plus two new cases — resolution through the two-stage float, and declining when the canonical target has no binding. Linter.Spec: lintDanglingImports coverage (binding/foreign resolution, Prim exemption, per-site reporting). cabal test all: 1055 examples, 0 failures; no existing golden moved.

Open Graph Description: Fixes #297. What was broken A module that instantiates discard with two different Bind dictionaries — Effect or ST plus any second monad; the repro uses ST + Effect, and Effect + Maybe produces the...

X Description: Fixes #297. What was broken A module that instantiates discard with two different Bind dictionaries — Effect or ST plus any second monad; the repro uses ST + Effect, and Effect + Maybe produces the...

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

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:00be0509-eb81-7f26-2200-73a1a672fa87
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id97F2:24FC21:C7E126:10287E4:6B00EF56
html-safe-nonceb06394fc46b4f473059e89746b07ee831acea7e129c8b8f731cfae26a328236a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0YyOjI0RkMyMTpDN0UxMjY6MTAyODdFNDo2QjAwRUY1NiIsInZpc2l0b3JfaWQiOiI2MTA3Mzg3ODM5ODU5NDkwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac43819a299463a2f084656f4776325a1d40c768f0d94876930cc2a6e378243d13
hovercard-subject-tagpull_request:4125888295
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/298/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:altFixes #297. What was broken A module that instantiates discard with two different Bind dictionaries — Effect or ST plus any second monad; the repro uses ST + Effect, and Effect + Maybe produces the...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc
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
release9983dd5da06943f833c971dd5b6bc988e2858be5
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/pull/298/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F298%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%2F298%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/298/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/298/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/298/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-297/canonicalize-through-toplevel-aliaseshttps://github.com/purescript-lua/purescript-lua/tree/issue-297/canonicalize-through-toplevel-aliases
Conversation 0 https://github.com/purescript-lua/purescript-lua/pull/298
Commits 1 https://github.com/purescript-lua/purescript-lua/pull/298/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/298/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/298/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/298/files
fix(optimizer): canonicalize Effect/ST heads through top-level aliases (#297) https://github.com/purescript-lua/purescript-lua/pull/298/files#top
Show all changes 1 commit https://github.com/purescript-lua/purescript-lua/pull/298/files
74c4fd6 fix(optimizer): canonicalize Effect/ST heads through top-level aliases Unisay Jul 24, 2026 https://github.com/purescript-lua/purescript-lua/pull/298/commits/74c4fd68b159a64290bc366fc9611f6738145bf3
Clear filters https://github.com/purescript-lua/purescript-lua/pull/298/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/298/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/298/files
20260724_160000_unisay_canonicalize_through_toplevel_aliases.md https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-0e85abb3123aa08bc995e951a526c26d1881c784ea9b3c3fa71b65f22396ce66
Backend.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c7b61c0a5ec94432343188b6840d78294db6703c8ef65baf74d41ddd0ec5ba94
EffectNames.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c715d67319c08b5e99d2e9b82914f79241cdefc0b7e8c6db54d9463a401ebb1e
Linter.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Pass.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-abae6efc48eb2a5c5262970ee389785ead06f276979fda85fee4d192b5540b32
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-08e99a545b6968e28ad847ee02dcca639e254768b40d4e04ba31de515a1e685b
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-e10bc6586bdc2afb3eed89cc8935f6ff0059d32a82668123ce53808a6046c019
corefn.json https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-9480f544632891120ae95b1b3bfa18e52e1b03dab526f43f60383c9ec79973dc
.gitignore https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-d56161d0afd7a72a1ec4882aade7b1580fc75be2119c775002bba4fbaac8993d
golden.txt https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-69be8a01df4252ff590faec15badc67f6f9d0fce34acb8b48aa4559627020e58
golden.ir https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-fc124bcef858c2f36260227792ebffc9c811d637da4bd5d17cb0091a370acf80
golden.lua https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-46c90be6e57e4b5074ff97cc3e991ae9c2810fba31ae2d018df9bd4aa9c915ec
Test.purs https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-563d4a37a4a12851c5350e1f87bd4839ffa0135b9f0d36fd4772f45d82fea656
changelog.d/20260724_160000_unisay_canonicalize_through_toplevel_aliases.mdhttps://github.com/purescript-lua/purescript-lua/pull/298/files#diff-0e85abb3123aa08bc995e951a526c26d1881c784ea9b3c3fa71b65f22396ce66
View file https://github.com/purescript-lua/purescript-lua/blob/74c4fd68b159a64290bc366fc9611f6738145bf3/changelog.d/20260724_160000_unisay_canonicalize_through_toplevel_aliases.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/298/{{ revealButtonHref }}
lib/Language/PureScript/Backend.hshttps://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c7b61c0a5ec94432343188b6840d78294db6703c8ef65baf74d41ddd0ec5ba94
View file https://github.com/purescript-lua/purescript-lua/blob/74c4fd68b159a64290bc366fc9611f6738145bf3/lib/Language/PureScript/Backend.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/298/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c7b61c0a5ec94432343188b6840d78294db6703c8ef65baf74d41ddd0ec5ba94
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c7b61c0a5ec94432343188b6840d78294db6703c8ef65baf74d41ddd0ec5ba94
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c7b61c0a5ec94432343188b6840d78294db6703c8ef65baf74d41ddd0ec5ba94
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c7b61c0a5ec94432343188b6840d78294db6703c8ef65baf74d41ddd0ec5ba94
lib/Language/PureScript/Backend/IR/EffectNames.hshttps://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c715d67319c08b5e99d2e9b82914f79241cdefc0b7e8c6db54d9463a401ebb1e
View file https://github.com/purescript-lua/purescript-lua/blob/74c4fd68b159a64290bc366fc9611f6738145bf3/lib/Language/PureScript/Backend/IR/EffectNames.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/298/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c715d67319c08b5e99d2e9b82914f79241cdefc0b7e8c6db54d9463a401ebb1e
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c715d67319c08b5e99d2e9b82914f79241cdefc0b7e8c6db54d9463a401ebb1e
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c715d67319c08b5e99d2e9b82914f79241cdefc0b7e8c6db54d9463a401ebb1e
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c715d67319c08b5e99d2e9b82914f79241cdefc0b7e8c6db54d9463a401ebb1e
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-c715d67319c08b5e99d2e9b82914f79241cdefc0b7e8c6db54d9463a401ebb1e
lib/Language/PureScript/Backend/IR/Linter.hshttps://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
View file https://github.com/purescript-lua/purescript-lua/blob/74c4fd68b159a64290bc366fc9611f6738145bf3/lib/Language/PureScript/Backend/IR/Linter.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/298/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
https://github.com/purescript-lua/purescript-lua/pull/298/files#diff-264d10c5a4ba000a7bb29051f94654ee58f4385168f828107ec14859df053b39
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/298/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.