Title: Fold ReflectCtor and DataArgumentByIndex over known constructor applications (case-of-known-constructor) · Issue #177 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Fold ReflectCtor and DataArgumentByIndex over known constructor applications (case-of-known-constructor) · Issue #177 · purescript-lua/purescript-lua
X Title: Fold ReflectCtor and DataArgumentByIndex over known constructor applications (case-of-known-constructor) · Issue #177 · purescript-lua/purescript-lua
Description: Problem The IR has no case-of-known-constructor: ReflectCtor (tag read) and DataArgumentByIndex (field read) never reduce, even when applied to a syntactically known saturated Ctor application — both are handled only at lowering in Lua.h...
Open Graph Description: Problem The IR has no case-of-known-constructor: ReflectCtor (tag read) and DataArgumentByIndex (field read) never reduce, even when applied to a syntactically known saturated Ctor application — bo...
X Description: Problem The IR has no case-of-known-constructor: ReflectCtor (tag read) and DataArgumentByIndex (field read) never reduce, even when applied to a syntactically known saturated Ctor application — bo...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/177
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fold ReflectCtor and DataArgumentByIndex over known constructor applications (case-of-known-constructor)","articleBody":"## Problem\n\nThe IR has no case-of-known-constructor: `ReflectCtor` (tag read) and `DataArgumentByIndex` (field read) never reduce, even when applied to a syntactically known saturated `Ctor` application — both are handled only at lowering in `Lua.hs`. While dictionaries stay opaque these shapes rarely occur, but they are exactly what dictionary specialization and method inlining produce en masse: `bind maybeBind (Just x) f` unfolds into a match on a literal `Just x`, and without these folds the cascade stops at \"construct a table, immediately read its tag\". This is the payoff step of the whole inlining series (GHC calls it KnownBranch); the upcoming specialization issues will list this one as a prerequisite.\n\n## Approach\n\nTwo rewrite rules in the `optimizedExpressionM` fixpoint:\n\n1. `ReflectCtor (Ctor … a₁ … aₙ)` over a saturated constructor spine reduces to the tag string literal. The existing string constant folding plus `removeUnreachableThenBranch`/`removeUnreachableElseBranch` then collapse the surrounding if-chain to the live branch.\n2. `DataArgumentByIndex i (Ctor … a₁ … aₙ)` reduces to `aᵢ`, with the same effect discipline as `reduceObjectProp`: discarded arguments must be trivial (Ref/literal), otherwise they are Let-bound rather than dropped or duplicated (the #167 class of care).\n\nThis is the algebraic-type twin of #153, which added the same fold for record literals.\n\n## Prerequisites / Relations\n\nNothing must land first — this is the enabler. Its landing unblocks the dictionary-specialization work in #178 and #180, whose inlining cascades bottom out at exactly these folds. It reuses the discard discipline established for #167 and mirrors #153 for algebraic types.\n\n## Verification / Measurement\n\nStandalone benchmark impact is near zero — the shapes barely exist before specialization lands — so the value materializes through the inlining cascade and is measured end-to-end by #172, not in isolation. Because the rules touch discard semantics, stress the randomized optimizer specs across seeds.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-06T10:08:59Z","url":"https://github.com/purescript-lua/purescript-lua/issues/177"}
| 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:e56b85df-c1b1-ac8e-bcce-d118534debe3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 835E:E3C4F:621B52:7F024C:6B00DFC2 |
| html-safe-nonce | 61878881c7944ebdfd07b81efa88edbd843ddd7c5552f766db1c748bde909ea0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzVFOkUzQzRGOjYyMUI1Mjo3RjAyNEM6NkIwMERGQzIiLCJ2aXNpdG9yX2lkIjoiMzkxOTE5MDE3NjU5MjYxNzQxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5a5d0bc88c43962ae5de8c9f1e06e7b6fdf7347f9b26999e7170eeada609354a |
| hovercard-subject-tag | issue:4818082754 |
| 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/177/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e5a4d3a70d3976f365af508620ee0421aa16e4d284fb6b1f84f9ca006711b1b7/purescript-lua/purescript-lua/issues/177 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e5a4d3a70d3976f365af508620ee0421aa16e4d284fb6b1f84f9ca006711b1b7/purescript-lua/purescript-lua/issues/177 |
| og:image:alt | Problem The IR has no case-of-known-constructor: ReflectCtor (tag read) and DataArgumentByIndex (field read) never reduce, even when applied to a syntactically known saturated Ctor application — bo... |
| 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