Title: Enrich IR analysis with a Complexity/Capture lattice to gate inlining and unpacking · Issue #231 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Enrich IR analysis with a Complexity/Capture lattice to gate inlining and unpacking · Issue #231 · purescript-lua/purescript-lua
X Title: Enrich IR analysis with a Complexity/Capture lattice to gate inlining and unpacking · Issue #231 · purescript-lua/purescript-lua
Description: Problem The inliner decides with a flat model: exact free-reference counts (Note [Incremental free-reference counting]), a single inlineSizeBudget = 64 node ceiling, and isInlinableExpr (a node is inlinable if it carries Always, is a bar...
Open Graph Description: Problem The inliner decides with a flat model: exact free-reference counts (Note [Incremental free-reference counting]), a single inlineSizeBudget = 64 node ceiling, and isInlinableExpr (a node is ...
X Description: Problem The inliner decides with a flat model: exact free-reference counts (Note [Incremental free-reference counting]), a single inlineSizeBudget = 64 node ceiling, and isInlinableExpr (a node is ...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/231
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enrich IR analysis with a Complexity/Capture lattice to gate inlining and unpacking","articleBody":"## Problem\n\nThe inliner decides with a flat model: exact free-reference counts (Note [Incremental free-reference counting]), a single `inlineSizeBudget = 64` node ceiling, and `isInlinableExpr` (a node is inlinable if it carries `Always`, is a bare `Ref`, or is a non-recursive literal). Nothing captures *how* costly an expression is to duplicate, or *where* a reference sits. So one size threshold gates a field projection and a 60-node lambda the same way, and a reference evaluated unconditionally is treated like one hidden behind an `if` or captured in a closure.\n\nTwo small per-node analysis lattices make the same calls sharper:\n\n- `Complexity = Trivial \u003c Deref \u003c KnownSize \u003c NonTrivial`: `Deref` is a field projection; `KnownSize` a lambda or a non-empty record/array literal.\n- `Capture = CaptureNone \u003c CaptureBranch \u003c CaptureClosure`: whether a reference is reached unconditionally, only under a branch, or from inside a closure.\n\nWith per-reference usage (`total`, `captured`, arities, call/access/case counts) alongside them, an inliner takes `Trivial`/`Deref` unconditionally while refusing to duplicate `NonTrivial` work under a branch or a closure.\n\n## Approach\n\nAdd a `Complexity` lattice and a `Capture` flag to the analysis already threaded for reference counting, computed bottom-up in the same traversal. Feed both into the shared inlining guard (`isInlinableExpr` / `withBinding` / `betaReduce`, which share one guard per Note [Beta reduction and local inlining share an inlining guard]): inline `Trivial`/`Deref` regardless of use count; allow a small `KnownSize` body when used once or closed; refuse to duplicate a `NonTrivial` body reached under `CaptureBranch`/`CaptureClosure`. The `64`-node budget stays as the ceiling for whatever is left.\n\nThis is analysis enrichment, not a pipeline reshape. No new pass, no move toward NBE. The lattices live in the annotation; the fixpoint framework and pass contracts are untouched.\n\n## Prerequisites / Relations\n\nIndependent to land. It is an enabler: #240 (scalar-replacement unpacking) needs the same exact-use accounting to prove an aggregate is read only field-wise, and #239 (ref-cell unboxing) needs the `Capture` flag to prove a cell does not escape. It also sharpens the existing inliner tuning in #211 and #221 and the CSE sharing condition in #183, without depending on any of them.\n\n## Verification / Measurement\n\nA focused optimizer test: a `Deref` used at several sites inlines at all of them with no size gate, while a `NonTrivial` body sitting under a branch stays shared. The corpus effect is size-shaped and shows up through the #172 counters (fewer shared trivial bindings, no growth from duplicated non-trivial work); eval goldens must not move, since the change is to which bindings dissolve, not to semantics.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-11T12:02:39Z","url":"https://github.com/purescript-lua/purescript-lua/issues/231"}
| 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:e6163ff1-2c36-584c-82f3-c557525e25b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C876:240CD1:6591BE:8374F7:6B00DFAE |
| html-safe-nonce | dd1c1c284315c920902b856e1c8b3370b20041da2dfe699a65c24f981abbe95a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODc2OjI0MENEMTo2NTkxQkU6ODM3NEY3OjZCMDBERkFFIiwidmlzaXRvcl9pZCI6Ijg5NTIxOTY1MjY2NTkxMzMzNTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9b548b3cbc5129cfe0813636bcbae4807d7853b8325add2ba9cd6d57b4146d85 |
| hovercard-subject-tag | issue:4862139795 |
| 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/231/issue_layout |
| twitter:image | https://opengraph.githubassets.com/424934e0d33ac56c7c02acdc36d5f058c184ef7b6dd944c50c92ced209a6aa7a/purescript-lua/purescript-lua/issues/231 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/424934e0d33ac56c7c02acdc36d5f058c184ef7b6dd944c50c92ced209a6aa7a/purescript-lua/purescript-lua/issues/231 |
| og:image:alt | Problem The inliner decides with a flat model: exact free-reference counts (Note [Incremental free-reference counting]), a single inlineSizeBudget = 64 node ceiling, and isInlinableExpr (a node is ... |
| 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