Skip to content

psi: keep a held reference's loan across an indexed reborrow call - #8603

Merged
Smotto merged 1 commit into
mainfrom
claude/project-thread-ccpacc
Dec 4, 2026
Merged

Smotto merged 1 commit into
mainfrom
claude/project-thread-ccpacc

Conversation

@Smotto

@Smotto Smotto commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Requested by Jarod · project thread

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


Generated by Claude Code

<!-- 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
@Smotto Smotto self-assigned this Dec 4, 2026
@Smotto
Smotto merged commit 46a542b into main Dec 4, 2026
1 check passed
@Smotto
Smotto deleted the claude/project-thread-ccpacc branch December 4, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants