Title: Derive transitive inline directives on specialization bindings by Unisay · Pull Request #324 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Derive transitive inline directives on specialization bindings by Unisay · Pull Request #324 · purescript-lua/purescript-lua
X Title: Derive transitive inline directives on specialization bindings by Unisay · Pull Request #324 · purescript-lua/purescript-lua
Description: Closes #241. Problem With graduated @inline directives in place (#232), a directive names the generic combinator, but the bindings that actually appear at call sites are often its specializations: purs's common-subexpression pass floats a repeated dictionary application into a top-level binding (bind = Control.Bind.bind bindStateT, verbatim from real CoreFn output), and users write the same shape by hand as top-level partial applications. None of these carry a directive of their own, so each had to be annotated by hand for the directive to keep working through the indirection. Mechanism The arity=N policy composes over application, which is what makes derivation mechanical. For a binding a = f x₁ … xₖ where f carries arity=N: when k < N, a call site applying N − k more arguments to a reconstructs — once a's right-hand side is pasted there — a site applying at least N arguments to f, exactly a qualifying site of the explicit directive, so a inherits arity=(N − k); when k ≥ N, the right-hand side is itself already a qualifying call, so every use of a stands for the specialized value and a inherits always-inline (the arity=0 reading of the same arithmetic). An explicit directive on the specialization always wins over derivation. The rationale lives in Note [Derived inline directives]. The optimizer pipeline is now split into two phases around the derivation point (OptimizerPhases). Derivation reads the module settled by the post-merge optimize+dce fixpoint rather than the pristine input: a specialization referenced once has already dissolved into its use site by then, so only the shared survivors are inspected. It runs before the uncurry worker/wrapper split, so a derived arity joins the uncurry veto like an explicit one, and before the post-uncurry fixpoint, whose whole-binding inlining performs the derived always-inline pastes; derived arities paste at qualifying call sites in the specialize fixpoint exactly like explicit ones. One left-to-right fold over the bindings both derives transitively (a standalone binding references only earlier bindings, so a chain of specializations resolves in a single pass) and bounds the derivation. End to end Golden.DirectiveDerived.Test carries -- @inline combine arity=2 on a three-parameter function too big for any heuristic paste, plus two pragma-free specializations: onePlusTwo = combine 1 2 (saturated at the directed arity) and oneOnly = combine 1 (one argument short). Before this change both survive as shared bindings and every site calls them (from the golden committed with the spec commit): local Golden_DirectiveDerived_Test_onePlusTwo = function(c_S_0) return c_S_0 - 1 - 1 - 2 - 2 - 1 - 3 - 2 - 4 - 1 - 5 - 2 - 6 - 1 - 7 - 2 - 8 - 1 - 9 - 2 - 10 - 1 - 11 - 2 - 12 - 1 - 13 - 2 - 14 - 1 - 15 - 2 - 16 - 1 - 17 - 2 - 18 - 1 - 19 - 2 - 20 end -- ... local _ = Effect_Console_log(Data_Show_showIntImpl(Golden_DirectiveDerived_Test_onePlusTwo(100)))() local _ = Effect_Console_log(Data_Show_showIntImpl(Golden_DirectiveDerived_Test_onePlusTwo(200)))() local _ = Effect_Console_log(Data_Show_showIntImpl(Golden_DirectiveDerived_Test_oneOnly(50)(60)))() After: onePlusTwo derives always-inline, pastes at both sites and folds to constants; oneOnly derives arity=1, pastes at its applied site, and stays a pinned shared binding for the bare use that passes it to a function: local _ = Effect_Console_log(Data_Show_showIntImpl(-140))() local _ = Effect_Console_log(Data_Show_showIntImpl(-40))() local _ = Effect_Console_log(Data_Show_showIntImpl(-660))() return Effect_Console_log(Data_Show_showIntImpl(Golden_DirectiveDerived_Test_apply34(Golden_DirectiveDerived_Test_oneOnly)))() end)() The hand-written eval oracle (-140, -40, -660, -246) passes in both states, so the transform is semantics-preserving. The corefn for this module also shows purs's CSE emitting genuine synthetic floats (sub = Data.Ring.sub ringInt, show = Data.Show.show showInt, discard = Control.Bind.discard discardUnit bindEffect) — the shapes this derivation exists for, once the default directive pack (#242) names their targets. Tests Four pipeline-level specs (derives directives for specializations) cover the saturated and under-applied derivations, transitivity through a chain (an inner specialization deriving from an outer one's derived entry, kept alive through the settle phase by a second use), and the explicit-directive precedence guard; three were red before the implementing commit. The golden module exercises the module-header pragma path end to end. No other golden moved: the corpus carries no arity= directives yet, so derivation fires nowhere else.
Open Graph Description: Closes #241. Problem With graduated @inline directives in place (#232), a directive names the generic combinator, but the bindings that actually appear at call sites are often its specializations: ...
X Description: Closes #241. Problem With graduated @inline directives in place (#232), a directive names the generic combinator, but the bindings that actually appear at call sites are often its specializations: ...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/pull/324
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:c4c9841c-6431-0720-8041-4c80fd325b42 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E32C:C2718:9C99A9:CC3A19:6B00E490 |
| html-safe-nonce | 8812fed767d32ccd72cbc8a82e3333be81dbba1ae4e4b0433d537d54ccea4009 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzJDOkMyNzE4OjlDOTlBOTpDQzNBMTk6NkIwMEU0OTAiLCJ2aXNpdG9yX2lkIjoiNzgzMDQwNjE5OTE0NDE0NjA2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9348f5cc52b51fd7d5397efb9cc41350d5ac39be9bc89055ac0413fd86542103 |
| hovercard-subject-tag | pull_request:4145166487 |
| 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/324/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 #241. Problem With graduated @inline directives in place (#232), a directive names the generic combinator, but the bindings that actually appear at call sites are often its specializations: ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width