René's URL Explorer Experiment


Title: fix: flatten Effect/ST do blocks (magic-do) to avoid Lua's nesting limit (#46) by Unisay · Pull Request #105 · purescript-lua/purescript-lua · GitHub

Open Graph Title: fix: flatten Effect/ST do blocks (magic-do) to avoid Lua's nesting limit (#46) by Unisay · Pull Request #105 · purescript-lua/purescript-lua

X Title: fix: flatten Effect/ST do blocks (magic-do) to avoid Lua's nesting limit (#46) by Unisay · Pull Request #105 · purescript-lua/purescript-lua

Description: Fixes #46. Problem A long straight-line do block desugars to a chain of bind/discard whose continuations nest lexically. Past ~200 levels Lua's parser rejects the chunk with chunk has too many syntax levels (LUAI_MAXCCALLS), so the file fails to load — before any code runs. The prelude test suites hit this in practice. Approach A new IR pass Language.PureScript.Backend.IR.MagicDo recognises bind/discard/pure specialised to the Effect or ST monad — whose runtime value is a nullary thunk — and rewrites the nested chain into a flat statement sequence: function() local x = m1(); local _ = m2(); ...; return last() end This mirrors the magic-do pass of the upstream JS backend and purs-backend-es, but is realised as a rewrite into existing Let/Abs constructs rather than a new IR node (which would ripple through every RawExp traversal, including the De Bruijn machinery behind #37/#56). Key points: Recognition normalises the application head — resolving module-local aliases, projecting fields out of literal dictionaries, and beta-reducing — until the Effect/ST bind instance is exposed. The optimizer inlines discard to discardUnit.discard = bind, so the chain head is rarely a bare Control.Bind.bind; normalisation sees through that. Chunking. A single flat thunk would overflow Lua 5.1's other limit, LUAI_MAXVARS (200 locals/function). The statements are split into nested thunks of ≤150 locals, so both the nesting limit and the local-variable limit stay satisfied. Placement. Runs as the final step of optimizedUberModule: after renameShadowedNames (locals are uniquely named, so moving binders into a Let needs no De Bruijn shifting) and after dead-code elimination (so the local _ = statements introduced for discard are not dropped as dead). Folding it into the single pipeline definition means both the compiler and the golden-test harness pick it up — no divergence. Effect/ST only. Other monads keep their bind calls (their bind is not "run a thunk"). A long straight-line do in Maybe/Either/State/… can still hit the parser limit; the generic, monad-agnostic fallback is tracked in #104. Testing New Golden.LongDoBlock regression — a 300-statement Effect block that previously failed to load now evaluates and prints 1..300. All existing eval goldens are unchanged (eval/golden.txt preserved, only golden.ir/golden.lua regenerated), confirming semantics are preserved — including Maybe (MaybeChain) and tailRecM (TailRecM2Shadow), which are deliberately not flattened. Full suite green: 237 examples, 0 failures (unit + property + golden + eval + luacheck). Docs Adds docs/QUIRKS.md (user-facing Lua-target guide) and notes the residual non-Effect/ST limit there.

Open Graph Description: Fixes #46. Problem A long straight-line do block desugars to a chain of bind/discard whose continuations nest lexically. Past ~200 levels Lua's parser rejects the chunk with chunk has too many ...

X Description: Fixes #46. Problem A long straight-line do block desugars to a chain of bind/discard whose continuations nest lexically. Past ~200 levels Lua's parser rejects the chunk with chunk has too m...

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

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:12893cd2-4840-0562-5dc8-edf73ddbea97
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB82E:34CAB:6F26EB:8F138A:6B00E4A3
html-safe-nonce87baa1ac5f0236a28d4bafde54520af9015b1ffdd65bf8703cd529976d5126f5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODJFOjM0Q0FCOjZGMjZFQjo4RjEzOEE6NkIwMEU0QTMiLCJ2aXNpdG9yX2lkIjoiNTUzNjg1MTcyNzAxOTQ2NzkzOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac4ed965c6c504f2c59d8a4d9b8c9db2b04ea3c2effdd5f485f04229252e8a2fc0
hovercard-subject-tagpull_request:3874880300
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/105/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 #46. Problem A long straight-line do block desugars to a chain of bind/discard whose continuations nest lexically. Past ~200 levels Lua's parser rejects the chunk with chunk has too many ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14
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
release624179fb8b88d26ba5bba08894eb60a1c5a1d93d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/pull/105/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F105%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%2F105%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/105/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/105/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/105/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-46/magic-do-effect-sthttps://github.com/purescript-lua/purescript-lua/tree/issue-46/magic-do-effect-st
Conversation 1 https://github.com/purescript-lua/purescript-lua/pull/105
Commits 4 https://github.com/purescript-lua/purescript-lua/pull/105/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/105/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/105/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/105/files
fix: flatten Effect/ST do blocks (magic-do) to avoid Lua's nesting limit (#46) https://github.com/purescript-lua/purescript-lua/pull/105/files#top
Show all changes 4 commits https://github.com/purescript-lua/purescript-lua/pull/105/files
132bc0b fix: flatten Effect/ST do blocks (magic-do) to avoid Lua's nesting li… Unisay Jun 16, 2026 https://github.com/purescript-lua/purescript-lua/pull/105/commits/132bc0bc0da5ad2bda3ad1985113b75fc9ea2e51
4579422 docs: add user-facing Lua-target quirks & gotchas guide Unisay Jun 16, 2026 https://github.com/purescript-lua/purescript-lua/pull/105/commits/4579422208629d46dd98f048c1ccc29d1a913de0
b69930b docs: note Lua's per-function locals/upvalues caps in QUIRKS Unisay Jun 21, 2026 https://github.com/purescript-lua/purescript-lua/pull/105/commits/b69930be8a7cb4912ac76fa777c25b96058e99f9
52deb38 refactor: use LambdaCase for CoreFn.Expr annotation helpers Unisay Jun 21, 2026 https://github.com/purescript-lua/purescript-lua/pull/105/commits/52deb381d1a6527872fce7b7a2d714dbd836b3dc
Clear filters https://github.com/purescript-lua/purescript-lua/pull/105/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/105/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/105/files
CLAUDE.md https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-6ebdb617a8104a7756d0cf36578ab01103dc9f07e4dc6feb751296b9c402faf7
QUIRKS.md https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-e829c580d06215599e6ce7868033ec1082f0c45c0e4d8aca64dc1c3a3da0d6c3
MagicDo.hs https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-328cbd548cb26793eb748fd65aeac8ad258513e2b55db04b4d1aefc7477ea06f
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Expr.hs https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-d3e384e8f34f93ffe2ad7543d1e604b58dffd8774ce1868da8e4b5be70e46911
pslua.cabal https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-cf0302393cf6443df4429c19c0fc326753a83405d0366075a98ac2753e5e1ab2
Test.purs https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-9222118c16db4639a193b0c09bef6c74619d25224eefc36e63786deecaaf8d6d
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-69a9ccb2bea2e47b079058b88387a58dda0b8ad3a23e3100948844c4bd22f8f2
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-d14061e081c835eadc7c359ed265bb765b321b458d478c3ba1cd2706ffc1b91f
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-a50730a65be2dd43fb54fcc7256daba19c0f0d185fa91ae70fd74eb6dc88babb
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-f09de2d9591e7ed04c015cf5105c29cef2be557187d5d7b8ca203b70d4f11bfc
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-8529207f5726b1c4ce856b7d81dadbbbdc4b244d37e96f40d897c3acc69290b8
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-0c90c2d7623d39f887ed98803e0198ce7532cb955c04690d5c518a02bb16d0e1
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-51768e0a180e8ba17b000ead8fa35bcd5743917951b324a2b821a2ffbfd4ee35
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-33101f4068d284cd068f09a25c752d3e6d8287f96ae0b55f30ffa86fa165fa8e
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-f681ba814c3f5a9d02a0f986890219bb41cd2f8fb10633efcc78b3ef649ad60f
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-9e3f316b6cc931f334b87e8edcd3d4b82e1342549d712184ba6514363e081a25
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-d3c70e506ea822ff99389c6a4e383878df25de8723c47a01e91e7dc5792501dc
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-596c7cb04898e2e110885627fbe42de08e09aa38b253a73bf3a99c9cedfa6bec
corefn.json https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-5087cd546014121bd11d871d08228597755b395fd3a0b971139d998dd2a83b4e
.gitignore https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-4b6b1b6530749f40a096f64e00ec0c8e6dbcf860b32d8fa0130deef80ce62a23
golden.txt https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-5303c8b8c0efe954370524e3d6a1c341f9a092a6aaecd19229845e13dfbd2738
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-8bb650ea21e73b8a93416c7bbefd047d58486d7ee1b19b713199ef7f6f00c2c1
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-1080c4da770e84d415bca9035ba0450a5984530aeea1c4a005f363a151df5e11
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-3006141b034eb94f2e88b5db2e09fd3a0fb2c4565719131fe516243bc24b92e8
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-8e7867f5f173ace42b15b122ecdf3ff80cec593e6931cb44edafb30838f1044a
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-ea89ea708c8e25a05b63283fb8d74820b2ce2219bd5484a5f8b7b9b4c3d2a659
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-4f0755e4e4caea3e293c097cbe735d371c163fa463fffab6dcb32535099b9029
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-df535e1f7273af0cc86db20df55495de4552000d7bf2f3abb21f421d07947914
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-8f846c962c84e2efb0046e7848c15b3bac3e044be37a2d2ee0620f823f2e9b0f
golden.ir https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-943a6e999776e2a06a4d4209af7f89e9a8d977d6000c31c70ed84e781da2e2ff
golden.lua https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-56618fb442d7b6de74d0159576d795d225986345ac7840c4a3a8a3831cb98ad3
CLAUDE.mdhttps://github.com/purescript-lua/purescript-lua/pull/105/files#diff-6ebdb617a8104a7756d0cf36578ab01103dc9f07e4dc6feb751296b9c402faf7
View file https://github.com/purescript-lua/purescript-lua/blob/52deb381d1a6527872fce7b7a2d714dbd836b3dc/CLAUDE.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/105/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-6ebdb617a8104a7756d0cf36578ab01103dc9f07e4dc6feb751296b9c402faf7
https://github.com/purescript-lua/purescript-lua/pull/105/files#diff-6ebdb617a8104a7756d0cf36578ab01103dc9f07e4dc6feb751296b9c402faf7
docs/QUIRKS.mdhttps://github.com/purescript-lua/purescript-lua/pull/105/files#diff-e829c580d06215599e6ce7868033ec1082f0c45c0e4d8aca64dc1c3a3da0d6c3
View file https://github.com/purescript-lua/purescript-lua/blob/52deb381d1a6527872fce7b7a2d714dbd836b3dc/docs/QUIRKS.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/105/{{ revealButtonHref }}
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/105/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/105/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.