Title: IR.Abs lowering wraps a chunk body in a scope IIFE that a separate rule then strips · Issue #158 · purescript-lua/purescript-lua · GitHub
Open Graph Title: IR.Abs lowering wraps a chunk body in a scope IIFE that a separate rule then strips · Issue #158 · purescript-lua/purescript-lua
X Title: IR.Abs lowering wraps a chunk body in a scope IIFE that a separate rule then strips · Issue #158 · purescript-lua/purescript-lua
Description: IR.Abs lowering (Lua.hs, the IR.Abs case) computes the body via goExp, which is asExpression <<$>> go. When the body lowers to a chunk rather than a bare expression, for example a Let or an IfThenElse, asExpression wraps it through Lua.c...
Open Graph Description: IR.Abs lowering (Lua.hs, the IR.Abs case) computes the body via goExp, which is asExpression <<$>> go. When the body lowers to a chunk rather than a bare expression, for example a Let or an IfThenE...
X Description: IR.Abs lowering (Lua.hs, the IR.Abs case) computes the body via goExp, which is asExpression <<$>> go. When the body lowers to a chunk rather than a bare expression, for example a Let o...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/158
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"IR.Abs lowering wraps a chunk body in a scope IIFE that a separate rule then strips","articleBody":"`IR.Abs` lowering (`Lua.hs`, the `IR.Abs` case) computes the body via `goExp`, which is `asExpression \u003c\u003c$>> go`. When the body lowers to a chunk rather than a bare expression, for example a `Let` or an `IfThenElse`, `asExpression` wraps it through `Lua.chunkToExpression` into a niladic IIFE: `(function() chunk end)()`. `Abs` then wraps that single expression in `Lua.return`, producing:\n\n```lua\nfunction(params)\n return (function()\n chunk\n end)()\nend\n```\n\n`removeScopeWhenInsideEmptyFunction` in `Lua/Optimizer.hs` exists specifically to undo this: it matches `Function outerArgs [Return (FunctionCall (Function [] body) [])]` and rewrites it back to `Function outerArgs body`. Every lambda whose body is a `Let` or `IfThenElse` pays for this wrapping and then immediately pays again to unwrap it.\n\nProposal: give `IR.Abs` lowering a chunk-aware path. When the body lowers to `Left chunk`, emit `Lua.functionDef luaParams chunk` directly instead of routing it through `asExpression`/`Lua.return`. Only fall back to the wrap-and-return form when the body lowers to `Right expr`. Once nothing produces the wrapped shape, `removeScopeWhenInsideEmptyFunction` and its spec become dead and can be deleted.\n\nNoticed while implementing #153: same pattern as #146 (a rule that's a symptom of an avoidable encoding introduced during lowering, rather than something that belongs at the AST level).\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-04T20:03:09Z","url":"https://github.com/purescript-lua/purescript-lua/issues/158"}
| 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:5a3ef666-8178-2afc-bb47-854abac84448 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E48:CC1A4:99B288:C52FA8:6B00EF30 |
| html-safe-nonce | 25697ff4f5d9332e0bfbad33a2b2ce716803e03a74b7f40f0cf2d75ba33b723c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTQ4OkNDMUE0Ojk5QjI4ODpDNTJGQTg6NkIwMEVGMzAiLCJ2aXNpdG9yX2lkIjoiMjMzNjk0MDkwMjEwNDIzMTcyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | eddf5c88e47a6019da8d9f647cf65336bc74c80de94e02b693699a0e51318bce |
| hovercard-subject-tag | issue:4810381345 |
| 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/158/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f9f2ffb5ef92bafd28c0ac45273f67e260838bc8f15af83f302e83344a175a26/purescript-lua/purescript-lua/issues/158 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f9f2ffb5ef92bafd28c0ac45273f67e260838bc8f15af83f302e83344a175a26/purescript-lua/purescript-lua/issues/158 |
| og:image:alt | IR.Abs lowering (Lua.hs, the IR.Abs case) computes the body via goExp, which is asExpression <<$>> go. When the body lowers to a chunk rather than a bare expression, for example a Let or an IfThenE... |
| 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 | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width