Repository navigation
feat(ts): translate a &mut str to a String wherever it is, and to a part of one - #367
Conversation
Quest-Claim: 1397ae1d553c85e9
…art of one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 35 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. |
|
quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/lang/expected/harness.ts, ts/fixtures/lang/src/harness.rs, ts/fixtures/reject/census.md |
|
quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/lang/expected/harness.ts, ts/fixtures/lang/src/harness.rs |
|
codex / Codex land fixer: (written by codex / Codex) |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/reject/census.md |
|
quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/lang/expected/harness.ts |
|
codex / Codex land fixer: (written by codex / Codex) |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
make_ascii_uppercase/make_ascii_lowercasewrote aStringonly where it was a local, a field, or behind a&mut String. Completes quest/m3/ts-str-places.md. No consumer calls these yet; planned in m3 as part of std.Reproduced before the change, each with its span:
Two reads of a
&mut stralso translated wrong (and failedtsc):String::from(s)/s.into()ands.to_string()returned thert.Placeinstead of its text.Approach
A JS string can't change in place, so a
&mut stris anrt.Place<string>:String:DerefMut,as_mut_str,AsMut<str>, andBorrowMut<str>of aString(orAsMutof astr) borrow the receiver's own place, asCow<str>::to_mutalready did (now onesame_placehelper). That reaches aStringin a tuple, an array, aVec(by index anditer_mut), and anOption.rt.strPart(p, start, end?)is aStrPartplace holding the whole's place and the part's UTF-16 range, checked as&s[a..b]is. Its getter slices the whole; its setter splices a new string in. Every write through a&mut strkeeps each char's length, so the range holds.IndexMutof astror aStringbya..b,a..,..b,..(strPart);str::get_mut(strGetMut,Nonewhere std's is);split_at_mut(panics as std'sslice_error_fail(self, 0, mid)does) andsplit_at_mut_checked.String::leakand<&mut str as Default>::defaultare{ v }.strSlicenow shares its offset check (units/unitsChecked) with the parts.Audit of std's functions taking or giving a
&mut str(nightly-2026-10-15 source):str::make_ascii_uppercase/_lowercase<str as IndexMut<Range/RangeFrom/RangeTo/RangeFull>>, same forStringstrPart)IndexMutbyRangeInclusive/RangeToInclusive&s[a..=b]is: quest/m3/ts-str-get.mdstr::get_mutstrGetMut)str::split_at_mut,split_at_mut_checkedString::as_mut_str,DerefMut for String,AsMut<str>forStringandstr,BorrowMut<str> for StringString::leak,Default for &mut str{ v })From<&mut str> for String,ToStringof a&mut strstr::as_bytes_mut,get_unchecked_mut,slice_mut_unchecked(unsafe)str::from_utf8_mut,from_utf8_unchecked_mut(a&mut strover bytes, not aString)str::as_mut_ptrTests: new
langcaseascii::parts, differential against native wasm32, on"aÉb\u{800}c😀dZ"(1-, 2-, 3- and 4-byte chars between ASCII letters) at every pair of byte offsets 0..=16 (so every boundary, inside each multi-byte char, empty, backwards, and out of range), and on empty text: case changed through&mut strs to aStringin a local, a tuple, an array, aVec(index,iter_mut,AsMut), and anOption; parts by each range kind;get_mutwithSomeandNone;split_at_mutwith both halves written after each other and a split of a part;split_at_mut_checkedviaBorrowMut; a part of a part through a&mut strparameter;String::from/to_stringof parts;leak;Default. The sourceStringis printed after each write. Two mutation checks fail the differential: splicing one unit too far inStrPart's setter, and checkingsplit_at_mut's offset as a start rather than an end (std's panic says "end byte index").Impact
rt.strPart,rt.strGetMut,rt.strSplitAtMut,rt.strSplitAtMutChecked(the runtime ships with the output; nothing breaks).Alternatives
rt.place(get, set)closures built by the translator: the offsets' check and UTF-16 conversion would be inlined at every site. A runtime class is smaller and reusesstrSlice's check.&mut strchanges a char's length, and theunsafeones that could are refused.Follow-ups
&mut *bof aBox<u32>,Box<String>, orBox<str>emitsb.vof a value with nov(pre-existing;tscrejects it).str::getand inclusive-range indexing of astr, shared and&mut.Choices made without asking
String::leakandDefault for &mut strincluded: each is one line, and both give a&mut strmake_ascii_*reaches.get_unchecked_mutstays refused rather than translated as checked indexing, matchingstr::get_unchecked, which refuses too.ascii_in_tuple/ascii_part(now translating) are replaced in the same lines bystr_bytes_mut/str_from_bytes_mut, so no other span moves.Review
mechanical fix by codex / Codex:
Merged base and mechanically reconciled rejection census counts and entries, preserving both sides.(head e6e77c5)mechanical fix by codex / Codex:
Merged base; preserved both fixture case additions and regenerated the combined rejection census.(head 765b0fa)Codex (gpt-6.1-sol, medium) via
quest review; clean at head 10b1e49.Round 1 (head 7593872): no findings.
Round 2 (head 10b1e49, after merging
mainwith hand-resolved fixture conflicts: the harness case list and regenerated snapshots): no findings.Head 5fd5f32: review skipped as trivial. It only merges
main(feat(ts): refuse a borrow through which a callee's pointer outlives its part's replacement #365, fix(ts): lend the byte arrays a reference to an Option's iterator yields #366, feat(ts): translate a crate's own Extend in a tuple #368), keeps both sides' cases in the harness list, and regeneratesexpected/harness.tsandreject/census.md, the same kind of resolution round 2 reviewed clean.Head 3aad1e1: review skipped as trivial. It only merges
main(perf(ts): pass byte slices as their parts, and return Results of them in a slot #160, fix(ts): judge a census's generic writes by the instances it reaches #370) and the quest fixer's merge and regeneratesexpected/harness.ts, the only conflict.Local checks:
just cipassed at 10b1e49, 5fd5f32, and 3aad1e1 (same tree as 2a2868f).(written by Claude Opus 5.5)
🤖 Generated with Claude Code