-
-
Notifications
You must be signed in to change notification settings - Fork 161
codegen: receiver-region model + equivalence lint (#9254 phase 1) #9257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
proggeramlug
merged 3 commits into
PerryTS:main
from
proggeramlug:design/9254-receiver-regions
Aug 31, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| **A single vocabulary for "receiver R has fact F, valid until boundary B"** (#9254 | ||
| phase 1). Codegen carries sixteen receiver-keyed fact tables on `FnCtx` — | ||
| `cached_lengths`, `bounded_index_pairs`, `packed_f64_loop_facts`, | ||
| `masked_window_array_facts`, `buffer_view_slots`, `int_range_facts` and ten more. | ||
| Each answers the same two questions (what do we know about this receiver, and how | ||
| long may we believe it), and each answers the second one differently: a | ||
| `retain(|f| f.scope_id != id)` at scope exit, an insert/remove pair with no | ||
| identifier, a mutable field downgraded in place and never removed, or a reload at | ||
| the safepoint instead of an invalidation. | ||
|
|
||
| A fifth boundary — the **unwind edge** — is expressed by none of them. `lower_try` | ||
| clears no fact table. Unwind safety is obtained today by six unrelated means: the | ||
| packed matcher rejecting `Stmt::Try` outright, a body shape that cannot contain | ||
| one, a post-hoc `contains_gc_unsafe_call` scan, a single `try_depth == 0` gate in | ||
| `versioned_indexed_loop`, a dirty bit stored before every call, and a storage kind | ||
| that simply never moves. Every one is a local decision by one tier, and a tier | ||
| added tomorrow inherits none of them. | ||
|
|
||
| This adds the model — `RegionEnder` (what ends a no-relocation region), | ||
| `FactBoundary` (how a table expresses extent), `ReceiverClaim` (value vs | ||
| representation vs address, the axis that decides whether a boundary is | ||
| load-bearing at all) and `boundary_admits`, the algebra in one place. **It emits | ||
| no IR and no lowering path consults it**; the `#![allow(dead_code)]` at the top of | ||
| the module is the marker for that, matching the #854 subgraphs in `hir_facts`, and | ||
| the whole thing is revertible by deleting the file. | ||
|
|
||
| The load-bearing artifact is the equivalence lint, which holds the model against | ||
| `loop_purity::loop_may_allocate` — shipping and audited — on a shared battery, | ||
| asserting the direction with teeth: *if the model finds no relocation point, then | ||
| `loop_may_allocate` must also have proven the body alloc-free.* The converse is | ||
| deliberately not asserted, since `loop_may_allocate` answers `true` for any | ||
| statement it does not model (`Return`, `Switch`), which is imprecision rather than | ||
| a collection point. | ||
|
|
||
| That lint paid for itself before this landed. Written the obvious way — enumerate | ||
| the enders, default to safe — the model passed every hand-written test and failed | ||
| the battery on three entries: a generic `IndexGet`/`PropertyGet` can reach an | ||
| accessor or a proxy trap, `Expr::Closure` allocates, and `is_inert` belongs on the | ||
| whole coercing node rather than per operand (the #6975 hole one abstraction up). | ||
| Inverting the match to an allowlist with an `Unmodelled` catch-all closes that | ||
| class: adding an HIR variant can no longer silently widen a region. | ||
|
|
||
| Note one deliberate divergence from `collectors::safepoint_sites`, which does not | ||
| count property reads — over-counting reads would over-spill a read-heavy loop, and | ||
| its consumer only needs a spill estimate. A region model has the opposite | ||
| obligation: missing one licenses a stale cached address. | ||
|
|
||
| All sixteen tables are also transcribed as test data with their declaration sites, | ||
| pinning the exact set whose unwind safety is *external to its stated boundary*: | ||
| `stable_packed_loop_facts` (emergent — `stmt_flags` has a `_ => {}` arm, so | ||
| `Stmt::Try` is invisible to its admission scan) plus the three immutable-fact | ||
| tables that lean on non-movable storage. A flag there is not a bug report; it says | ||
| the safety comes from somewhere the boundary vocabulary cannot express, which is | ||
| what phase 2 has to fix, and pinning the set is how phase 2 proves it closed one. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the rollback statement.
Deleting
receiver_regions.rsalone leavesmod receiver_regions;incrates/perry-codegen/src/collectors/mod.rs, Line [46], and causes compilation to fail. State that the module declaration must also be removed, or remove this claim.Proposed wording
📝 Committable suggestion
🤖 Prompt for AI Agents