Skip to content

feat(ts): translate Arc and Rc of dyn Iterator, and dyn FusedIterator - #478

Merged
kixelated merged 5 commits into
mainfrom
ts-dyn-iter-arc
Nov 3, 2026
Merged

kixelated merged 5 commits into
mainfrom
ts-dyn-iter-arc

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Problem

Since #437, a dyn Iterator, dyn DoubleEndedIterator, or dyn ExactSizeIterator translates behind &, &mut, and Box. Several forms were still refused:

  • An Arc, Rc, or Weak of one, refused as "a trait object of another crate's trait".
  • Arc::get_mut of one, an "unsupported call".
  • A dyn FusedIterator behind any pointer.

The trait objects quest names Arc<dyn Iterator> and dyn FusedIterator. moq builds neither; this is std coverage the quest calls for.

Approach

  • dyn FusedIterator joins the family: an rt.Iter, made by rt.iterDyn as the others are. Its vtable is Iterator's.
  • An Arc or Rc unsized to one of these is an rt.ArcDyn over rt.iterDyn of the iterator the Arc holds, built as dyn Future's is. A Weak coerced to one, and Arc::from(Box<dyn Iterator>), follow from #450. The last Arc drops the iterator, and so the items it still owns.
  • Arc::get_mut and Rc::get_mut of a trait object lend its object while no other Arc or Weak shares it, as they do for a sized value. This covers the crate's own traits too.
    • A dyn Any's stays refused. Its object may hold a copy of a value JS copies, and Arc::downcast gives back the Arc<T>, which would not see a write made through get_mut.

Also, as the maintainer decided, quest/m3/ts-refcell-debug.md now covers Debug of a Cell too.

Tests: dyns::iters in the lang fixture's differential test against native wasm32 now also covers:

  • Fused: through &mut dyn FusedIterator, a fuse of the crate's own iterator that resumes after its end, a Box<dyn FusedIterator> of the crate's own fused iterator, and the resuming one unfused, through dyn Iterator, for contrast.
  • An Arc<dyn Iterator<Item = Tagged>> made from an Arc<vec::IntoIter<_>>:
    • size_hint through a clone, and get_mut refused while a clone or a Weak shares it.
    • next through get_mut once they drop, dropping that item.
    • The rest of the items, which drop with the last Arc.
  • An Rc<dyn ExactSizeIterator> and its upcast to Rc<dyn Iterator>: len, get_mut refused while shared, then next and size_hint.
  • Arc::from(Box<dyn Iterator>) of the crate's own iterator, read by get_mut and then dropped.
  • A Weak coerced from an Rc<Countdown>, upgraded before and after it drops.
  • Pin<Box<dyn Iterator + Unpin>>, read and dropped.

Census at the moq pin, before → after: unchanged (542 / 86 / 70 for moq-net / model / kio), since moq builds none of these.

Impact

  • The translator's output: these trait objects translate instead of failing.
  • No breaking change.

Alternatives

  • Arc::get_mut of dyn Iterator alone: it is the same mapping for every trait object, so limiting it would leave the crate's own traits refused for no reason. Only dyn Any's has a way back to the concrete value.

Follow-ups

  • quest/m3/ts-dyn.md now holds only dyn Error's downcasts, resized from [L] to [M]. Its goal no longer names &mut dyn Debug, which landed in #453.
  • Arc::get_mut of a dyn Any stays refused, as above.

Review

Codex gpt-6.1-sol at medium effort, via quest review, round 2 on head 95458959956d7ccc24a98e47e65b39144422a197: no findings.

Round 1 (head 402db123) reported one finding, refuted: callback ownership in ffi/src/dart.rs, which is #472's code. #472 landed on main during the round and is outside this branch's diff.

🤖 Generated with Claude Code

kixelated and others added 3 commits November 2, 2026 19:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 59 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: 2c2c610c-6143-4d22-a6c7-154dd9d07647
Commits

Reviewing files that changed from the base of the PR and between 070208c and cf0607f.

Files selected for processing: 11
  • quest/m3/README.md
  • quest/m3/ts-dyn.md
  • quest/m3/ts-refcell-debug.md
  • ts/README.md
  • ts/fixtures/lang/expected/core/option.ts
  • ts/fixtures/lang/expected/dyns.Resuming.ts
  • ts/fixtures/lang/expected/dyns.ts
  • ts/fixtures/lang/src/dyns.rs
  • ts/src/lower/iter.rs
  • ts/src/lower/mir/rvalue.rs
  • ts/src/lower/task.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.

@kixelated
kixelated enabled auto-merge November 3, 2026 04:04
@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 7f3b112 Nov 3, 2026
3 checks passed
@kixelated
kixelated deleted the ts-dyn-iter-arc branch November 3, 2026 04:22
kixelated added a commit that referenced this pull request Nov 3, 2026
#478's `dyns` cases regenerate in the `dyns` fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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