Repository navigation
psi: keep a held reference's loan across an indexed reborrow call - #8603
Merged
Merged
Conversation
<!-- claude-projects-attribution: {"github_login":"Smotto"} -->
_Requested by **Jarod** · [project thread](https://claude.ai/code/project/chan_016sYCuiAKSBqBrH3DwXxBdZ?thread=cmsg_016sYCuiAKSBqBrH3DwXxBdZRaB3dxmSh2NRAsL4XdxaF3)_
The checker refused programs that lend one array element at a runtime index through a held `@mutable` reference, such as `replace(@mutable parent[index], 7)` where `parent` is a local `@mutable [Cell; 2]`. It wrongly treated the call as able to overwrite `parent` itself, so it forgot what `parent` points at and refused with "reference descriptor has no current origin account" or "call reference descriptor has no complete original loan correspondence". This makes all 10 positive programs of `samples/cli/facts/core/write_only_indexed_reborrow` compile; their 9 negative twins still refuse with their expected error.
When a call's argument has no exact descriptor location (an element at a runtime index has none), `mark_opaque_call_occupancy` in `descriptor_results/terminal_flow/calls.rs` marked every descriptor slot of the argument's root place as overwritten. For a borrowed argument the callee can only reach storage at or below the argument's path, so the slots now marked are those inside the longest prefix of that path that does have a location. For `parent[index]` that prefix is `parent`'s referent, so the reference held in `parent` keeps its account while everything inside the referent is still treated as overwritten. Owned arguments keep the old whole-root behavior, because moving a value transfers every loan inside it.
The new test checks both directions: the program above is accepted, and a direct write to `cells` between two reborrows through `parent` is still rejected as a conflicting loan, so the loan `parent` holds stays live.
Gate: RC-SOURCE-SEMANTICS | lending an element at a runtime index through a held mutable reference
Spec: wiki/spec/terminal-psi/loans.md
Proof: new `an_indexed_reborrow_through_a_held_reference_keeps_that_reference` (accept and conflict twin), `mbx test -p lowered-program-to-checked-program --lib tests::ownership` (284 passed), `mbx test -p terminal-semantics --lib descriptor` (171 passed), `write_only_indexed_reborrow` family source-checked (10 positives exit 0, 9 negatives keep their fragments), minimal repro Psi exit 0, clippy terminal-semantics | the full 06 lib run has 5 failures (`discarded_compound_orders_preserve_queries_without_materializing_facts`, two `a_dispatched_payload_*`, `an_upgraded_slice_still_conflicts_with_other_live_views_of_its_window`, `a_named_provider_selection_needs_no_edge_on_its_machine`) that fail identically without this change
Agent: Claude Code | Model: claude-opus-5-5 | Effort: low | Tokens: unavailable in (unavailable cached), unavailable out | Steps: unavailable | Time: unavailable | Steers: 0
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Requested by Jarod · project thread
The checker refused programs that lend one array element at a runtime index through a held
@mutablereference, such asreplace(@mutable parent[index], 7)whereparentis a local@mutable [Cell; 2]. It wrongly treated the call as able to overwriteparentitself, so it forgot whatparentpoints at and refused with "reference descriptor has no current origin account" or "call reference descriptor has no complete original loan correspondence". This makes all 10 positive programs ofsamples/cli/facts/core/write_only_indexed_reborrowcompile; their 9 negative twins still refuse with their expected error.When a call's argument has no exact descriptor location (an element at a runtime index has none),
mark_opaque_call_occupancyindescriptor_results/terminal_flow/calls.rsmarked every descriptor slot of the argument's root place as overwritten. For a borrowed argument the callee can only reach storage at or below the argument's path, so the slots now marked are those inside the longest prefix of that path that does have a location. Forparent[index]that prefix isparent's referent, so the reference held inparentkeeps its account while everything inside the referent is still treated as overwritten. Owned arguments keep the old whole-root behavior, because moving a value transfers every loan inside it.The new test checks both directions: the program above is accepted, and a direct write to
cellsbetween two reborrows throughparentis still rejected as a conflicting loan, so the loanparentholds stays live.Gate: RC-SOURCE-SEMANTICS | lending an element at a runtime index through a held mutable reference
Spec: wiki/spec/terminal-psi/loans.md
Proof: new
an_indexed_reborrow_through_a_held_reference_keeps_that_reference(accept and conflict twin),mbx test -p lowered-program-to-checked-program --lib tests::ownership(284 passed),mbx test -p terminal-semantics --lib descriptor(171 passed),write_only_indexed_reborrowfamily source-checked (10 positives exit 0, 9 negatives keep their fragments), minimal repro Psi exit 0, clippy terminal-semantics | the full 06 lib run has 5 failures (discarded_compound_orders_preserve_queries_without_materializing_facts, twoa_dispatched_payload_*,an_upgraded_slice_still_conflicts_with_other_live_views_of_its_window,a_named_provider_selection_needs_no_edge_on_its_machine) that fail identically without this changeAgent: Claude Code | Model: claude-opus-5-5 | Effort: low | Tokens: unavailable in (unavailable cached), unavailable out | Steps: unavailable | Time: unavailable | Steers: 0
Generated by Claude Code