Skip to content

feat(ts): translate the rest of a guard's maps - #384

Merged
moq-bot[bot] merged 6 commits into
mainfrom
quest/m3/ts-guard-maps
Nov 1, 2026
Merged

moq-bot[bot] merged 6 commits into
mainfrom
quest/m3/ts-guard-maps

Conversation

@kixelated

@kixelated kixelated commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts refused RefMut::map, Ref::filter_map, Ref::map_split, RefMut::filter_map, RefMut::map_split, and the map/filter_map of an RwLock's guards (and of the MappedRwLock*Guards they make). #374 landed only Ref::map. Completes quest/m3/ts-guard-maps.md.

Approach

  • One lowering, guard_map in ts/src/lower/task.rs, for both shared and exclusive guards. It calls the map's function on what the guard lends (an exclusive guard of a value JS copies lends rt.valuePlace(guard)), then hands each part to the runtime as the guard should hold it.
  • rt.RefMap is now the single mapped-guard class. It holds the part's rt.Place and its cell, and reads and writes the part through value, as a cell does its own value. So every existing write path through a guard (guard.value = ... from DerefMut) reaches the cell, never a copy:
    • a part JS copies (number, String, Option) is the rt.Place the closure already returns;
    • an object part (Vec, a struct) is rt.partPlace(obj), which writes a whole value into the object in place, as a write through a &mut to it does (vecAssign or ptrWrite);
    • a [u8; N] part is the byteSliceView of the rt.ByteSlice its reference is. This also fixes Ref::map to a [u8; N], which feat(ts): translate the rest of the cells' and locks' methods #374 left emitting output tsc rejected.
  • Split guards share the cell's count: map_split adds a shared borrow, or one more exclusive one (std's BorrowRefMut::clone). refMutRelease now decrements the exclusive count instead of zeroing it, so the cell frees only as the last part drops.
  • MappedRwLockReadGuard/MappedRwLockWriteGuard map to Std::Ref/Std::RefMut, so they deref, write through, and drop like the guards they come from.
  • A mapped exclusive guard of a sized part JS can't write in place (a closure, a binding's class, another guard) is refused with a span. Otherwise a whole write would silently miss the cell.
  • write_in and erased moved from Fx to Translator so the guard lowering shares the store's rule for what writes in place.

Tests

  • borrows::maps (new, lang differential against native wasm32): writes through mapped guards to a u32, String, Vec, [u8; 4], Option<u16>, and a Drop value. Whole writes drop the old value at the write, and are read back after the guard drops. Also covers maps of maps, filter_map Ok/Err, shared and exclusive map_split with parts dropped in either order, guards of a [u8; 4], and borrow state after each drop. It checks wasm32's panics: RefCell already mutably borrowed and RefCell already borrowed while a mapped, filtered, or split guard holds the cell.
  • locks::mapped (new): RwLockReadGuard/RwLockWriteGuard map/filter_map, and the mapped guards' own map/filter_map, with lock state through try_read/try_write.
  • reject fixture: mapped_closure, the new refusal.
  • just ci passes locally.

Impact

  • Translator output: these calls now translate instead of being refused. Ref::map's output changes shape (rt.refMap(guard, part)), and a mapped Ref is an rt.RefMap holding a place.
  • Runtime: refMap now takes the part rather than the function; new refFilterMap, refMapSplit, refMutMap, refMutFilterMap, refMutMapSplit, partPlace; RefMap no longer extends RefCell but implements it. The runtime ships with the output, so there is no MIGRATE.md entry.
  • New refusal: a mapped exclusive guard of a sized part JS can't write in place.

Alternatives

  • Leave a mapped RefMut of an object holding the object, and lower whole writes through every RefMut in place. Rejected: a whole write through an unmapped guard of a binding's class works today and would regress.
  • Keep the runtime calling the function, with the translator passing adapters for place or object inputs and outputs. Rejected: four or more variants per method, against one call site that computes the parts.

Follow-ups

  • quest/m3/ts-guard-rest.md: Debug of RefCell/RwLock guards (refused today), MutexGuard::map, and the guards' unstable try_map.
  • quest/m3/ts-abort-differential.md: wasm32's RwLock locked again while held is an rtabort! with no panic message, which the differential can't compare with the runtime's rt.Panic("rwlock locked for ..."). So locks::mapped checks lock state through try_read/try_write instead. The gap predates this PR.

Review

  • Reviewer: Codex (quest review), gpt-6.1-sol, medium effort.
  • Round 1, head 2b4d8fa: no findings.
  • Round 2, head 0842d57, after merging origin/main: no findings.

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 6 commits November 1, 2026 02:18
Quest-Claim: 1d3f1f04f27d5fe2
RefMut::map, Ref and RefMut's filter_map and map_split, and the map and
filter_map of an RwLock's guards, mapped or not. A mapped guard is an
rt.RefMap of where its part is: a write through a mapped RefMut reaches
the cell, through the part's rt.Place where JS copies it, or into the
object in place. Split guards share the cell's borrow until the last
drops. A mapped guard of a sized part JS can't write in place is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lowering for both guards

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	ts/fixtures/lang/expected/harness.ts
#	ts/fixtures/lang/expected/lib.ts
#	ts/src/lower/mir/call.rs
@kixelated kixelated changed the title The rest of a guard's maps feat(ts): translate the rest of a guard's maps Nov 1, 2026
@kixelated
kixelated marked this pull request as ready for review November 1, 2026 12:07
@coderabbitai

coderabbitai Bot commented Nov 1, 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 16 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: ca464d75-2816-4474-88b3-e743f43aa5a1
Commits

Reviewing files that changed from the base of the PR and between a55d312 and 0842d57.

Files selected for processing: 31
  • quest/m3/README.md
  • quest/m3/ts-abort-differential.md
  • quest/m3/ts-guard-maps.md
  • quest/m3/ts-guard-rest.md
  • ts/README.md
  • ts/fixtures/lang/caller.ts
  • ts/fixtures/lang/expected/atomics.ts
  • ts/fixtures/lang/expected/borrows.Parts.ts
  • ts/fixtures/lang/expected/borrows.ts
  • ts/fixtures/lang/expected/core/bool.ts
  • 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/expected/lib.ts
  • ts/fixtures/lang/expected/locks.ts
  • ts/fixtures/lang/expected/shapes.ts
  • ts/fixtures/lang/src/borrows.rs
  • ts/fixtures/lang/src/harness.rs
  • ts/fixtures/lang/src/lib.rs
  • ts/fixtures/lang/src/locks.rs
  • ts/fixtures/reject/census.md
  • ts/fixtures/reject/expected.txt
  • ts/fixtures/reject/src/lib.rs
  • ts/fixtures/reject/ts.toml
  • ts/runtime/rt/task.ts
  • ts/src/lower/library.rs
  • ts/src/lower/mir/call.rs
  • ts/src/lower/mir/place.rs
  • ts/src/lower/mod.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

@kixelated
kixelated enabled auto-merge (squash) November 1, 2026 12:07
@moq-bot
moq-bot Bot merged commit 5df52d6 into main Nov 1, 2026
1 check passed
@moq-bot
moq-bot Bot deleted the quest/m3/ts-guard-maps branch November 1, 2026 12:26
kixelated added a commit that referenced this pull request Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moq-bot Bot pushed a commit that referenced this pull request Nov 1, 2026
* chore(quest): claim quest/m2/ts-byte-views/README.md

Quest-Claim: 00e3717952d0d17a

* perf(ts): return a Result of numbers alone in a slot

A function only translated code calls that returns a Result of numbers
alone, such as Decoder::varint's Result<u64, E> or a Result<(i64, u64), E>,
now hands back through #160's slot: it returns the first number, or
undefined with the error in the slot, and writes any other numbers there.
A local with no slice is held as its parts only where it meets a slot, and
a tuple made where its parts are taken apart is never made.

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

* chore(ts): update results' snapshot for #381's merge

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

* chore(ts): regenerate core/result.ts's snapshot for #384's merge

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

---------

Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: quest fixer <quest-fixer@localhost>
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