Title: Conservative CSE for effect-free-by-construction IR subexpressions · Issue #183 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Conservative CSE for effect-free-by-construction IR subexpressions · Issue #183 · purescript-lua/purescript-lua
X Title: Conservative CSE for effect-free-by-construction IR subexpressions · Issue #183 · purescript-lua/purescript-lua
Description: Problem Generated output contains verbatim repeats of pure subexpressions. In Data.String.CodePoints.unsafeCodePointAt0 the charAt lambda is pasted twice (two applications with different arguments but an identical lambda body); dictionar...
Open Graph Description: Problem Generated output contains verbatim repeats of pure subexpressions. In Data.String.CodePoints.unsafeCodePointAt0 the charAt lambda is pasted twice (two applications with different arguments ...
X Description: Problem Generated output contains verbatim repeats of pure subexpressions. In Data.String.CodePoints.unsafeCodePointAt0 the charAt lambda is pasted twice (two applications with different arguments ...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/183
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Conservative CSE for effect-free-by-construction IR subexpressions","articleBody":"## Problem\n\nGenerated output contains verbatim repeats of pure subexpressions. In `Data.String.CodePoints.unsafeCodePointAt0` the `charAt` lambda is pasted twice (two applications with different arguments but an identical lambda body); dictionary projections and `compare(dictOrd)`-style chains repeat within one body. Each repeat is a repeated closure allocation and repeated calls at runtime.\n\n## Approach\n\nBinding-level CSE in the IR: alpha-equivalent subexpressions within one body are hoisted into a shared Let binding. The strictness caveat bounds the scope: hoisting an expression that would only have evaluated in one branch into a dominating Let introduces divergence or exceptions where none existed. Hence the pass only touches forms that are effect-free by construction — lambda literals (closure allocation is pure; exactly the `charAt` case), literals, saturated `Ctor` applications, and projections out of refs — never arbitrary applications. GHC's CSE pass with its sharing restrictions is the precedent (see docs/OPTIMIZATIONS_SURVEY.md).\n\n## Prerequisites / Relations\n\nNo prerequisites; independent in the dependency graph. Relates only to #172, which would register the effect.\n\n## Verification / Measurement\n\nThe duplicated `charAt` lambda in `Data.String.CodePoints.unsafeCodePointAt0` is emitted once (hoisted into a shared Let) instead of pasted twice. The win is small-to-medium and allocation-shaped, so it shows up indirectly in #172 (code size, allocation counters) rather than as a headline speed-up. Because the pass moves expressions, stress the randomized optimizer specs across seeds to confirm no branch-conditional evaluation is hoisted.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-06T10:48:17Z","url":"https://github.com/purescript-lua/purescript-lua/issues/183"}
| 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:25243fbf-3ad9-22fe-04c3-859ede718e17 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9062:16EED3:727E3B:93439C:6B00E44C |
| html-safe-nonce | 1d495ab000bb76ac206d527808c8197df58ef5618143587955643d8abc39d380 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDYyOjE2RUVEMzo3MjdFM0I6OTM0MzlDOjZCMDBFNDRDIiwidmlzaXRvcl9pZCI6IjQyNzg4MjEwNjgzMjU1Nzc4MDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d32c65623ef113c871f1c34eaad01362af115dd745c92bdb50ca2e141a3e4170 |
| hovercard-subject-tag | issue:4818376479 |
| 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/183/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9cb982b5f9d06601da3af98cac204ea14445855c55c559e1687a9ac243e297c4/purescript-lua/purescript-lua/issues/183 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9cb982b5f9d06601da3af98cac204ea14445855c55c559e1687a9ac243e297c4/purescript-lua/purescript-lua/issues/183 |
| og:image:alt | Problem Generated output contains verbatim repeats of pure subexpressions. In Data.String.CodePoints.unsafeCodePointAt0 the charAt lambda is pasted twice (two applications with different arguments ... |
| 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 | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width