Skip to content

feat(ts): translate Debug of std's iterator sources, Option's, Result's, and an array's iterators, and a slice's parts - #542

Merged
kixelated merged 5 commits into
mainfrom
quest/m3/ts-iter-source-debug
Nov 3, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m3/ts-iter-source-debug

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Debug of std's iterator sources and several collection iterators was refused, so an adaptor over one (for example char::decode_utf16([..]), which wraps an array's IntoIter) failed to translate. #515 covered the adaptors; this covers what they wrap.

Approach

Extends iter_debug in ts/src/lower/fmt.rs, which #515's peel_iter-based adaptor Debug already reaches through wrapped. Each new arm writes std's private fields as std's impl does, from the runtime iterator's own state:

  • Once, option::{Iter, IterMut, IntoIter}, and result::{Iter, IterMut, IntoIter}: rt.fmtIterOption, the item left as an Option inside std's wrapper structs (Once { inner: IntoIter { inner: Item { opt } } }). Its item is written as the iterator's item type, so a &mut to a value JS copies is read through its place.
  • FromFn and RepeatWith: their names, without closures, as std writes them. Successors: the item it yields next.
  • An array's IntoIter: the list it has left, as a Vec's.
  • CharIndices: its front offset and Chars. A String's Drain: what it has left.
  • A slice's Windows, Chunks, ChunksExact, RChunks, RChunksExact: rt.fmtParts, what the parts left cover, the remainder, and the size. PartsIter now tracks whether a read past the end emptied it, as std's Windows::nth, nth_back, and next_back set v to [].
  • A slice's Split and its nine forms: rt.fmtSplit, what is left to split and finished, a &mut one emptying its slice as it finishes, and a splitn's GenericSplitN with its count.
  • A HashSet's set operations: the list a clone yields, as std's debug_list().entries(self.clone()).
  • A slice's ChunksMut and its forms are refused at their span: std writes their *mut [T] as an address.

Tested differentially in fmt::sources of the shapes fixture, plain, {:#?}, and {:x?}, fresh, read from either end, and past the end. A reject fixture covers ChunksMut.

Impact

  • New runtime exports: fmtIterOption, fmtIterClone, fmtSuccessors, fmtParts, fmtSplit, fmtCharIndices, fmtStringDrain. No breaking changes.
  • Consumer: moq translates Debug derives over its types; any field or adaptor holding one of these iterators now translates instead of refusing.

Alternatives

  • One generic runtime writer driven by a field list from the driver: rejected, since each kind's state (cleared windows, taken splits, sentinel Nones) is computed differently anyway.

Follow-ups

The quest is rewritten to what remains: str's searcher iterators (Split, Lines, SplitWhitespace, Matches) write CharSearcher and TwoWaySearcher state the runtime does not keep; a BTreeSet's set operations write std's strategy; ExtractIfs write a peeked item; and iter::repeat, repeat_n, and once_with are not translated at all yet.

Review

🤖 Generated with Claude Code

kixelated and others added 5 commits November 3, 2026 10:59
…'s, and an array's iterators, and a slice's parts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ce-debug

# Conflicts:
#	ts/README.md
#	ts/runtime/rt/str.ts
#	ts/src/lower/fmt.rs
@kixelated kixelated changed the title Debug of std's other iterators feat(ts): translate Debug of std's iterator sources, Option's, Result's, and an array's iterators, and a slice's parts Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 19:37
@pullfrog

pullfrog Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

This run was cancelled before it finished.

Pullfrog  | View workflow run | via Pullfrog

@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
@coderabbitai

coderabbitai Bot commented Nov 3, 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 12 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: fccbd0ed-39a3-4214-aafc-a0d615655885
Commits

Reviewing files that changed from the base of the PR and between fd9ec1e and 7a1260b.

Files selected for processing: 17
  • quest/m3/README.md
  • quest/m3/ts-iter-source-debug.md
  • ts/README.md
  • ts/fixtures/lang/shapes/expected/core/bool.ts
  • ts/fixtures/lang/shapes/expected/core/option.ts
  • ts/fixtures/lang/shapes/expected/fmt.ts
  • ts/fixtures/lang/shapes/expected/lib.ts
  • ts/fixtures/lang/shapes/src/fmt.rs
  • ts/fixtures/lang/shapes/src/lib.rs
  • ts/fixtures/reject/census.txt
  • ts/fixtures/reject/expected.txt
  • ts/fixtures/reject/src/fmt.rs
  • ts/fixtures/reject/ts.toml
  • ts/runtime/rt.ts
  • ts/runtime/rt/iter.ts
  • ts/runtime/rt/str.ts
  • ts/src/lower/fmt.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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

Merged via the queue into main with commit aff50d0 Nov 3, 2026
7 of 8 checks passed
@kixelated
kixelated deleted the quest/m3/ts-iter-source-debug branch November 3, 2026 19:48
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