Skip to content

#2366: an assignment makes the new value before freeing the old; #2377 (D129): str.find(needle, from = 0) in std.string - #2402

Merged
ehartford merged 2 commits into
mainfrom
s-trim-2366
Oct 14, 2026
Merged

ehartford merged 2 commits into
mainfrom
s-trim-2366

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Two commits, one battery.

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.

Eric Hartford 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.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on 44cd433 (with run tools/battery.w: gate rc=0 wall 1004.6 s, uat rc=0, battery-checks survey green, out/battery/status.txt empty of reds, run rc=0). Stage1-only reds seen at the iterate tier (#2314's warning on behav_c_facade_pending_producer_warns, the 1944 memory limit, child-compiler timeouts) do not reproduce under the release compiler the battery builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant