Repository navigation
D111: a str is a value (counted buffers, holds, last use moves) - #2275
Merged
Merged
Conversation
added 30 commits
October 8, 2026 08:53
…consumer reads it
…ized str is a statement temp
A Copy subject with drop glue (str, Option[str]) took the bit-copy path: copied into a temp whose owner's drop was then cancelled (a regex match on a str local leaked it, validate-ownership). Only bit-copy subjects skip observation now. Over an observed subject a Copy binding (payload, whole subject, slice element) reads by copy with its own hold instead of moving the part out and blanking it (a later match on the subject read empty). The observed let-else lowers its failing path before the bindings, as the consuming path does (#1365): a str binding's drop reached the else path.
classify_cast_ownership met a Copy target with a copy (D22 §6.2). With str Copy under D111, `n as str` for `n: &Name` became an owned temporary, and `fn name_text(n: &Name) -> &str: n as str` (behav_1810) was refused as a view of a temporary. Only a bit-copy target converts at the cast now; a str stays the reference until an owned demand copies it.
A &str element passed to `s: str` double-freed: the contextual-copy materialization minted a fresh buffer as a statement temp that a consuming Copy argument never cancelled, and the auto-deref/contextual-copy argument paths returned before the consume step, so a plain pointee copy took no hold. The str materializes as every Copy value does (a pointee copy), the early argument paths consume into an owning parameter (call_param_borrows, one owner for the share-place decision), and a D87 implicit fill of a str takes its hold. A generic parameter already bound to a Copy X (a BTreeMap[str, V] receiver's K) meets a &X argument with a copy instead of refusing the inference.
…one() D22 §6.2 binds an unannotated let to the view; an owned demand copies a Copy value. The diagnostic told an i32 or (D111) a str to write `.clone()`; it now names the annotation that copies it.
…s copy per element The behavior corpus found four classes on the D111 stack: - MIR's element-view test for Vec/map iteration became "not plain bits", while Sema binds a view only for an element with drop glue. A plain struct (no Copy, no glue) bound by value in Sema and read as a view in MIR: a field read GEP'd into the pointer slot and LLVM's SROA crashed (behav_iter_view_to_fn, repr_packed_n, 2022, same_named_types). The four sites that were "needs drop and not Copy" are "needs drop". - A contextual copy into a `&T` parameter took a hold: `k.clone()` on a map-key view leaked a count per call. call_param_owns names the owning parameters; `&T` and share-place ones borrow. - `[s; N]` of a str took the one-evaluation fill (N slots, no holds, garbage past 64). §4.3a evaluates the value per element; only a bit copy keeps the single evaluation, and the validator's fill check covers glue types. - Tools: --dump-mir shows a copy's hold (copy+retain, copy+take); the codegen-units path honours WITH_DUMP_LLIR_PRE (it ran SROA before any dump).
check_slice checked its bounds and recorded nothing: `s[at..at + 3]` with `let at = cuts[0]` (a view, D27) reached codegen as the element's address and failed LLVM verification (also on main). A bound is an owned demand for its integer (D22 §6.2); a shared view of a Copy one is copied, as check_range does.
`[s; 65]` with `s: &str` under a `[str; 65]` demand asked whether the spelled value (a `&str`, plain bits) could be bit-copied, took the one-evaluation fill, and put one str in every slot without holds; the typed validator refused it. The array's element type decides.
added 4 commits
October 8, 2026 15:38
- A str field read through its binding (`let p = x.s; seen = p`) moved out of the field and blanked it; a Copy field is read by copy and its consumer takes the hold (behav_view_dead_across_loop_blocks). - A comprehension's element is an owned demand (the collection stores it): a view of a Copy value is copied in. `[s for s in gen()]` collected the generator's yielded `&buf`, which the next resume overwrote (also on main; the explicit loop was already refused). - The tail read of a D60 tail assignment moves the local out, as a plain tail does; it cancelled the local's drop and then read it with a hold (validate-all: a leak). - The comptime mutable-global check ignored that a local shadows the global: a user's `var name` broke std.os's comptime `let name`. - `sub in text` records the D110 signature row for the contains it lowers as (a BUG at run time).
… on a Vec 24 fixtures asserted "use of moved value", a D32 implicit field move, a D52 global move or a D95 discard for a str. D111 makes each of those str spellings valid (a str is copied), so each fixture now spells its rule with a Vec, the nearest non-Copy owner, and says why. The rules themselves are unchanged; the str forms are pinned as valid by the D111 behavior tests.
- move-audit: a str field read in any position copies, so its 24 str cells
expect OK; the Vec cells keep D32.
- bundle-interface: the consuming closure captures a Vec (a str capture is
copied, so that closure may run twice).
- da_str_double_free_reported: `*(&raw const s)` is now a copy with its own
hold; the second holder is made by copying the {ptr, len} words as plain
bits.
- dump_typed_d22_*: the adjustment counts are program-wide, and every
`&str` meeting an owned demand in std is now a contextual Copy
adjustment (41 -> 1599, 13 -> 1571).
- spec_ss13_2_iterator_borrowing passes (known-issue #723 directive
removed; the issue's other three tests stay).
added 3 commits
October 8, 2026 15:57
Consuming closures, D60 tails, D73 assignment views, distinct casts, an element field projection and a let-else reuse each asserted their rule on a str, which D111 copies. Each now spells the rule with a Vec (or a distinct Vec) and says why; the rules are unchanged. A Copy field bound from an element copies, for a str as for an i32 (main accepts the i32 form).
The two D22 phase fixtures pinned the program-wide count, which moves with every edit to the embedded stdlib (D111 made each std `&str` at an owned demand an adjustment: 41 -> 1599; the next layer's std change moved it again). `contextual-copy-adjustments-outside-std` counts those in the program's own sources; the fixtures pin that. Their own counts (29, 1) are what they were before D111 (41 and 13 less std's 12).
with_getenv_str wrapped getenv's pointer as a str. A later setenv rewrote those bytes in place, so a saved value changed under its holder (on main too: `let saved = env(X); set_env(X, ...)` read the new bytes). Under D111 every copy shares the buffer, and the build runner's save-and-restore of WITH_OUT_DIR restored garbage. The value is copied into an owned buffer. Audited every make_str in rt_core: the others wrap a static literal, a fresh allocation, the format buffer handed over, a uniquely held buffer appended in place, or argv (process-lifetime, never rewritten). The allocator reads its settings through rt_getenv, never this function, so the allocation here cannot re-enter it.
Contributor
Author
|
Battery GREEN on the stack top 42c8b5a (seed-driven, |
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.
D111: a str is a value.
with_str_retain/release, in-place append only when unique, keys copied into maps retain.stris Copy with drop glue (copy_is_bitsseparates the two kinds of Copy).--dump-mirshows it (copy+retain,copy+take).&strpassed to an owning parameter double-freed (plain, generic, library map key, implicit fill); iteration over a plain non-Copy struct crashed LLVM (MIR disagreed with Sema's view rule);clone(&self)on a view leaked a count per call;[s; 65]of a str read garbage (§4.3a: evaluated per element unless plain bits); a cast through a reference to str stays a view; slice bounds naming an element (also broken on main).WITH_DUMP_LLIR_PREworks on the codegen-units path; the typed validator's fill check covers glue types; the view-into-temporary diagnostic names the annotation, not.clone(), for a Copy value.&&strjoin).Found by the stack's first battery, fixed here (each with a behavior test):
sub in texthad no D110 row.env()wrapped libc's environment bytes, so a saved value was rewritten by the nextset_env(also on main). It returns an owned copy; every othermake_strin rt was audited.--dump-typedprintscontextual-copy-adjustments-outside-std), which is unchanged by D111. spec_ss13_2 now passes (Spec test spec_ss04_8_unit_elision fails: §4.8 unit elision unimplemented #723 noted).