Skip to content

fix(ts): deref a reference to an Arc, a lock, or a pin as the reference - #236

Merged
kixelated merged 6 commits into
mainfrom
fix/ts-pinned-ref-deref
Oct 29, 2026
Merged

kixelated merged 6 commits into
mainfrom
fix/ts-pinned-ref-deref

Conversation

@kixelated

@kixelated kixelated commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Deref of a reference to an Arc, a Mutex, a guard, a RefCell borrow, or a Pin mistranslated:

A local review of #220 found the Pin case. Reproduced against native wasm32 with new lang fixture cases:

  • Arc::strong_count(&*Pin::new(&arc)) and **Pin::new(&arc);
  • generic Deref through a &Pin<Arc<u8>>, a &Arc<u8>, and a &Mutex<u8>, each also through a &mut, and Deref of a Pin<&mut Arc<u8>>.

On main, tsc rejects these, for example p.value.value on a u8. Where the payload is itself an object with such a field, the same output would type-check and read the wrong value.

Approach

  • A Deref whose Self is a reference to one of these types gives back the object the reference points at: the receiver itself, or for a shared deref of a &mut that is an rt.Place (an Arc, pinned or not), the place's v. DerefMut keeps the place.
  • A pin is its pointer, so Pin's Deref derefs that pointer as it would: .value for an Arc, compared without stripping references, and a reference as above.

I checked the other places #220 added that test for std types (needs_place, the DerefMut guard in call.rs, and write_in): none strips references. library.rs's Deref mapping for Vec, String, Box, and Cow matches the type exactly too.

Impact

  • Output only: these derefs now match native. No public API change.

Alternatives

  • Stop self_std from stripping references for every mapping in task.rs. Rejected for now: the other arms, such as Clone, are never reached through a reference, so only Deref needed it.

Follow-ups

None.

Review

Round 1: quest review, Codex with gpt-6.1-sol at medium effort, on head 284252fa43813964380c83bb28e69865e8ec784c against origin/main at aed2b009. No findings.

An advisory online review of 279719e9 then found that a shared Deref of a &mut Arc still returned its rt.Place. Reproduced (tsc rejects .value on Place<Arc<u8>> for through_arc(&mut ..) and through(&mut pinned)) and fixed in 4be01fa7.

Round 2: quest review --responses, same reviewer and session, on head 4be01fa738d15605b001f266f30d60289f1fe679 against origin/main at aed2b009. No findings.

The advisory online review of 4be01fa7 found the same bug for Pin<&mut Arc<T>>. Reproduced (tsc rejects .strong and .value on Place<Arc<u8>>) and fixed in 0ec35c23.

Round 3: quest review --responses, same reviewer and session, on head 0ec35c23027c8a6046c426b563783e184ce1e851 against origin/main at aed2b009. No findings.

Round 4: merged origin/main at a8e75f2e (ffi only), then quest review --responses, same reviewer and session, on head 705551a741e3e6d724d48c522415070e0feb8fff against origin/main at a8e75f2e. No findings.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

kixelated and others added 2 commits October 29, 2026 12:50
…ned Arc

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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-29T21:01:31.854342Z 705551a New commits
🔒 Security Review ✅ Completed 2026-10-29T21:02:42.417669Z 705551a 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: 279719e

One P2 remains in the reference-deref fix: shared Deref of a mutable reference to an Arc still returns its Place wrapper rather than the Arc. See the inline scenario. This is an uncovered case of the existing bug, not a claim of a new regression.

The shared-reference fixtures and exact Pin pointer check otherwise address the extra payload read. Keeping this correction local to Deref is preferable to changing unrelated mappings' reference handling. Extend the differential fixture to mutable-reference inputs and preserve writable aliases separately for DerefMut.

Verification: static lowering, argument/result representation and fixture review, with independent confirmation of the finding. No translator, TypeScript compiler or native/wasm differential tests run; reported reproductions were not independently executed.

(Written by OpenAI)

Comment thread ts/src/lower/task.rs Resolved
A `&mut` to an `Arc`, pinned or not, is an `rt.Place`, so `<&mut Arc as Deref>::deref`
gives the `Arc` the place holds, while `DerefMut` lends the place on.

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

@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: 4be01fa

The previously reported direct mutable-reference case is fixed: the generated through_arc(&mut ...) and through(&mut pinned) helpers now read p.v.value, while shared-reference helpers retain p.value and DerefMut retains the writable place.

One P2 variant of the same underlying issue remains: Pin<&mut Arc> still returns the Place from shared Deref. This is a pin containing a mutable reference, distinct from the newly tested mutable reference to Pin<Arc>. See the inline scenario and extend the differential fixture to this pointer shape.

Verification: static delta, Pin/reference representation, call argument handling and generated-fixture review, with independent confirmation. No translator, TypeScript compilation or native/wasm differential tests run. No unrelated new regression identified.

(Written by OpenAI)

Comment thread ts/src/lower/task.rs Resolved
A pin is its pointer, so `Pin<&mut Arc<T>>`'s shared `Deref` reads the `Arc` out of
the `rt.Place` the reference is.

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

@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: 0ec35c2

The remaining P2 in discussion_r4417548147 is fixed: shared Deref of Pin<&mut Arc> now reads the pointer's Place value, while DerefMut preserves the writable place. The new fixture specifically covers Pin::new(&mut owned); its generated accesses are lent2.v.strong and lent2.v.value. The earlier direct mutable-reference fix remains intact.

No new actionable findings in this delta. Reusing the existing pointee conversion keeps the correction local without changing unrelated reference representations.

Verification: static delta, surrounding representation/helper logic and generated-fixture review, with an independent pass. No translator, TypeScript compilation or native/wasm differential tests run; author-reported execution was not independently reproduced.

(Written by OpenAI)

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