Skip to content

fix(ts): write through DerefMut of a pinned or plain &mut to a value JS copies - #245

Merged
kixelated merged 5 commits into
mainfrom
fix/ts-deref-mut-place
Oct 30, 2026
Merged

kixelated merged 5 commits into
mainfrom
fix/ts-deref-mut-place

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A write through DerefMut of a &mut, or a pin of one, to a value JS copies was wrong:

  • *Pin::new(&mut byte) ^= 0x5a lowered to _210 = _210 ^ 90, which overwrote the rt.Place the pin is instead of writing through its v. tsc rejects it, and the byte never changed.
  • Generic code doing *p ^= by with P = Pin<&mut u8> was wrong the same way.
  • P = &mut u8 was refused (<&mut u8 as DerefMut>::deref_mut was unmapped).

Found while fixing #238's online finding. It is on main and independent of that PR.

Approach

  • mir/call.rs: the DerefMut arm aliases its result as the pointee's path. A &mut, or a pin of one, that is an rt.Place hands back the place itself, so its path is now the place's v. MutexGuard, RefMut, and Pin<Box<Arc>> keep the paths their mappings already give.

  • task.rs: Deref/DerefMut of a reference now maps for any pointee, not just the std types fix(ts): deref a reference to an Arc, a lock, or a pin as the reference #236 listed:

    • deref reads pointee_value;
    • deref_mut lends the reference.

    No other snapshot changed.

  • Fixture: ts/fixtures/lang/src/objects.rs writes a byte through DerefMut of Pin<&mut u8> directly, and through a generic DerefMut with Pin<&mut u8> and &mut u8. It also replaces an Arc through Pin<&mut Arc>, &mut Arc, and a MutexGuard<Arc>, which were already correct and are now pinned by the differential.

Impact

  • Output only: these writes now match native, and <&mut T as DerefMut> translates. No public API change.

Alternatives

  • Make Pin<&mut T>'s deref_mut mapping return the place's v. Rejected: outside the alias arm, the Pin<&mut Arc> path needs the place itself, so only the arm that turns the result into a path knows to read v.

Follow-ups

None. The census was not run for this change.

Review

Round 2: quest review --responses, Codex with gpt-6.1-sol at medium effort, on head 0fee740dd6dbd3cedb428f2090ddcce2d70a2096 against origin/main at cff3177b. No findings.

Since round 1 (on 6902e6b3):

  • Merged origin/main at 7edb4e5b, conflict-free.
  • Snapshot: #241's place fold changed only replaceThrough$Arc_u8 in objects.ts. It drops the const _4 = p alias, and the write stays p.v = _3 into the caller's place. The Pin and guard variants are unchanged.
  • Checks: I regenerated the snapshot, and the lang differential passes. just ci passes on the head.
  • Later main: #252 landed after this merge. A trial merge with it passes the lang fixture with no snapshot change.

Merge of main at 692c17d2aaf819f339f90619be24449fc3ed13e1 (adds #252): git merged it without conflicts, no snapshot changed, and just ci passed on this exact tree; it is a recorded skip, too trivial to review, on top of round 2's clean review of 0fee740d.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

…JS copies

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-30T02:28:42.821385Z 8972349 PR opened
🔒 Security Review ✅ Completed 2026-10-30T02:29:35.688790Z 8972349 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: 8972349

The plain-reference and single-Pin fixes address the right representation boundary, and the Arc/guard fixtures protect replacement and drop behavior. One instance of the same bug remains: nested Pin wrappers still lose the writable .v path (inline P2). This is an incomplete fix of the existing problem, not a newly introduced regression. Prefer resolving the erased pointer representation consistently rather than adding one-wrapper special cases.

Verification: independent static tracing of MIR alias lowering, task mappings, type representation and the changed fixtures. No compiler, differential tests or census run performed; author check claims were not independently verified.

(Written by OpenAI)

Comment thread ts/src/lower/mir/call.rs
});
let place = match lent {
Some(lent) if self.b.t.place_pointee(lent).is_some() => place.member("v"),
_ => place,

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.

[P2] Resolve nested Pin wrappers before choosing the writable path

The new logic peels only one Pin. The existing fixture helper can also be called as write_through(Pin::new(Pin::new(&mut byte)), 1): both Pins erase recursively to rt.Place<u8> and both constructors are identity mappings. However, the outer DerefMut mapping returns that Place, while lent here is still Pin<&mut u8>, for which place_pointee returns None. The alias therefore points at the wrapper itself instead of its .v, so *p ^= by still fails to update byte (and emits the same invalid Place/scalar operation this PR fixes for one Pin). Resolve the nested pointer representation consistently and add this case to the differential fixture.

# Conflicts:
#	ts/fixtures/lang/expected/objects.ts
#	ts/fixtures/lang/src/objects.rs
@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 2 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: fa9c7637-2619-4cff-9396-b0051ef68592
Commits

Reviewing files that changed from the base of the PR and between cff3177 and 692c17d.

Files selected for processing: 4
  • ts/fixtures/lang/expected/objects.ts
  • ts/fixtures/lang/src/objects.rs
  • ts/src/lower/mir/call.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 1ce0b44 into main Oct 30, 2026
2 checks passed
@kixelated
kixelated deleted the fix/ts-deref-mut-place branch October 30, 2026 06:38
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