Skip to content

feat(ts): translate Arc's get_mut, make_mut, and pin, and as_deref of an Option<Arc> - #238

Merged
kixelated merged 6 commits into
mainfrom
quest/m3/ts-arc-mut
Oct 30, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/m3/ts-arc-mut

Conversation

@kixelated

@kixelated kixelated commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Arc::get_mut, Arc::make_mut, Arc::pin, and Option::as_deref of an Option<Arc> were refused, for Rc too (quest/m3/ts-arc-mut.md). as_deref failed for a broader reason: the translator took a callee's signature unnormalized in 15 places. So a function item such as <Arc<u8> as Deref>::deref passed as a value kept <Arc<u8> as Deref>::Target as an unresolved projection.

Approach

  • get_mut: rt.arcGetMut gives the value while strong === 1 && weak === 0, as std's is_unique does. A value JS copies gets an rt.Place over the Arc's value instead (arcGetMutPlace), following localKeyWithBorrowMut's split.
  • make_mut: this takes the Arc's rt.Place (added to takes_place), with T's Clone and the Arc's dropper.
    • While another Arc shares the value, it clones the value into a new Arc at the place and drops the old Arc. If the clone released the other owners, that drop is the last one and drops the value.
    • While only Weaks share it, it moves the value to a new Arc and leaves the Weaks dangling (strong count 0).
    • Unsized T is refused.
  • Arc::pin: this is new rt.Arc, since JS erases the pin.
  • Translator::sig: a new helper gives a callee's signature with its projections normalized. All 15 fn_sig(..).instantiate(..).skip_norm_wip() sites use it, including ty() for a function item. This replaces three hand-rolled normalizations.
  • Body::fn_value: this now passes a &mut parameter that std declares, and that is an rt.Place, as what it points at, as call sites' operands do (both use pointer::pointees). So a mapped std function used as a function pointer, such as Arc::get_mut, gets the Arc.
  • std_places: the list of mappings that hand back a place for a value JS copies now includes Arc/Rc get_mut and make_mut.
  • Tests: these are differential tests against native wasm32 in counts.rs (new unique_arcs/unique_rcs, plus new ops in arcs/rcs). They cover:
    • get_mut and make_mut on a byte and on a Drop value with a custom Clone, called directly and through function pointers;
    • every strong and weak count make_mut leaves, including dangling Weaks;
    • a value whose Clone releases the other handles;
    • Arc::pin, and as_deref of an Option<Arc>.

Census on moq (just ts census, main 5318470a vs this branch):

Target Refusals before After
moq-net 1607 1573
model 537 521
kio 153 153

No new refusal kinds. Most of the drop is unresolved projections ("unsupported type", 46 → 26 in moq-net), which Translator::sig fixes.

Impact

  • Output only: these calls now translate. The runtime gains arcGetMut, arcGetMutPlace, arcMakeMut, and arcMakeMutPlace, which only generated code calls. No public API change.

Alternatives

  • Map get_mut to an inline strong === 1 && weak === 0 ? … : undefined. Rejected because it evaluates the receiver twice, and the TS AST has no optional chaining.
  • Normalize only at the FnDef arm and fn_value. Rejected: the other 13 sites share the bug, and three already normalized it in their own ways.

Follow-ups

  • Option::cloned ignores Clone. It lowers through copied, so opt_ref_arc.cloned() takes no count (it later drops one too many), and a custom Clone impl never runs. Found while writing this fixture (it used .map(Arc::clone) instead). It's a silent miscompile on main, so I suggest a quest via /quest-plan.

Review

Round 3: quest review --responses, Codex with gpt-6.1-sol at medium effort, on head 67959e0502634e7ae5d73ccf613b6694bd67147e against origin/main at f78c588f. No findings.

Since round 2:

  • Online finding on 34732656 (thread): function-value wrappers tested the instantiated signature, so Pin::new through a function pointer returned a0.v. Fixed in 015ec2e4.
    • Reproduced first: tsc rejected the u8 returned as a Place<u8>.
    • pointer::pointees now decides from std's declared signature, for call sites and Body::fn_value alike, and fn_value still checks the concrete place.
    • The lang fixture's pin_via covers it.
  • Merged origin/main: the generated harness.ts snapshot conflicted, so I regenerated it.

Round 2, on 34732656, had no findings. Round 1, on 0c480dc2, had two findings, both fixed and reproduced first:

  1. make_mut decremented the replaced Arc without dropping it. Fixed: it now drops through the Arc's dropper.
  2. Arc::get_mut as a function value received the place, not the Arc. Fixed in Body::fn_value.

just check and just test pass on the reviewed head.

Merge of main at af6f0246f71cfe144758dac9157d36b6a6490458: the only conflict was this PR deleting its finished quest file while #249 updated that file's links; resolved by deleting it. Nothing else changed since the reviewed head 67959e05, so this merge is a recorded skip, too trivial to review.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

kixelated and others added 3 commits October 29, 2026 14:33
Quest-Claim: 4bf81eb5cc775de9
… an Option<Arc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…&mut as std's mappings take it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Arc's unique-access functions feat(ts): translate Arc's get_mut, make_mut, and pin, and as_deref of an Option<Arc> Oct 29, 2026
@kixelated
kixelated marked this pull request as ready for review October 29, 2026 22:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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:56:14.806779Z 67959e0 New commits
🔒 Security Review ✅ Completed 2026-10-30T01:57:30.588137Z 67959e0 New commits
ℹ️ 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 3473265.

One P2: function-value argument unwrapping now mistakes a generic by-value parameter instantiated as &mut T for a declared mutable-reference parameter. Pin::new used as a function pointer consequently returns a copied value instead of its Place; see the inline example.

Direction: centralized signature normalization and the Arc/Rc runtime operations are coherent. The custom-Clone last-owner drop correction and get_mut function-value receiver correction are reflected in code and fixtures. Preserve the direct-call distinction between declared references and generic values when applying the latter fix. The separately reported Option::cloned limitation is unchanged, not a new finding here.

Limits: GitHub-only static review of changed code, runtime/lowering surroundings and differential fixtures/generated snapshots. No compiler, TypeScript, wasm differential tests or census executed; reported passing checks were not independently reproduced.

(Written by OpenAI)

Comment thread ts/src/lower/body.rs Resolved
kixelated and others added 2 commits October 29, 2026 18:28
…eclares one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	ts/fixtures/lang/expected/harness.ts

@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 67959e0 against my prior review at 3473265, separating inherited main changes.

Fixed: the function-value generic mutable-reference P2. The shared pointer::pointees helper checks declared parameters rather than instantiated generic values, so Pin::new preserves its Place while Arc::get_mut still receives its pointee. The new function-pointer fixture mutates through the returned pin and reads the original byte; its generated snapshot returns a0, not a0.v.

No new actionable bugs found in this delta. Direction: sharing the existing direct-call rule is simpler and less likely to drift than maintaining a separate function-value heuristic. The make_mut Place exception remains intact.

Verification: GitHub-only static inspection of lowering, helper extraction, relevant generated snapshots and regression coverage, with an independent review pass. No compiler, TypeScript, wasm differential tests or census executed; reported passing checks were not independently reproduced.

# Conflicts:
#	quest/m3/ts-arc-mut.md
@coderabbitai

coderabbitai Bot commented Oct 30, 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: c0848b0a-b77c-4833-b2cf-958af03bba72
Commits

Reviewing files that changed from the base of the PR and between e51ecad and af6f024.

Files selected for processing: 25
  • quest/m3/README.md
  • quest/m3/ts-arc-mut.md
  • ts/README.md
  • ts/fixtures/lang/expected/core/option.ts
  • ts/fixtures/lang/expected/counts.ArcReleasing.ts
  • ts/fixtures/lang/expected/counts.Noisy.ts
  • ts/fixtures/lang/expected/counts.RcReleasing.ts
  • ts/fixtures/lang/expected/counts.ts
  • ts/fixtures/lang/expected/harness.ts
  • ts/fixtures/lang/expected/lib.ts
  • ts/fixtures/lang/expected/objects.ts
  • ts/fixtures/lang/src/counts.rs
  • ts/fixtures/lang/src/harness.rs
  • ts/fixtures/lang/src/objects.rs
  • ts/runtime/rt/task.ts
  • ts/src/lower/bind.rs
  • ts/src/lower/body.rs
  • ts/src/lower/dynamic.rs
  • ts/src/lower/iter.rs
  • ts/src/lower/library.rs
  • ts/src/lower/mir/call.rs
  • ts/src/lower/mod.rs
  • ts/src/lower/pointer.rs
  • ts/src/lower/stock.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

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

@kixelated
kixelated merged commit 1a3ae90 into main Oct 30, 2026
2 checks passed
@kixelated
kixelated deleted the quest/m3/ts-arc-mut branch October 30, 2026 05:28
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