Title: Uncurry data constructor applications · Issue #201 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Uncurry data constructor applications · Issue #201 · purescript-lua/purescript-lua
X Title: Uncurry data constructor applications · Issue #201 · purescript-lua/purescript-lua
Description: Problem The Lua codegen emits every data constructor as a curried chain of closures. In the IR.Ctor case of lib/Language/PureScript/Backend/Lua.hs, foldr wrap value args wraps the table constructor in one single-parameter Lua function pe...
Open Graph Description: Problem The Lua codegen emits every data constructor as a curried chain of closures. In the IR.Ctor case of lib/Language/PureScript/Backend/Lua.hs, foldr wrap value args wraps the table constructor...
X Description: Problem The Lua codegen emits every data constructor as a curried chain of closures. In the IR.Ctor case of lib/Language/PureScript/Backend/Lua.hs, foldr wrap value args wraps the table constructor...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/201
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Uncurry data constructor applications","articleBody":"## Problem\n\nThe Lua codegen emits every data constructor as a curried chain of closures. In the `IR.Ctor` case of `lib/Language/PureScript/Backend/Lua.hs`, `foldr wrap value args` wraps the table constructor in one single-parameter Lua function per field, so a two-field constructor `C` becomes `function(a) return function(b) return { ... } end end`. A saturated application `C x y` then pays two closure allocations and two calls to build one table, the same per-argument cost that #24 removes for ordinary functions. Constructor applications are among the most common applications in typical PureScript, so this is a broad and hot cost.\n\n## Approach\n\nGive constructors the worker/wrapper treatment #24 gives functions. At a saturated constructor site, emit the table directly from the arguments, with no intermediate closures. Keep a curried wrapper for partial applications and for a constructor used as a first-class value, so that `map Just xs` and a partially applied constructor still work unchanged. The split can live in the IR (a constructor worker that is an n-ary `AbsN` over the fields, building the table) so that the existing saturated-site rewrite and the downstream DCE and beta passes handle it exactly as they do for functions, rather than as a special case in the Lua backend.\n\n## Prerequisites / Relations\n\nSame family as #24, applied to the constructor side of application rather than the function side.\n\n## Verification / Measurement\n\n`bench/micro/ctor_match.lua` already measures constructor allocation and tag matching and is the natural before/after anchor. The win is the removal of the per-field closure allocations on saturated construction, both the PUC Lua call overhead and the LuaJIT trace aborts that closure creation triggers.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-07T17:38:55Z","url":"https://github.com/purescript-lua/purescript-lua/issues/201"}
| 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:4abaee22-ba3f-eaab-259d-d5ccd1d557e2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6D8:20AA01:99640F:C6792C:6B00DFA8 |
| html-safe-nonce | 45397c19dac5e28a1d39b0bccb53a256ed2cd842979792bb9d4ef0912d96b092 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkQ4OjIwQUEwMTo5OTY0MEY6QzY3OTJDOjZCMDBERkE4IiwidmlzaXRvcl9pZCI6IjUxNTE5OTc4NzUzMzY1Njg3NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 20fdf4ccd133595642cc6f3b13a83f686a8c35240cf9980dc1dc40ecb0a4b788 |
| hovercard-subject-tag | issue:4830876752 |
| 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/201/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1503dc3035987db5080d8eee5cdd6abad9362b1c55940ed99bb01ce16be9202/purescript-lua/purescript-lua/issues/201 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1503dc3035987db5080d8eee5cdd6abad9362b1c55940ed99bb01ce16be9202/purescript-lua/purescript-lua/issues/201 |
| og:image:alt | Problem The Lua codegen emits every data constructor as a curried chain of closures. In the IR.Ctor case of lib/Language/PureScript/Backend/Lua.hs, foldr wrap value args wraps the table constructor... |
| 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