Repository navigation
#2366: an assignment makes the new value before freeing the old; #2377 (D129): str.find(needle, from = 0) in std.string - #2402
Merged
Merged
Conversation
added 2 commits
October 13, 2026 21:15
`s = s.trim()` stored a `&str` view into s's own buffer after the overwrite drop had freed it: five NULs where `alpha` had been, no error, exit 0 (D111 made `str` a value, so the store was `copy+retain view.*` and the retain read a freed block). The same for `trim_start`, `trim_end`, `let v = u.trim(); u = v`, and every `with -p 'line = line.trim()'`. finish_assignment_to_place now takes a copy read through a projection (a deref, a field, an element) into a temp, with its hold, before the drop-before-overwrite, and moves the temp into the place after it. A plain-local copy and a move are unchanged. The fixture shows the four shapes failing on the installed compiler and passing on stage1; the repro under WITH_DEBUG_ALLOC_SCRIBBLE prints `[alpha]` with leak count 0.
…ethod; rfind compares bytes
`find` leaves the compiler: an `impl str` method in lib/std/string.w
with a §9.1a default parameter, written over the `index_of` intrinsic
(D105's rule: a method the stdlib can write is not an intrinsic). `from`
past `len()` finds nothing, a negative `from` is out of range (D71), an
empty needle is found at `from`; `s.find(x, first + 1)` finds the next
occurrence with no cast, since `first` is the isize `find` returned.
Sema no longer maps `find` to STR_FIND (the intrinsic serves only the
pinned seed's lowering of the compiler's own calls), BuiltinSigs drops
the row, and the comptime evaluator takes the D104 user-method path.
`rfind` compared views cut at every byte and panicked inside a
multibyte character on any such haystack ("string slice inside a UTF-8
character"); it compares bytes now.
Decision log D129 records the brief. The #2358 extra-argument fixture
moves to `index_of`, which keeps one argument.
Contributor
Author
|
Battery green on 44cd433 ( |
ehartford
marked this pull request as ready for review
October 14, 2026 05:03
This was referenced Oct 14, 2026
Closed
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.
Two commits, one battery.
s = s.trim()stores freed bytes: the assignment drops the oldsbefore reading the view of it #2366 (memory safety on main):s = s.trim()read a freed buffer.finish_assignment_to_placematerializes a projected copy into a temp before the overwrite drop and moves it in after. Fixturebehav_2366_assign_view_of_self(four shapes, shown failing on the installed compiler).find(needle: &str, from: isize = 0) -> isizebecomes animpl strmethod inlib/std/string.wover theindex_ofintrinsic; Sema drops the STR_FIND mapping and BuiltinSigs its row; the comptime evaluator takes the D104 path.rfindno longer panics inside a multibyte character. Fixturebehav_2377_str_find_from; the ICE:s.find(needle, from)on a str reaches MIR with no declared signature (BUG, exit 134) instead of a diagnostic #2358 extra-argument fixture moves toindex_of.Iterate tier: stage1 corpus (behavior + internals) matches main's stage1 (the only reds are stage1-only on main too: #2314's warning, the 1944 memory limit, child-compiler timeouts); self-check ok; census diff ok. Battery evidence follows.