Skip to content

feat(ts): translate str::chars, char patterns, and String::push - #96

Merged
kixelated merged 5 commits into
mainfrom
quest/m2/ts-str-char
Oct 27, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m2/ts-str-char

Conversation

@kixelated

@kixelated kixelated commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

#86 made char values translate, but the str and String methods over them did not: moq-net's ietf/namespace.rs refused str::chars, split('/'), is_empty, and eight String::push calls, and other modules refused the remaining char-pattern searches and char::is_ascii_digit.

Approach

  • rt/str.ts (new): strChars, a double-ended iterator stepping by code point, and the searches strSplit, strMatchIndices, strStartsWith, strTrimStartMatches, strTrimEndMatches, and strRfind. Each takes an rt.Pattern: the char's text, which indexOf finds, or the predicate itself. The searcher is a port of std's: it keeps a front and a back finger, so mixing next and next_back matches std, and it calls a predicate once per char it reads, in std's order. rfind and match_indices return UTF-8 byte offsets, counted from the code units (a surrogate pair counts as 4 bytes). match_indices keeps a running count from each end, so it stays linear.
  • library.rs: maps those methods, plus str::is_empty, String::is_empty, and char::is_ascii_digit. Any pattern other than a char, a closure, or a fn item stays an unsupported call.
  • mir/call.rs: String::push assigns place + text to whatever the &mut borrows: a local, a field (also through &mut self), or an element. A constant char becomes a string literal. A &mut String parameter is still refused, as other &mut to values JS copies are.
  • Tests: the lang fixture gets a strs case, checked against native and wasm32 builds. Its text uses chars of each UTF-8 width and the ones on either side of the surrogate range and of U+FFFF/U+10000. It mixes next and next_back, logs every char a predicate is called with, and includes namespace.rs's escape/unescape loop. To check the tests catch bugs, I broke utf8Len and, separately, the surrogate stepping in before; the differential failed both times. reject pins the refusals for a &str pattern and for a push through a parameter.

moq-net census at the pinned moq rev, measured on main at 62a8a59:

Refusals ietf/namespace.rs
before 11879 14
after 11828 1

After merging #87, moq-net has 11503 refusals and kio 344 (#87's drops); namespace.rs still has 1. This PR does not change kio (355 before and after on 62a8a59). namespace.rs still refuses <Cow<str> as From<&str>>::from in refusal. That comes from Cow, not from str or char, so I did not fix it here.

Impact

  • Translator output: the calls above translate, where they used to fail.
  • Runtime: new rt/str.ts, re-exported from rt.ts, exporting Pattern, strChars, strSplit, strMatchIndices, strStartsWith, strTrimStartMatches, strTrimEndMatches, and strRfind. rt.ts also gains charIsAsciiDigit.

Alternatives

  • Eager s.split(c) into an array: rejected. It is not lazy, it can't run a predicate in std's order, and it does extra work for split(..).next().
  • Separate functions per pattern kind instead of string | predicate: rejected. That doubles the API to save one typeof check per call.
  • &str patterns (starts_with::<&str> and contains::<&str> in path/mod.rs): left out of scope. An empty &str pattern has its own semantics in split, trim_*, and match_indices.

Follow-ups

  • Cow<str>: 139 moq-net refusals, including the last one in namespace.rs.
  • &str patterns, and str slicing by byte range (&s[..i]). Slicing is what makes the byte offsets from rfind and match_indices useful in discovery.rs and lite/compress.rs.

(written by Opus 5.5)

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

kixelated and others added 3 commits October 26, 2026 18:14
Quest-Claim: 93dc02fbf02063bc
`str::chars`, `split`, `match_indices`, `starts_with`, `trim_start_matches`,
`trim_end_matches`, and `rfind` by a `char` or a predicate, `str::is_empty`,
`char::is_ascii_digit`, and `String::push` through a `&mut String` translate, so
moq-net's `ietf/namespace.rs` refuses only its `Cow`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title str and String methods over char feat(ts): translate str::chars, char patterns, and String::push Oct 27, 2026
@kixelated
kixelated marked this pull request as ready for review October 27, 2026 01:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T02:40:51.342716Z 7349b37 New commits
🔒 Security Review ✅ Completed 2026-10-27T02:43:56.831717Z 7349b37 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)
Reviewed commit: 464c9f1

No actionable bugs found in the changed areas. The shared two-ended searcher is justified over eager splitting: it preserves lazy predicate evaluation and mixed-direction iteration. UTF-8 offset accounting remains separate from UTF-16 traversal, and String::push reuses the existing borrowed-place restrictions rather than pretending JavaScript strings are mutable references. Keeping &str patterns and arbitrary &mut String parameters explicitly unsupported is a reasonable scope boundary.

Reviewed runtime searches, translator mappings/assignment handling, generated snapshots, and differential/refusal fixtures. The Unicode-boundary and predicate-order cases are meaningful coverage. Source review only; I did not run the translator, native/wasm differential tests, or the full suite.

kixelated added a commit that referenced this pull request Oct 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated
kixelated merged commit ed84e93 into main Oct 27, 2026
1 check passed
kixelated added a commit that referenced this pull request Oct 27, 2026
Give #96's strs and this branch's stores their own ops (% 44), and regenerate the harness snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated added a commit that referenced this pull request Oct 27, 2026
Keep both sides' reject cases (copy_within and Arc<[u8]> beside #96's String and str patterns), and regenerate the snapshots over #96's and #99's lowering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated added a commit that referenced this pull request Oct 27, 2026
* chore(quest): default comparison methods and generic instances

Follow-ups from #98 and #94.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* chore(quest): Cow<str> and str slicing from #96

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* chore(quest): share Copy types the crate never changes in place

Replaces ts-shared-read's narrow fix, as #99 suggested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* chore(quest): an A/A control that measures noise

From #87's and #97's bench findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

---------

Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated deleted the quest/m2/ts-str-char branch October 27, 2026 20:32
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