Title: Case-of-known-constructor through a let-bound scrutinee · Issue #214 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Case-of-known-constructor through a let-bound scrutinee · Issue #214 · purescript-lua/purescript-lua
X Title: Case-of-known-constructor through a let-bound scrutinee · Issue #214 · purescript-lua/purescript-lua
Description: Problem reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place. A scrutinee read more than once is never in place: beta reduction Let-binds a non-trivial argument instead of substituting it into every oc...
Open Graph Description: Problem reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place. A scrutinee read more than once is never in place: beta reduction Let-binds a non-trivial argument ...
X Description: Problem reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place. A scrutinee read more than once is never in place: beta reduction Let-binds a non-trivial argument ...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/214
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Case-of-known-constructor through a let-bound scrutinee","articleBody":"## Problem\n\n`reduceKnownConstructor` (#177) only fires on a constructor that is syntactically in place. A scrutinee read more than once is never in place: beta reduction Let-binds a non-trivial argument instead of substituting it into every occurrence (the #167 discipline), and a dictionary method reads its scrutinee at least three times: a tag test, a payload read, and a second tag test for the fallthrough. So inlining a `bind`/`apply` method and beta-reducing lands on\n\n```\nlet v = Just (x + 1) in\n if justTag == ReflectCtor v then … v.value0 …\n else if nothingTag == ReflectCtor v then Nothing\n else …\n```\n\nand folds nothing: the rules see `ReflectCtor (Ref v)` and `ObjectProp (Ref v) \"value0\"`, never the constructor. Checked against the current optimizer: that term is returned unchanged.\n\nThis is the step that turns an inlined method into straight-line code. Without it #180 inlines the method but leaves an opaque Let-bound match, which is a near-zero win for exactly the multi-use-scrutinee methods (`bind`, `apply`), which is most of them.\n\n## Approach\n\nPropagate a known constructor from a Let binder into its reads. When a `Standalone` Let binding's RHS is a saturated `Ctor` application, fold the binder's reads in the body: `ReflectCtor v` becomes the tag string, and each payload read (`ObjectProp v \"valueᵢ\"`, `DataArgumentByIndex i v`) becomes the iᵗʰ argument.\n\nTo keep the #167 discipline (a field expression must not be duplicated across reads), bind each read field to a fresh local rather than substituting the constructor into the read sites: GHC's case-binder to field-binder split. Trivial fields and dead field-binders then inline or DCE away. Drop the Let once the binder is no longer read as a whole value, keep it otherwise. GUC guarantees no shadowing, so the binder resolves by name.\n\nWith the reads folded, the surrounding `Eq`/`if` meets constant folding and `removeUnreachable*`, collapsing the decision tree to its live arm: the KnownBranch payoff #177 set up, now reachable through the Let.\n\n## Prerequisites / Relations\n\nExtends #177 from in-place to Let-bound scrutinees. Consumes the `ObjectProp` field-read fold (#213) and the Let-binding discipline of #167. Prerequisite for #180: this is the enabler that makes method inlining pay off.\n\n## Verification / Measurement\n\nMeasured end to end by #172 through the `LongMaybeBind` / `LongEitherBind` / `LongWriterBind` / `LongStateBind` bind-chain goldens; the eval goldens are the correctness net, and they must not move. The rule rewrites binders and touches discard semantics, so stress the randomized optimizer specs across seeds and lean on the checked pipeline's scope-invariant linting.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-09T08:51:31Z","url":"https://github.com/purescript-lua/purescript-lua/issues/214"}
| 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:f6524cf8-004c-2ac9-f83a-32dcae40aec0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9698:22DB35:87812E:B10274:6B00DB73 |
| html-safe-nonce | 50b80ec718a6a89cdbadc59a5f8a5a7ad134749104c32982d9ad8fa6d6bcad61 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Njk4OjIyREIzNTo4NzgxMkU6QjEwMjc0OjZCMDBEQjczIiwidmlzaXRvcl9pZCI6IjI5ODU0NTc4NTY4NzYxNzQxOTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 28d978704a3249dfee02013b6cdac8e94de60181cc1dac60ec3e4165ae5deb65 |
| hovercard-subject-tag | issue:4844749206 |
| 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/214/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3bf9e8be13dfb9669dadd0097fe754874940d5be58f5d544deda2edd5fda3f39/purescript-lua/purescript-lua/issues/214 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3bf9e8be13dfb9669dadd0097fe754874940d5be58f5d544deda2edd5fda3f39/purescript-lua/purescript-lua/issues/214 |
| og:image:alt | Problem reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place. A scrutinee read more than once is never in place: beta reduction Let-binds a non-trivial argument ... |
| 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