Skip to content

feat(ts): translate a &mut str to a String wherever it is, and to a part of one - #367

Merged
moq-bot[bot] merged 10 commits into
mainfrom
quest/m3/ts-str-places
Nov 1, 2026
Merged

moq-bot[bot] merged 10 commits into
mainfrom
quest/m3/ts-str-places

Conversation

@kixelated

@kixelated kixelated commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

make_ascii_uppercase/make_ascii_lowercase wrote a String only 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:

`std::ops::DerefMut::deref_mut` of a value JS copies, which is no path                          p.1.make_ascii_uppercase()      (tuple)
`std::ops::DerefMut::deref_mut` of a value JS copies, which is no path                          a[1].make_ascii_uppercase()     (array)
`std::ops::DerefMut::deref_mut` of a value JS copies, which is no path                          v[1].make_ascii_uppercase()     (Vec)
`std::ops::IndexMut::index_mut` with a mutable reference to a value JS copies, which its mapping would copy   s[a..b], s[1..], s[..1]
`std::string::String::as_mut_str` with a mutable reference to a value JS copies, which its mapping would copy
`core::str::<impl str>::split_at_mut` with a mutable reference to a value JS copies, which its mapping would copy
`core::str::<impl str>::get_mut` with a mutable reference to a value JS copies, which its mapping would copy
`std::string::String::leak` / `<&mut str as Default>::default` ... which its mapping would copy

Two reads of a &mut str also translated wrong (and failed tsc): String::from(s) / s.into() and s.to_string() returned the rt.Place instead of its text.

Approach

A JS string can't change in place, so a &mut str is an rt.Place<string>:

  • The whole String: DerefMut, as_mut_str, AsMut<str>, and BorrowMut<str> of a String (or AsMut of a str) borrow the receiver's own place, as Cow<str>::to_mut already did (now one same_place helper). That reaches a String in a tuple, an array, a Vec (by index and iter_mut), and an Option.
  • A part: rt.strPart(p, start, end?) is a StrPart place 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 str keeps each char's length, so the range holds.
  • Producers of parts: IndexMut of a str or a String by a..b, a.., ..b, .. (strPart); str::get_mut (strGetMut, None where std's is); split_at_mut (panics as std's slice_error_fail(self, 0, mid) does) and split_at_mut_checked.
  • Fresh places: String::leak and <&mut str as Default>::default are { v }.
  • strSlice now 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):

Function Here
str::make_ascii_uppercase / _lowercase translate, at every place below
<str as IndexMut<Range/RangeFrom/RangeTo/RangeFull>>, same for String translate (strPart)
IndexMut by RangeInclusive / RangeToInclusive refused with a span, as the shared &s[a..=b] is: quest/m3/ts-str-get.md
str::get_mut translates (strGetMut)
str::split_at_mut, split_at_mut_checked translate
String::as_mut_str, DerefMut for String, AsMut<str> for String and str, BorrowMut<str> for String translate (same place)
String::leak, Default for &mut str translate ({ v })
From<&mut str> for String, ToString of a &mut str fixed to read the place's text
str::as_bytes_mut, get_unchecked_mut, slice_mut_unchecked (unsafe) stay refused with a span (reject fixture covers the first two)
str::from_utf8_mut, from_utf8_unchecked_mut (a &mut str over bytes, not a String) stay refused with a span (reject fixture covers the first)
str::as_mut_ptr stays refused (raw pointer into UTF-8)

Tests: new lang case ascii::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 a String in a local, a tuple, an array, a Vec (index, iter_mut, AsMut), and an Option; parts by each range kind; get_mut with Some and None; split_at_mut with both halves written after each other and a split of a part; split_at_mut_checked via BorrowMut; a part of a part through a &mut str parameter; String::from/to_string of parts; leak; Default. The source String is printed after each write. Two mutation checks fail the differential: splicing one unit too far in StrPart's setter, and checking split_at_mut's offset as a start rather than an end (std's panic says "end byte index").

Impact

  • Translator output: the calls above translate where they refused. New runtime functions rt.strPart, rt.strGetMut, rt.strSplitAtMut, rt.strSplitAtMutChecked (the runtime ships with the output; nothing breaks).
  • No Rust public API change.

Alternatives

  • A part as 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 reuses strSlice's check.
  • Recomputing the part's code units from byte offsets on each access: needless, since no safe write through a &mut str changes a char's length, and the unsafe ones that could are refused.

Follow-ups

  • quest/m3/ts-box-places.md: found here, a write through &mut *b of a Box<u32>, Box<String>, or Box<str> emits b.v of a value with no v (pre-existing; tsc rejects it).
  • quest/m3/ts-str-get.md: str::get and inclusive-range indexing of a str, shared and &mut.

Choices made without asking

  • String::leak and Default for &mut str included: each is one line, and both give a &mut str make_ascii_* reaches.
  • get_unchecked_mut stays refused rather than translated as checked indexing, matching str::get_unchecked, which refuses too.
  • Reject fixture: ascii_in_tuple/ascii_part (now translating) are replaced in the same lines by str_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.

Local checks: just ci passed at 10b1e49, 5fd5f32, and 3aad1e1 (same tree as 2a2868f).

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 4 commits October 31, 2026 16:42
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>
@kixelated kixelated changed the title A &mut str to any String feat(ts): translate a &mut str to a String wherever it is, and to a part of one Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 1, 2026 01:14
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d2e874b0-eb6c-4ccd-85d1-99136966ed7d
Commits

Reviewing files that changed from the base of the PR and between 43f05be and 3aad1e1.

Files selected for processing: 17
  • quest/m3/README.md
  • quest/m3/ts-box-places.md
  • quest/m3/ts-str-get.md
  • quest/m3/ts-str-places.md
  • ts/README.md
  • ts/fixtures/lang/caller.ts
  • ts/fixtures/lang/expected/ascii.ts
  • ts/fixtures/lang/expected/harness.ts
  • ts/fixtures/lang/src/ascii.rs
  • ts/fixtures/lang/src/harness.rs
  • ts/fixtures/reject/census.md
  • ts/fixtures/reject/expected.txt
  • ts/fixtures/reject/src/lib.rs
  • ts/fixtures/reject/ts.toml
  • ts/runtime/rt/str.ts
  • ts/src/lower/library.rs
  • ts/src/lower/mir/call.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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
.

@moq-bot
moq-bot Bot enabled auto-merge (squash) November 1, 2026 01:47
@moq-bot moq-bot Bot added the quest:merge label Nov 1, 2026
@moq-bot
moq-bot Bot disabled auto-merge November 1, 2026 01:47
@moq-bot moq-bot Bot removed the quest:merge label Nov 1, 2026
@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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
.

@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

codex / Codex land fixer: This maintainer pick already used its mechanical fi·x attempt. Run /quest-iterate to diagnose the repeated failure, then pick it again.

(written by codex / Codex)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated enabled auto-merge (squash) November 1, 2026 03:47
@moq-bot
moq-bot Bot disabled auto-merge November 1, 2026 03:48
@moq-bot moq-bot Bot removed the quest:merge label Nov 1, 2026
@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/reject/census.md
.

@moq-bot
moq-bot Bot enabled auto-merge (squash) November 1, 2026 04:08
@moq-bot moq-bot Bot added the quest:merge label Nov 1, 2026
@moq-bot
moq-bot Bot disabled auto-merge November 1, 2026 04:08
@moq-bot moq-bot Bot removed the quest:merge label Nov 1, 2026
@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/lang/expected/harness.ts
.

@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

codex / Codex land fixer: This maintainer pick already used its mechanical fi·x attempt. Run /quest-iterate to diagnose the repeated failure, then pick it again.

(written by codex / Codex)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated enabled auto-merge (squash) November 1, 2026 04:29
@moq-bot
moq-bot Bot merged commit f460b68 into main Nov 1, 2026
1 check passed
@moq-bot
moq-bot Bot deleted the quest/m3/ts-str-places branch November 1, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant