Skip to content

feat(ts): translate repeat, repeat_n, once_with, and a hash map's and set's extract_if, with Debug of a B-tree set's operations and the ExtractIfs - #547

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

iter::repeat, repeat_n, and once_with had no mapping, nor did HashMap::extract_if and HashSet::extract_if. Debug of a BTreeSet's set operations and of a list's ExtractIf was refused as an unsupported call. Continues quest/m3/ts-iter-source-debug.md after #542.

Approach

  • rt.iterRepeat, rt.iterRepeatN, rt.iterOnceWith: each item is a clone of the element, except repeat_n's last, which is the element itself. Repeat skips nothing, and its count and last panic with iterator is infinite. RepeatN drops its element when an advance passes the last item, and its own count and last clone nothing. A Take of a Repeat reads from the back as it does from the front, as std's specialization does. once_with's closure is called on the first read from either end; an Fn closure goes through rt.once, as std calls it through FnOnce, and one never called drops with the iterator. drops now sees the element a RepeatN holds inside its private struct.
  • rt.hashExtractIf, hashExtractIfMut (values JS copies, lent as places), and hashExtractKeysIf take out what the closure accepts as they read, in hashIter's order and through collided chains too. They keep what they haven't read and hint (0, unread) as hashbrown's does.
  • Debug: Repeat { element }, RepeatN { count, element }, and OnceWith(Some(_)) (unpadded). A BTreeSet's Difference and Intersection write the way std picked (Stitch, Search, Iterate, Answer), and Union and SymmetricDifference write their MergeIterInner with the key it holds back. To make that state readable, a new Search class replaces both the intersection's iterFilter and the difference's set lookup. A list's ExtractIf writes peek, and a hash map's and set's write ExtractIf { .. }.
  • count and last of an iterator that holds a Repeat or a RepeatN, or flattens one, take the owned path, which reaches their own count and last (as a Cycle already did).
  • Debug of a str's searches (Split and its forms, Matches, MatchIndices, Lines, SplitWhitespace) is now refused with a precise reason. std writes its searcher's state (finger, the Two-Way searcher's crit_pos/period/byteset/memory) in UTF-8 bytes, and the runtime searches in UTF-16 by a Pattern. Matching it means porting std's searchers or replaying them, which can land on its own, so the quest is rewritten to that remainder.

Tests are differential against native Rust: lang/shapes fmt::sources and the new fmt::sets cover Debug fresh, {:#?}, {:x?}, padded, and after reads from either end; lang/clones clones::sources covers clone and drop order, panics, and adaptors; lang/collections collections::extracts covers keys of each kind, colliding keys, and partial reads; reject covers the str refusal.

Impact

  • No public API change: the translator accepts more std, and the runtime's new exports are what generated code calls.

Alternatives

  • Tracking std's UTF-8 searcher state for every str search would cost each plain search something. Measuring that is left to the rewritten quest.

Follow-ups

Review

Codex (quest review), gpt-6.1-sol, medium effort. Round 3 on head 26df0cd: no findings.

  • Round 1, fixed in 3580917: repeat_n(x).chain(empty()).count() of items that clone observably but never drop took iterCount, which folds and clones. count/last of an iterator holding a Repeat or RepeatN now take the owned path, which reaches their own.
  • Round 2, fixed in b631ec1: the same through a Flatten of iterators that a function makes. The type walk now follows the items an iterator yields when they are iterators themselves.

🤖 Generated with Claude Code

kixelated and others added 2 commits November 3, 2026 11:53
… set's extract_if, with Debug of a B-tree set's operations and the ExtractIfs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Debug of std's other iterators feat(ts): translate repeat, repeat_n, once_with, and a hash map's and set's extract_if, with Debug of a B-tree set's operations and the ExtractIfs Nov 3, 2026
kixelated and others added 3 commits November 3, 2026 13:02
…ach their own

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 21:17
@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
Merged via the queue into main with commit 1b0fe64 Nov 3, 2026
6 of 8 checks passed
@kixelated
kixelated deleted the quest/m3/ts-iter-source-debug branch November 3, 2026 21:25
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