Repository navigation
Keep a ChainedVector consistent when deleteat! throws - #140
Open
quinnj-bot[bot] wants to merge 2 commits into
Open
quinnj-bot[bot] wants to merge 2 commits into
quinnj-bot[bot] wants to merge 2 commits into
Conversation
Fails on main; passes with the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
deleteat!(x, inds) shrinks one chunk at a time and recomputed the chunk offsets only after the last index. An out-of-bounds or unsorted index threw before that step, leaving offsets that point past the end of the shortened chunks. Recompute them with setinds! in a finally block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
A
ChainedVectorshould stay usable after an operation throws, as aVectordoes.deleteat!(x, inds)deletes from one chunk at a time and recomputed its chunk offsets only at the end. When a later index was out of bounds or out of order, the error skipped that step.xkept its old length while its chunks were shorter, so later reads went past the end of a chunk. With bounds checks off, those reads return unrelated memory.What changed
deleteat!(x, inds)recomputes the chunk offsets in afinallyblock, with the samesetinds!helper the constructor uses, soxmatches its chunks whether or not an index throws.Scope
xconsistent. It does not undo deletions made before the error, soxends with those elements removed.Vectordoesn't undo a faileddeleteat!either: it keeps its length but can be left with shifted, duplicated elements (deleteat!([1, 2, 3, 4, 5], [1, 4, 3])leaves[2, 3, 3, 4, 5]).Blast radius
Successful calls do the same work as before. The diff re-indents the loop inside
try.Verification
mainand passes on this branch (Julia 1.12.6).setinds!is the helper the constructor uses, and it does what the removed reset loop did: drop empty chunks, then recompute offsets.ChainedVector,SentinelVector, andMissingVector, compared withVector) reports this mismatch onmainand not with the fixes applied.🤖 Generated with Claude Code