Repository navigation
Fresh writes through a zip, a copy, and a repeat - #516
Merged
Merged
Conversation
Quest-Claim: cbeace3334d6ce36
…] of a Copy type A type parameter's value read out of what std's code returns holds no pointer but one read through a cast pointer, or a function's parameter of that type. copied and Copied copy rather than run a Copy bound's Clone. vec![x; n] runs the crate's Clone only on its argument. A Copy type of the crate's drops none of its code. The quest keeps a zip whose other half points at a part of the slot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 14:02
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 34 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. CodeRabbit Verify
|
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.
Claims quest/m3/ts-fresh-shapes.md.
Problem
#394 made a whole write into fresh memory count as fresh in a function generic over a type. Three shapes stayed refused ("a raw pointer to ... which the crate may put another object in place of"), for concrete types and type parameters alike:
Zip::next'sSome((slot, x)), counted as holding the pointer that went in, whatever its type.iter().copied()over aCopytype, the crate's or aT: Copy, counted as running the crate'sClone, sinceCopy's supertrait selects a parameter candidate.vec![x; n]does run the crate'sClone,n - 1times, so it was refused whole.A
Copytype of the crate's also counted as dropping the crate's code, though it has no drop glue.Consumer: the
lengthsfixture now, and any crate that fills slots from a zip, acopied, or avec![x; n].Approach
All in
ts/src/lower/mir/holders.rs:Holds:Trace::holderstakes what its root holds in place of abool. A value whose type shows no pointer holds one only if read as a part. Neither std's code nor a body generic overTmakes aTout of a pointer, except by reading one through a pointer cast to point at it, which is a part read.keeps, which asks whether a crate callee generic overTkeeps its parameter, usesHolds::Any, since that parameter may itself be the pointer. The reject fixture's newclones::stashed_slotscovers this: it stays refused, and translates ifkeepsusesHolds::Pointers.copies:inertpasses aCopyclause on std'scopied(ofIterator,Option,Result) and on theCopiedadaptor, which copy and never callclone. It does not trustCopyin general. Std'sExtend<&T>forLinkedList,BinaryHeap,BTreeSetandHashSetcallscloned()under a bareT: Copybound.repeats:vec::from_elem(vec![x; n]) counts as fresh when its element shows no pointer and drops none of the crate's code. It runs the crate'sCloneonly on&x, then movesxinto the vector last, so thatClonenever sees the returned memory, and what it returns holds no pointer std's code could keep.drops_own_code: counts only the crate's types that have drop glue, so a crate'sCopytype no longer counts.Tests:
lengthsgainsrepeated::<T>(generic) andloud(concrete). Both rewrite through raw pointers into the parts of rows made bycopiedandvec![x; n], then read back the source rows, so a write that showed through a shared copy would change the output.LoudisCopywith a hand-writtenClonethat logs, returns a different value than the copy, and panics on0xff.caller.tspins inputs that put0xffin the copied rows (no clone, no panic) and as eachvec!value (panics after logged clones). Each fix is load-bearing: reverting any one makes the fixture refuse.Impact
clones::stashed_slots, a pointer kept by a generic callee as aT.Alternatives
Copycalls nothing, everywhere: unsound, because of theExtend<&T>impls above.Vec's buffer pointer by its element, notUnique<u8>: would fix one of the vector-access refusals, but it's a separate cause and is recorded in the new quest.Follow-ups
zipwith aVec<[T; N]>, or withcopiedof the slot's held type).Trace::freshreads a liveZip's whole type. The quest weighs a parametric mask of std's signatures against a table of adaptors.first_mut/get_mut, a by-value arrayfor, and aVec'sUnique<u8>buffer.Choices made without asking
Review
quest review, Codexgpt-6.1-solat medium effort, round 1 on head 2b3e086 against base dcfa0b2: 0 findings. The head since adds only conflict-free merges of origin/main (#517, #518, #524).just cipassed on 2b3e086 and on the merge head b0f609e.🤖 Generated with Claude Code