Title: Long do blocks generate Lua that exceeds the parser nesting limit · Issue #46 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Long do blocks generate Lua that exceeds the parser nesting limit · Issue #46 · purescript-lua/purescript-lua
X Title: Long do blocks generate Lua that exceeds the parser nesting limit · Issue #46 · purescript-lua/purescript-lua
Description: Reported as a side note in #32: a long enough do block fails at runtime. The failure is not an actual stack overflow during evaluation, it happens before any code runs. Lua refuses to parse the file: lua: golden.lua:144: chunk has too ma...
Open Graph Description: Reported as a side note in #32: a long enough do block fails at runtime. The failure is not an actual stack overflow during evaluation, it happens before any code runs. Lua refuses to parse the fil...
X Description: Reported as a side note in #32: a long enough do block fails at runtime. The failure is not an actual stack overflow during evaluation, it happens before any code runs. Lua refuses to parse the fil...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/46
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Long do blocks generate Lua that exceeds the parser nesting limit","articleBody":"Reported as a side note in #32: a long enough do block fails at runtime. The failure is not an actual stack overflow during evaluation, it happens before any code runs. Lua refuses to parse the file: `lua: golden.lua:144: chunk has too many syntax levels`.\n\nThe cause is the shape of the generated code. Each statement of a do block compiles to a bind continuation that is lexically nested inside the previous one:\n\n```lua\nreturn M.discard(M.Effect_Console_foreign.log(\"61\"))(function()\n return M.discard(M.Effect_Console_foreign.log(\"62\"))(function()\n return M.discard(M.Effect_Console_foreign.log(\"63\"))(function()\n ...\n```\n\nLua's parser has a hard recursion limit (`LUAI_MAXCCALLS`, 200 by default), so a do block with roughly 200 statements produces a chunk that no stock Lua interpreter will load. The repro is mechanical:\n\n```purs\nmain :: Effect Unit\nmain = do\n log \"1\"\n log \"2\"\n -- ... 300 lines total\n log \"300\"\n```\n\nTo make this an eval golden, generate the module and the expected output:\n\n```bash\ncd test/ps/golden/Golden && mkdir -p LongDoBlock\n{ echo 'module Golden.LongDoBlock.Test where'; echo\n echo 'import Prelude'\n echo 'import Effect (Effect)'\n echo 'import Effect.Console (log)'; echo\n echo 'main :: Effect Unit'\n echo 'main = do'\n for i in $(seq 1 300); do echo \" log \\\"$i\\\"\"; done\n} > LongDoBlock/Test.purs\nmkdir -p ../../output/Golden.LongDoBlock.Test/eval\nseq 1 300 > ../../output/Golden.LongDoBlock.Test/eval/golden.txt\n```\n\nThis is a different root than the instance dictionary overflow fixed for #32, which is why it gets its own issue. Fixing it means making the generated code lexically flatter, and none of the options are local tweaks:\n\n- A magic-do style rewrite for Effect, like the upstream JS backend: turn chains of `bind`/`discard` over the Effect monad into sequential statements inside one function body. Most effective, but requires recognizing the Effect dictionaries.\n- Hoisting continuation lambdas into named locals. This only helps for `discard` chains where continuations capture nothing; a `x \u003c- m` bind captures `x`, so the continuation cannot leave the enclosing scope, and the nesting stays.\n- Documenting the limit and recommending users split long do blocks. Cheap, but it leaves generated code that a stock interpreter cannot load, and the prelude test suites hit it in practice.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-06-12T14:23:23Z","url":"https://github.com/purescript-lua/purescript-lua/issues/46"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cfef120c-8b30-bc4a-52ab-675e376d1e88 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA2C:27D3AD:5832C9:71C7DE:6B00DB5D |
| html-safe-nonce | 8dae3fa397f9b70f13ec543d8629833137e585eb5a0ce60c7ea4556103d583c5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTJDOjI3RDNBRDo1ODMyQzk6NzFDN0RFOjZCMDBEQjVEIiwidmlzaXRvcl9pZCI6IjU2MDAzMzM0Njk2NjMxNTcwODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ed96b16cb641ee5dc4b5db5f74e59dbc5ae4b0d26afb71f077e2a33c3f39f26c |
| hovercard-subject-tag | issue:4650010004 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/46/issue_layout |
| twitter:image | https://opengraph.githubassets.com/244f132802721bfa099adbb16476ae2684db3c916784dfb275c7dfb1fff23202/purescript-lua/purescript-lua/issues/46 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/244f132802721bfa099adbb16476ae2684db3c916784dfb275c7dfb1fff23202/purescript-lua/purescript-lua/issues/46 |
| og:image:alt | Reported as a side note in #32: a long enough do block fails at runtime. The failure is not an actual stack overflow during evaluation, it happens before any code runs. Lua refuses to parse the fil... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Unisay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 587200487 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 587200487 |
| octolytics-dimension-repository_network_root_nwo | purescript-lua/purescript-lua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width