Title: Lift the *.Uncurried mk wrappers to n-ary function definitions (#227) by Unisay · Pull Request #229 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Lift the *.Uncurried mk wrappers to n-ary function definitions (#227) by Unisay · Pull Request #229 · purescript-lua/purescript-lua
X Title: Lift the *.Uncurried mk wrappers to n-ary function definitions (#227) by Unisay · Pull Request #229 · purescript-lua/purescript-lua
Description: Closes #227. #226 lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 compiles to add3(1, 2, 3). The constructors stayed opaque FFI, though, and they undid much of the win. add3 = mkFn3 \a b c -> a + b + c still emitted as mkFn3(function(a) return function(b) return function(c) … end end end), uncurried on the outside but re-curried on the inside via fn(a)(b)(c), so every call of a Fn3 built this way allocated two intermediate closures. This PR lifts the mk half. The definition now compiles to function(a, b, c) return a + b + c end with no closures at all, and the mk* accessors disappear from the emitted FFI tables the same way the run* ones did in #226. Changes 1. Lift the mk wrappers (ForeignLift). Two shapes join the translatable subset. A multi-parameter function literal lifts to a single n-ary AbsN, provided every parameter is named and the names are pairwise distinct: a vararg declines, and so does a duplicate name, because Lua binds the body's reference to the last same-named parameter and an AbsN would silently miscompile it. A nullary call fn() (the trailing effect run of the mk{ST,Effect}FnN wrappers) lifts to an application of the EffectRunArg marker, the same shape magic-do emits; codegen erases it back to an empty argument list. The literal-head arity guard from #226 stays exact, with the marker counting as one argument, so a thunk head passes and any wider literal declines. mkFn2…mkFn10, mkSTFn1…mkSTFn10, and mkEffectFn1…mkEffectFn10 join the allowlist. runFn0/mkFn0 stay off it by policy, not liftability: their bodies force a pure Fn0 with a nullary call, which must not be marked an effect run. 2. Guard the allowlist against lifting the Effect/ST core. With nullary calls translatable, the core (Effect.bindE/pureE, Control.Monad.ST.Internal.bind_/pure_) becomes technically liftable, and the allowlist Haddock now warns the broader-allowlist follow-up (#187) off it. Magic-do recognises bind chains by name, so an inline-always core would be inlined away during the optimizer fixpoint, which runs before magic-do, and that recognition would go blind: no flat do-chunks, and none of the chunked statement sequences that keep the output under Lua's local-variable limits (#19). Lifting the core behind a marker magic-do understands is tracked in #228. Before / after Pure definitions collapse to n-ary literals, including the point-free mulByFn = mkFn2 mul, whose wrapped function arrives through dictionary resolution rather than as a literal lambda: -- before: M.Golden_UncurriedLift_Test_add3 = M.Data_Function_Uncurried_foreign.mkFn3(function( a ) return function(b) return function(c) return a + b + c end end end) -- after: M.Golden_UncurriedLift_Test_add3 = function(a, b, c) return a + b + c end M.Golden_UncurriedLift_Test_mulByFn = function(a, b) return a * b end An effectful body whose thunk head is not a literal erases the marker into a direct force: M.Golden_UncurriedLift_Test_sumST = function(a, b) return M.Control_Monad_ST_Internal_applicativeST.pure(a + b)() end One shape keeps a residual closure. A do-block body (logTwice = mkEffectFn2 \a b -> do …) is a statement sequence, and the codegen thunk fusion from #226 only covers single-call bodies, so the run of the magic-do chunk emits as an IIFE inside the n-ary literal: one closure per call, down from the wrapper's two. A tail-position IIFE collapse in the Lua optimizer would finish the job; #230 tracks that as optimizer work independent of the lifter. The Data.Function.Uncurried, Effect.Uncurried, and Control.Monad.ST.Uncurried foreign tables are gone from the golden output entirely. Verification The lifter specs were written first and red: five new positive shapes (mkFn2, mkEffectFn2, mkSTFn1, a bare multi-parameter literal, a nullary call) plus new declines (a vararg, duplicate parameter names, an under-applied multi-parameter head). The UncurriedLift golden gains the mulByFn case, with its hand-written eval oracle line (48) added before any run; the checked golden pipeline lints scoping, uniqueness, and well-appliedness at every pass boundary. Full cabal test all is green (718 examples), the spec suite was repeated on three fresh Hedgehog seeds, luacheck reports no errors, and the bench FNEW census is unchanged (the bench modules use no mk* wrappers).
Open Graph Description: Closes #227. #226 lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 compiles to add3(1, 2, 3). The constructors stayed opaque FFI, though, and they undid much of the win....
X Description: Closes #227. #226 lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 compiles to add3(1, 2, 3). The constructors stayed opaque FFI, though, and they undid much of the win....
Opengraph URL: https://github.com/purescript-lua/purescript-lua/pull/229
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:8b2e9f23-0460-3c8d-f128-623dfbd257df |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BD30:6FAD8:C9F4FB:104C608:6B00EF99 |
| html-safe-nonce | 9ed2a0d880cb51c9bfadb1bfa017ee5fd6e963f58f41769d1718deadb676c874 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDMwOjZGQUQ4OkM5RjRGQjoxMDRDNjA4OjZCMDBFRjk5IiwidmlzaXRvcl9pZCI6Ijc2MTU4MDk4MTYwNTY4ODUxNDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | af2df7c23a22d68f416419ce207652b48902b8abed27b50ce5daca94690371ac |
| hovercard-subject-tag | pull_request:4035093211 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/purescript-lua/purescript-lua/pull/229/files |
| twitter:image | https://avatars.githubusercontent.com/u/1009751?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1009751?s=400&v=4 |
| og:image:alt | Closes #227. #226 lifted the run half of the uncurried wrappers: a saturated runFn3 add3 1 2 3 compiles to add3(1, 2, 3). The constructors stayed opaque FFI, though, and they undid much of the win.... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| 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 |
Links:
Viewport: width=device-width