Title: Lift the `*.Uncurried` mk wrappers to n-ary function definitions · Issue #227 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Lift the `*.Uncurried` mk wrappers to n-ary function definitions · Issue #227 · purescript-lua/purescript-lua
X Title: Lift the `*.Uncurried` mk wrappers to n-ary function definitions · Issue #227 · purescript-lua/purescript-lua
Description: #226 (issue #198) lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 now compiles to add3(1, 2, 3). The constructors stayed opaque FFI, and they undo much of the win. add3 = mkFn3 \a b c -> a + b + c still emits...
Open Graph Description: #226 (issue #198) lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 now compiles to add3(1, 2, 3). The constructors stayed opaque FFI, and they undo much of the win. add3...
X Description: #226 (issue #198) lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 now compiles to add3(1, 2, 3). The constructors stayed opaque FFI, and they undo much of the win. add3...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/227
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Lift the `*.Uncurried` mk wrappers to n-ary function definitions","articleBody":"#226 (issue #198) lifted the `run` half of the uncurried wrappers: a saturated `runFn3 add3 1 2 3` now compiles to `add3(1, 2, 3)`. The constructors stayed opaque FFI, and they undo much of the win. `add3 = mkFn3 \\a b c -> a + b + c` still emits as `mkFn3(function(a) return function(b) return function(c) ... end end end)`: the wrapper uncurries the call from the outside but re-curries on the inside via `fn(a)(b)(c)`, so every call of a `Fn3` built this way allocates two intermediate closures. The goal is `add3 = function(a, b, c) return a + b + c end`, with zero closures and the `mk*` accessors gone from the emitted FFI tables the same way the `run*` ones went in #226.\n\n## Foreign shapes\n\nFrom the fork FFI (`Data.Function.Uncurried`, `Control.Monad.ST.Uncurried`, `Effect.Uncurried`):\n\n- `mkFn2`..`mkFn10` are `function(fn) return function(a, …, n) return fn(a)…(n) end end`: a multi-parameter function literal wrapping a curried chain;\n- `mkSTFn1`..`mkSTFn10` and `mkEffectFn1`..`mkEffectFn10` are the same shape with a trailing force: `return fn(a)…(n)()`;\n- `mkFn0` wraps a nullary call `fn()` and stays opaque, symmetric with `runFn0`; `mkFn1` and `runFn1` have no foreign at all (they are PureScript-side `id`).\n\n## Approach\n\nExtend the foreign lifter (#178) with two shapes, mirroring how #198 handled the run half, and allowlist `mkFn2`..`mkFn10`, `mkSTFn1`..`mkSTFn10`, `mkEffectFn1`..`mkEffectFn10`:\n\n- A multi-parameter function literal (all parameters named; a vararg declines) lifts to a single n-ary `AbsN`, not to nested unary `Abs`. The nested encoding is exactly the misapplication the lifter's current decline comment warns about. The n-ary `AbsN` codegen already exists (the #24 uncurrying workers emit through it), and the `WellApplied` linter invariant only constrains literal-lambda heads of `AppN`, which this translation does not create.\n- A nullary call `fn()` in an FFI body is the run of an effect thunk. It lifts to an application of `EffectRunArg`, so `isEffectRun` recognises it throughout the IR pipeline and codegen erases the marker back to a plain `fn()`, the same treatment magic-do's own effect runs get.\n\nWith both in place, `mkFn3` lifts to `\\fn -> AbsN [a, b, c] (fn(a)(b)(c))`, and a `mkFn3 \\a b c -> …` site beta-reduces layer by layer to a bare n-ary `AbsN`, i.e. a direct Lua `function(a, b, c)` definition. Compositions with the run half reduce end to end: `runFn3 (mkFn3 f) x y z` collapses to `f x y z`, and `mkEffectFn2 (runEffectFn2 h)` either reduces to a direct `AppN h [a, b]` (the marker lands on the thunk's unused parameter and is dropped) or is left as the effect-run redex that the codegen fusion from #226 already collapses.\n\nOne guardrail belongs in the allowlist comment: after this change the Effect core (`bindE`, `pureE`) becomes technically liftable (their bodies are pure return trees), but it must not be allowlisted. Magic-do recognises bind chains by name, and inline-always lifting of `bindE` in the optimizer fixpoint (which runs before magic-do) would blind that recognition, which would cost the flat do-chunks and with them the handling of Lua's nesting and locals limits (#19). The broader-allowlist follow-up (#187) needs that warning spelled out.\n\n## Future direction (#228)\n\nThe cleaner endgame is marker-driven magic-do: normalise every effect run to `EffectRunArg` before magic-do runs, and build do-chunks from those semantics instead of recognising `bindE`/`pureE` by name. That would remove the name-driven fragility the guardrail above works around, but it means redesigning magic-do's recognition and the way chunk boundaries keep generated functions within Lua's limits (#19), so it is tracked separately in #228.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-11T09:27:58Z","url":"https://github.com/purescript-lua/purescript-lua/issues/227"}
| 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:bf18aa35-1117-0d96-da85-bfbe36f917c3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 909E:2454CC:723820:92FFAB:6B00E452 |
| html-safe-nonce | 14aef28f22cd80d000f585acf19331c2cad58b17afb8fce5875f334b787b947f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDlFOjI0NTRDQzo3MjM4MjA6OTJGRkFCOjZCMDBFNDUyIiwidmlzaXRvcl9pZCI6Ijg3Njk3MzIxMjk2NDgwNzU4NTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 77c6bffc41f04d78223bc7622710f8d0f62c8c895ab6bf2bfdb707c0befff9f5 |
| hovercard-subject-tag | issue:4861604645 |
| 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/227/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ff7aaf20b8d5cfaf421e990b074c4d5da9391578d0e00204fd1069f344289ce5/purescript-lua/purescript-lua/issues/227 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ff7aaf20b8d5cfaf421e990b074c4d5da9391578d0e00204fd1069f344289ce5/purescript-lua/purescript-lua/issues/227 |
| og:image:alt | #226 (issue #198) lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 now compiles to add3(1, 2, 3). The constructors stayed opaque FFI, and they undo much of the win. add3... |
| 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 | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width