Skip to content

quest: plan a boxed iterator's folds as std's box reads them - #476

Merged
kixelated merged 2 commits into
mainfrom
quest-plan/ts-box-folds
Nov 3, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest-plan/ts-box-folds

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Iterator for Box<I> forwards only next, size_hint, nth, last, next_back, nth_back, len, and is_empty, so std reads every other consumer of a box by next. The translation erases the box and folds what it holds by that iterator's own fold. A differential probe in the lang fixture (on #437's head) shows where that diverges:

  • A boxed Chain of mapped vec::IntoIters matches native across 750k cases for count, fold, for_each, find, position, max_by_key, rev().fold, and skip(1).count(). Chain's folds read and drop in next's order.
  • Box::new(a.map(f).zip(b.map(g)).skip(1)) does not (98 differences): count and fold make and drop the skipped pair whole, as Skip's by-index fold does, while native skips it one side at a time through the zip's nth.

Approach

One quest, quest/m3/ts-box-folds.md [S]: read a Box<I> of a sized iterator, owned or behind a &mut, as rt.iterDyn reads a dyn Iterator, with last forwarded to the iterator's own as std's BoxIter specializes it. m3 because no consumer builds one: moq boxes only dyn Iterator, which #437 already reads this way.

Impact

None: quests only.

Alternatives

  • Do nothing, as the Chain probe matches: the skip of an indexed zip shows that a box's iterator can fold in an order next doesn't.

Follow-ups

None. The probe also met rfold refused for any iterator, which quest/m3/ts-iter-back-folds.md already plans.

Review

  • Codex (quest review), gpt-6.1-sol, medium effort, round 1 on e8af0d9f6aa57800b807ae68d4031bfefc7c81de: no findings.
  • just check passes locally.

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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 5 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: ef13678d-2fd9-4618-8df9-b82a95943d5b
Commits

Reviewing files that changed from the base of the PR and between d9695a7 and 2a0a060.

Files selected for processing: 2
  • quest/m3/README.md
  • quest/m3/ts-box-folds.md
  • 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.

@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 6a557e4 Nov 3, 2026
3 checks passed
@kixelated
kixelated deleted the quest-plan/ts-box-folds branch November 3, 2026 03:42
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