Skip to content

fix(ts): return std's next from a function other than next as an Option - #258

Merged
kixelated merged 5 commits into
mainfrom
quest/m3/ts-next-return
Oct 30, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m3/ts-next-return

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A function other than an Iterator::next impl that returns it.next() directly emitted the protocol's raw item or rt.DONE instead of the Option its signature declares, so tsc rejected it. Generic or not: first<I: Iterator>(mut it: I), &mut I, &mut slice::Iter, Chars, the crate's own iterators, and a slice iterator made in the function (stepped in place to return i < s.length ? s[i++] : rt.DONE) all hit it. Found by #241, on main.

Approach

find_next_results marks the locals a next assigns that hold the protocol's value unconverted. Its use check walks places, and MIR's return reads _0 as a local, not a place, so a next into the return place always passed. The return place is now never a protocol local, except in a next itself, which already marks it. One condition in ts/src/lower/mir/mod.rs; the range-specific RETURN_PLACE exclusion beside it is now redundant and dropped.

The other Option-returning calls the quest named (next_back, nth, last, Peekable::peek, slice get) already converted when returned directly; the new case proves each against native wasm32.

Differential case iters::returned in the lang fixture: each of those returned from generic and non-generic functions, over u8 items and Option<u8> items (Option<Option<u8>> returns, so None and Some(None) stay apart), through &mut, the crate's own iterators, and iterators made in the function.

Impact

  • Translator output only. A returned next is now rt.iterToOption(it.next()), typed as declared.
  • A slice iterator whose next is returned is no longer stepped in place (it was wrong there). Dropped: that stepping, for this shape only.
  • &mut dyn Iterator's returned next now also refuses at its call (reject fixture, 12:4), as a non-returned call already did; before, the protocol path skipped that refusal. The parameter's refusal was already there.
  • Census at the moq pin: unchanged (moq-net 500, model 153, kio 1509).

Alternatives

  • Teach the use visitor visit_local so return counts as a whole-value move. Same result for this case, more surface; the return place is the only local return reads.
  • Convert at return with rt.iterToOption while keeping the stepped form. Saves an rt.Iter for a rare shape; not worth the extra path.

Follow-ups

Review

  • Reviewer: Codex, gpt-6.1-sol, medium effort (quest review, round 3)
  • Reviewed head: 52bbb5b
  • Findings: none in rounds 1 (61df52a), 2 (b524ab6), or 3 (52bbb5b, a hand-resolved merge of main).

just ci passed locally on 52bbb5b.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

kixelated and others added 4 commits October 30, 2026 00:02
Quest-Claim: cabcf1da3bd9ef9d
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	ts/fixtures/lang/expected/harness.ts
#	ts/fixtures/lang/src/harness.rs
…ts call

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Return a std iterator's next from a generic function fix(ts): return std's next from a function other than next as an Option Oct 30, 2026
@kixelated
kixelated marked this pull request as ready for review October 30, 2026 07:47
# Conflicts:
#	ts/fixtures/lang/expected/harness.ts
#	ts/fixtures/lang/src/harness.rs
#	ts/fixtures/reject/census.md
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 53 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: fed2e6e2-d2d5-454e-9b86-f8eeef0f0ac8
Commits

Reviewing files that changed from the base of the PR and between b524ab6 and 52bbb5b.

Files selected for processing: 12
  • quest/m3/README.md
  • quest/m3/ts-next-return.md
  • quest/m3/ts-option-items.md
  • ts/fixtures/lang/expected/core/option.ts
  • ts/fixtures/lang/expected/core/result.ts
  • ts/fixtures/lang/expected/harness.ts
  • ts/fixtures/lang/expected/iters.ts
  • ts/fixtures/lang/src/harness.rs
  • ts/fixtures/lang/src/iters.rs
  • ts/fixtures/reject/census.md
  • ts/fixtures/reject/expected.txt
  • ts/src/lower/mir/mod.rs

No actionable comments were generated in the recent review.

Recent review info
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: f9fbd919-c6f0-4e79-bd91-f5cd91d282f5
Commits

Reviewing files that changed from the base of the PR and between 931cb8f and b524ab6.

Files selected for processing: 12
  • quest/m3/README.md
  • quest/m3/ts-next-return.md
  • quest/m3/ts-option-items.md
  • ts/fixtures/lang/expected/core/option.ts
  • ts/fixtures/lang/expected/core/result.ts
  • ts/fixtures/lang/expected/harness.ts
  • ts/fixtures/lang/expected/iters.ts
  • ts/fixtures/lang/src/harness.rs
  • ts/fixtures/lang/src/iters.rs
  • ts/fixtures/reject/census.md
  • ts/fixtures/reject/expected.txt
  • ts/src/lower/mir/mod.rs
Files with no reviewable changes: 1
  • quest/m3/ts-next-return.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The changes replace the documented ts-next-return goal with ts-option-items, adjust MIR handling of detected Iterator::next results at the return place, and add an iterator fixture with generated TypeScript expectations. The rejection fixture adds a second unsupported dyn Iterator diagnostic and updates its census counts and spans.

Priority: Normal

Merge Risk: Minimal · previous review b524a

No actionable merge-blocking issue was identified. The change appears mergeable subject to normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the change: a function other than Iterator::next that returns it.next() now yields an Option in the TypeScript output. The summary, the find_next_results change in `ts/src/lowe…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description directly explains the returned-Iterator::next translation fix, the MIR change, related fixture updates, test coverage, and impact. It matches the changeset.
Full details: Title check

Explanation

The title names the change: a function other than Iterator::next that returns it.next() now yields an Option in the TypeScript output. The summary, the find_next_results change in ts/src/lower/mir/mod.rs, and the new iters::returned fixture all match this. The title uses the fix(ts): prefix and is one sentence under 80 characters.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 7 files. (4 skipped: 4 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch quest/m3/ts-next-return
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: b524ab60a739af404c530d5f1bcb237923b4b939.

No actionable bugs found in the inspected changes. Excluding the return place from protocol-local inference sends ordinary returned next() calls through the existing Option conversion, including the distinct nested-Option sentinel. An actual Iterator::next still explicitly marks its return place for the protocol representation.

Direction is sound: this narrow exclusion fixes the boundary without adding another conversion path at return. The differential fixture and snapshots cover generic, borrowed, local and crate-defined iterators; the unsupported nested-item consumers are tracked separately rather than silently treated as supported.

Verification limits: GitHub-only static review of inference, call lowering, iterator conversion and regression fixtures, with an independent pass. No compiler builds, differential tests or census runs were executed; reported checks were not independently verified.

@kixelated
kixelated merged commit 3b74e5f into main Oct 30, 2026
2 checks passed
@kixelated
kixelated deleted the quest/m3/ts-next-return branch October 30, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant