Conversation
Slice index reconstruction replaced the indexed place only in the bounds check's target block, but MIR can use it again in a later block of the same expression: the inner bounds check of `grid[i][j]` re-reads `grid[i]` in its own target, and with overflow checks `s[i] += 1` writes `s[i]` in the target of the overflow assert. The untouched `(*slice)[index]` place then reached `Path::from` or `elaborate_place_for_borrow` and panicked, and the read-only first use selected `Index::index` even though the expression writes. Follow the blocks entered only from the target, up to the next bounds check on the same slice and index, rewrite the indexed place in all of them, and select `IndexMut::index_mut` when any of those uses mutates. A bounds check whose length is read through the indexed place (the inner check of `grid[i][i]`) does not end the expression. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019sxU2nknAtpn8CJu7xZeQt
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
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.
Fixes #322.
Slice index reconstruction used to rewrite the indexed place
(*slice)[index]only in the bounds check's target block. MIR also uses that place in later blocks of the same expression:grid[i][j]re-readsgrid[i]in its own target;-C overflow-checks=on,s[i] += 1writess[i]in the target of the overflow assert.The leftover
Indexprojection then panicked inPath::from/elaborate_place_for_borrow. In the+=case, the only use the pass saw was the read, so it choseIndex::indexeven though the expression writes.Changes
blocks_using_indexed_placefollows the blocks entered only from the target (the same single-predecessor condition the pass already asserts for the target). It stops at the next bounds check on the same slice and index, because that check starts a separate indexing expression; atopt-level >= 1GVN reuses the index local across statements.checks_slice_withinkeeps the inner check ofgrid[i][i]from counting as that stopping point: the inner check uses the same index local, but its length is read through the indexed place.IndexedPlaceFindernow ORs the mutability over every use of the found place, andreplace_indexed_placerewrites all of the access's blocks.Tests
slice_index_nested(pass/fail):grid[i][i]on&[&[i64]]. This is the nested case and the same-index-local stop rule.slice_index_add_assign_overflow_checked(pass/fail):s[i] += 1with-C overflow-checks=on. This checks that uses are rewritten across the overflow assert and thatindex_mutis selected.cargo testpasses locally (396 UI tests plus unit tests) with Z3 5.0.0 and the pinned PCSat wrapper.cargo fmt --checkandcargo clippy --all-targetsare clean.Remaining limitation (not touched here):
grid[i][j] = 0on&mut [&mut [i64]]no longer panics, but a caller that reads the row back afterwards is still rejected. The rows are&mutstored in aSeq, whose prophecy is never resolved (#202).🤖 Generated with Claude Code
https://claude.ai/code/session_019sxU2nknAtpn8CJu7xZeQt
Generated by Claude Code