René's URL Explorer Experiment


Title: Case-of-known-constructor through a let-bound scrutinee (#214) by Unisay · Pull Request #216 · purescript-lua/purescript-lua · GitHub

Open Graph Title: Case-of-known-constructor through a let-bound scrutinee (#214) by Unisay · Pull Request #216 · purescript-lua/purescript-lua

X Title: Case-of-known-constructor through a let-bound scrutinee (#214) by Unisay · Pull Request #216 · purescript-lua/purescript-lua

Description: Closes #214. Builds on #213 (now on main). What reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place, and a scrutinee read more than once is never in place. Beta reduction Let-binds a non-trivial argument rather than substitute it into every occurrence (the #167 discipline), and a dictionary method reads its scrutinee several times: a tag test, a payload read, a fallthrough tag test. So an inlined and beta-reduced method lands on let v = Just (x + 1) in if justTag == ReflectCtor v then … v.value0 … else if nothingTag == ReflectCtor v then Nothing else … and nothing folds. The rules see ReflectCtor (Ref v) and ObjectProp (Ref v) "value0", never the constructor, so the whole match stays opaque behind the Let. That is a near-zero win for exactly the multiply-read-scrutinee methods (bind, apply), which are most of them. How propagateKnownCtorThroughLet propagates a known constructor from a Standalone Let binding into the binder's reads. When the RHS is a saturated Ctor application and the binder is read only through constructor-eliminating reads: each ReflectCtor v folds to the tag string (sum types only, as in reduceKnownConstructor); each field read (ObjectProp v "valueᵢ", DataArgumentByIndex i v) folds to a fresh field-binder bound once to the iᵗʰ argument, GHC's case-binder to field-binder split, so a non-trivial argument read at several sites is evaluated once rather than copied to each site; the binding is dropped, its unread arguments discarded with the same licence reduceKnownConstructor has for a field read's siblings. Trivial and dead field-binders then inline or DCE away, and with the reads folded the surrounding Eq/if meets constant folding and the unreachable-branch rules, collapsing the decision tree to its live arm. That is the case-of-known-constructor payoff of #177, now reached through the Let. The rule declines when the binder is read as a whole value anywhere (a sibling binding, or a non-eliminating position such as an argument to a function): dropping it would dangle the reference, and keeping it while binding the fields would duplicate the arguments. A product-type ReflectCtor read has no tag row to fold to, so it too leaves a whole-value read and the rule declines. It also guards against a self-referencing RHS, which cannot arise under the global uniqueness condition but can on the non-GUC input optimizedExpression is exercised on directly. Why now This is the enabler that makes dictionary-method inlining (#180) pay off. Once #180 inlines a method and beta reduction Let-binds the dictionary value, the payload is read through exactly this Let-bound shape; without this rule #180 would inline the method but leave the match opaque. #180 stacks on this branch. Verification New optimizer specs cover the fold and its refusals: the tag fold unlocking the live branch, the payload dropped when only the tag is read, a field read at several sites bound once (proving no duplication), the whole-value and partial-application declines, and an end-to-end collapse to straight-line code run through the checked pipeline so a GUC or scoping violation would fail rather than pass silently. A randomized property stresses the fold across scalar payloads, checking the binder is eliminated and the free-reference multiset never grows. Full suite green (cabal test all): 702 examples, 0 failures, and the IR optimizer specs stay green across several seeds. No structural golden moved and no eval oracle moved, matching the near-zero standalone impact the issue predicts, since the shape appears once method inlining lands. fourmolu and hlint clean, warning-free build.

Open Graph Description: Closes #214. Builds on #213 (now on main). What reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place, and a scrutinee read more than once is never in place. Beta...

X Description: Closes #214. Builds on #213 (now on main). What reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place, and a scrutinee read more than once is never in place. Beta...

Opengraph URL: https://github.com/purescript-lua/purescript-lua/pull/216

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:4f90702d-25a1-7cc4-60f4-267e3c0f99c3
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idEA90:2F9718:82EA0B:B119BA:6B00E4A6
html-safe-nonce4a72af1506726480cdd14c6a27bb467392914b402faf3b2066ab302c77cf2737
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTkwOjJGOTcxODo4MkVBMEI6QjExOUJBOjZCMDBFNEE2IiwidmlzaXRvcl9pZCI6IjI3OTAyNTMzNzEzODk0MzcwOTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacabdf213beadf2bc91e5303287771940a68e7d5939f9f19f5db96b956e263c0fd
hovercard-subject-tagpull_request:4020982577
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/purescript-lua/purescript-lua/pull/216/files
twitter:imagehttps://avatars.githubusercontent.com/u/1009751?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1009751?s=400&v=4
og:image:altCloses #214. Builds on #213 (now on main). What reduceKnownConstructor (#177) only fires on a constructor that is syntactically in place, and a scrutinee read more than once is never in place. Beta...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git
octolytics-dimension-user_id131581790
octolytics-dimension-user_loginpurescript-lua
octolytics-dimension-repository_id587200487
octolytics-dimension-repository_nwopurescript-lua/purescript-lua
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id587200487
octolytics-dimension-repository_network_root_nwopurescript-lua/purescript-lua
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release624179fb8b88d26ba5bba08894eb60a1c5a1d93d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/purescript-lua/purescript-lua/pull/216/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F216%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpurescript-lua%2Fpurescript-lua%2Fpull%2F216%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=purescript-lua%2Fpurescript-lua
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/216/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/216/files
Reloadhttps://github.com/purescript-lua/purescript-lua/pull/216/files
purescript-luahttps://github.com/purescript-lua
purescript-luahttps://github.com/purescript-lua/purescript-lua
Codehttps://github.com/purescript-lua/purescript-lua
Issues48 (48)https://github.com/purescript-lua/purescript-lua/issues
Pull requestshttps://github.com/purescript-lua/purescript-lua/pulls
Discussionshttps://github.com/purescript-lua/purescript-lua/discussions
Actionshttps://github.com/purescript-lua/purescript-lua/actions
Projectshttps://github.com/purescript-lua/purescript-lua/projects
Security and qualityhttps://github.com/purescript-lua/purescript-lua/security
Insightshttps://github.com/purescript-lua/purescript-lua/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpurescript-lua%2Fpurescript-lua%2Fissues%2Fnew%2Fchoose
Unisayhttps://github.com/Unisay
mainhttps://github.com/purescript-lua/purescript-lua/tree/main
issue-214/known-ctor-through-lethttps://github.com/purescript-lua/purescript-lua/tree/issue-214/known-ctor-through-let
Conversation 12 https://github.com/purescript-lua/purescript-lua/pull/216
Commits 3 https://github.com/purescript-lua/purescript-lua/pull/216/commits
Checks 2 https://github.com/purescript-lua/purescript-lua/pull/216/checks
Files changed https://github.com/purescript-lua/purescript-lua/pull/216/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/216/files
Case-of-known-constructor through a let-bound scrutinee (#214) https://github.com/purescript-lua/purescript-lua/pull/216/files#top
Show all changes 3 commits https://github.com/purescript-lua/purescript-lua/pull/216/files
1b43350 feat: fold case-of-known-constructor through a let-bound scrutinee (#… Unisay Jul 9, 2026 https://github.com/purescript-lua/purescript-lua/pull/216/commits/1b433504b0be4919c88ac367aba39eb8e3442474
2d1db25 address copilot review on PR #216 Unisay Jul 9, 2026 https://github.com/purescript-lua/purescript-lua/pull/216/commits/2d1db25d78498bfb6f8a621b0b03983d3cd0962f
bc274d9 address copilot re-review on PR #216 Unisay Jul 9, 2026 https://github.com/purescript-lua/purescript-lua/pull/216/commits/bc274d94618d65377e907ffa607a60967eacfd2e
Clear filters https://github.com/purescript-lua/purescript-lua/pull/216/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/216/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/216/files
20260709_114305_unisay_known_ctor_through_let.md https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-9777fa5bbca0931d1ea1c5202c7378a33218fbbf9664fdf2b3d547c88673cd46
Optimizer.hs https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Spec.hs https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-241ea2421c606c31b9414fb386f9f4d1beb60055ed792935b393101edfd7b949
changelog.d/20260709_114305_unisay_known_ctor_through_let.mdhttps://github.com/purescript-lua/purescript-lua/pull/216/files#diff-9777fa5bbca0931d1ea1c5202c7378a33218fbbf9664fdf2b3d547c88673cd46
View file https://github.com/purescript-lua/purescript-lua/blob/bc274d94618d65377e907ffa607a60967eacfd2e/changelog.d/20260709_114305_unisay_known_ctor_through_let.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/216/{{ revealButtonHref }}
lib/Language/PureScript/Backend/IR/Optimizer.hshttps://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
View file https://github.com/purescript-lua/purescript-lua/blob/bc274d94618d65377e907ffa607a60967eacfd2e/lib/Language/PureScript/Backend/IR/Optimizer.hs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/purescript-lua/purescript-lua/pull/216/{{ revealButtonHref }}
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/216/files
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/216/files
https://github.com/purescript-lua/purescript-lua/pull/216/files#diff-487ead9d0ca9c3e6f68e23c604b0ae9070089e0dd0f7d214cdce5fbc878f3315
Please reload this pagehttps://github.com/purescript-lua/purescript-lua/pull/216/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.