Skip to content

quest: plan Option::cloned through Clone - #244

Merged
kixelated merged 1 commit into
mainfrom
quest-plan/ts-option-cloned
Oct 30, 2026
Merged

kixelated merged 1 commit into
mainfrom
quest-plan/ts-option-cloned

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Option::cloned lowers through Translator::copied, which skips Clone. So v.first().cloned() of a Vec<Arc<T>> takes no strong count but later drops one, and a hand-written Clone never runs. The output type-checks, so the miscompile is silent. Found while writing #238's fixture, which uses .map(Arc::clone) instead.

Approach

This plans one quest, quest/m2/ts-option-cloned.md, ranked right after Shared ownership in m2.

  • Fix: cloned maps the payload as Iterator::cloned already does: through the copy shim where Clone only copies, and through Clone::clone otherwise.
  • Same gap elsewhere: clone_copies assumes a Copy type, so Vec<Arc<T>> passes as copying. The quest checks Iterator::cloned for this gap too and fixes every instance.
  • Milestone, m2:
    • moq-net and kio, the first consumers, call Option::cloned on map lookups and handles (for example kio/src/log.rs and moq-net's ietf/subscriber.rs), so translating the model would miscount silently.
    • Not m0, because no consumer runs translated output yet.
    • Not m3, which holds std that no consumer calls.

Impact

  • Quest tree only: no code or public API change.

Alternatives

  • Fold it into Shared ownership. Rejected: that quest owns the runtime's counts, while this bug is a std mapping that also skips hand-written Clone impls on types with no Arc at all.
  • Plan it in m3. Rejected because moq calls it, as above.

Follow-ups

None.

Review

Skipped: this is a quest-only change (one new quest and its link in quest/m2/README.md), with quest check passing on head 1095ca644a3efc88a95078236f956044237134ed.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T01:44:38.185830Z 1095ca6 PR opened
🔒 Security Review ✅ Completed 2026-10-30T01:45:29.439439Z 1095ca6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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 1095ca644a3efc88a95078236f956044237134ed.

No actionable defects found in this plan. The current Option lowering does share copied with cloned, and auditing the iterator/helper path rather than assuming it is correct is warranted. Keeping this std-mapping fix separate from shared-ownership runtime work is a sensible boundary; reuse the common Clone-dispatch logic instead of adding an Arc-only exception.

Nonblocking implementation coverage: include None (no Clone call), a Copy type with a side-effecting hand-written Clone, and nested Vec/derived aggregates checking both counts and independence. Preserve Option sentinel representation and mutable-reference unwrapping when mapping the payload.

Verification: static inspection of the plan and relevant Option/iterator/clone-helper code, independently checked. This PR contains no implementation fix; I did not run differential tests or verify the reported quest check.

@kixelated
kixelated merged commit e8e8862 into main Oct 30, 2026
1 check failed
@kixelated
kixelated deleted the quest-plan/ts-option-cloned branch October 30, 2026 05:29
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