Skip to content

fix(ts): translate the crate's own iterator held as a value, taken by value or by std's &mut self methods - #540

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

kixelated merged 5 commits into
mainfrom
quest/m3/ts-own-iter-value

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A crate's own iterator whose JS value is copied, as an enum's is, failed to type-check when taken by value: toggle.map(f) gave rt.iterFrom the enum's value where its next takes an rt.Place (found by #515). The same held for every by-value use (filter, zip, chain, collect, extend, sum, rev, cycle, IntoIterator of a crate type returning one), and for std's methods taking &mut self (nth, any, find, position), whose mapping got the enum's value, so writes landed in a copy and a value that drops dropped twice. A borrowed one ((&mut toggle).map(f)) also passed the place to its own &self overrides (size_hint, len), which take the value.

Approach

  • into_iter of an owned one moves it into a place of its own, { v: value }; its dropper and its overrides that take self or &self read it.v, and its clone (for cycle and clone) makes a new place.
  • std's Iterator and DoubleEndedIterator methods of such an iterator take the &mut's place (pointer::takes_place), and a std method taking &mut self of the crate's own iterator borrows it, so into_iter gives no dropper and only the overrides std's &mut I forwards. For a struct, this drops the by-value fold, count, and last from what try_fold, rposition, and the like may call (the ends and stock snapshot changes); std's never call them there.
  • New iters::by_value differential case: a fieldless enum with its own size_hint, count, and next_back, an enum holding a value that logs as it drops, and a struct that logs as it drops, through adaptors, consumers, for, extend, cycle, IntoIterator of a crate type, adaptors dropped partway, and std's &mut self methods on a local.
  • Records three std gaps fix(ts): keep a nested Vec's capacity where clone_from writes over it #533 found as quest/m3/ts-std-stragglers.md.

Impact

  • Translator output only: such iterators now translate, by value and through std's &mut self methods. No public API change.

Alternatives

  • A runtime rt.iterFrom variant that knows which Own methods take &mut self: duplicates the trait's signatures in the runtime, where the translator reads them from rustc.

Follow-ups

Consumer: none yet, planned as part of std (m3).

Review

Codex (quest review), gpt-6.1-sol, medium effort, round 1 on head 5d8d8a5 against origin/main f0b2a31: no findings. Head 3c0fc4b adds only a conflict-free merge of origin/main.

🤖 Generated with Claude Code

@kixelated kixelated changed the title An adaptor of the crate's own iterator held as a value fix(ts): translate the crate's own iterator held as a value, taken by value or by std's &mut self methods Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 19:25
@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 24 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: c97cd296-863c-4503-8605-34c1b76e180b
Commits

Reviewing files that changed from the base of the PR and between 7e7e420 and 3c0fc4b.

Files selected for processing: 18
  • quest/m3/README.md
  • quest/m3/ts-own-iter-value.md
  • quest/m3/ts-std-stragglers.md
  • ts/README.md
  • ts/fixtures/lang/ends/expected/ends.ts
  • ts/fixtures/lang/iters/expected/core/option.ts
  • ts/fixtures/lang/iters/expected/iters.Bag.ts
  • ts/fixtures/lang/iters/expected/iters.Logged.ts
  • ts/fixtures/lang/iters/expected/iters.Noted.ts
  • ts/fixtures/lang/iters/expected/iters.Phase.ts
  • ts/fixtures/lang/iters/expected/iters.Ticks.ts
  • ts/fixtures/lang/iters/expected/iters.ts
  • ts/fixtures/lang/iters/expected/lib.ts
  • ts/fixtures/lang/iters/src/iters.rs
  • ts/fixtures/lang/iters/src/lib.rs
  • ts/fixtures/stock/expected/maps.ts
  • ts/src/lower/iter.rs
  • ts/src/lower/pointer.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 fd9ec1e Nov 3, 2026
7 of 8 checks passed
@kixelated
kixelated deleted the quest/m3/ts-own-iter-value branch November 3, 2026 19:31
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