Skip to content

feat(ts): translate the rest of the cells' and locks' methods - #374

Merged
moq-bot[bot] merged 11 commits into
mainfrom
quest/m2/ts-shared
Nov 1, 2026
Merged

moq-bot[bot] merged 11 commits into
mainfrom
quest/m2/ts-shared

Conversation

@kixelated

@kixelated kixelated commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The last methods of quest/m2/ts-shared.md were refused: Clone, Debug, get_mut, and get_or_try_init of OnceCell and OnceLock, and Clone, get_mut, into_inner, try_borrow, Ref::map, and Ref::clone of RefCell and RwLock. Reproduced first by the new fixture cases, which failed translation with 148 refusals such as unsupported call to std::cell::Ref::<'_, T>::map and `RwLock::get_mut` with a mutable reference to a value JS copies.

Approach

  • One-time cells: get_mut lends the cell itself, already a place of its Option, through rt.optionAsMut where JS copies the value; get_or_try_init is get_or_init whose error leaves the cell empty, before a OnceCell set from within would panic reentrant init; Clone clones what it holds into the same class; Debug writes OnceCell(<uninit>) as std does.
  • RefCell: try_borrow and try_borrow_mut give rt.BorrowError and rt.BorrowMutError, with std's Debug and Display; Clone borrows the cell while cloning, so it panics while mutably borrowed; Ref::clone counts another borrow; Ref::map makes an rt.RefMap, a Ref of the part it lends that counts its borrow in its cell, so refRelease releases the cell's.
  • A clone of a reference to an Arc, a Weak, a waker, or one of these cells is that reference: the std Clone arms now take only an owned receiver. The Arc and Weak arms already counted a strong reference for <&Arc<T>>::clone, as in a generic T: Clone given &Arc.
  • get_mut and into_inner of Mutex, RefCell, and RwLock: the value, or rt.valuePlace of the holder where JS copies it (what Arc::get_mut already did, now shared).
  • Proven by differential tests in the lang fixture against wasm32: new borrows::guards case and extended cells, locks, and rwlocks, with named scripts for every panic (RefCell already mutably borrowed, RefCell already borrowed, reentrant init, one-time initialization may not be performed recursively) and drop timing logged for clones and into_inner.

Model census (ts/moq/model.toml, moq at the pin): 365 refusals before, 363 after. The two removed are moq's Content::drop, Mutex::get_mut of an Option (model/group/content.rs:211 and :216); none added.

Choices made without asking, for review:

  • RwLock has no Clone, try_borrow, Ref::map, or Ref::clone in std; its share of the list is get_mut and into_inner.
  • try_borrow_mut, Mutex::get_mut of a value JS copies, and Mutex::into_inner are included: each is the same refusal as one on the list.

Impact

  • Translator output for the methods above, which were refused before.
  • rt gains RefMap, refMap, refClone, refCellClone, refCellTryBorrow, refCellTryBorrowMut, BorrowError, BorrowMutError and their Debug and Display, valuePlace, onceGetOrTryInit, onceClone, and onceDebug. Additive; no MIGRATE.md entry.
  • The lang fixture enables once_cell_try. The reject fixture drops mutex_number, which now translates.

Alternatives

  • A Ref as { cell, value } everywhere instead of the RefMap subclass: allocates for every borrow to serve the rare map.
  • rt.BorrowError as undefined: an Option<BorrowError> would then need rt.None.

Follow-ups

  • quest/m3/ts-guard-maps.md: RefMut::map, the guards' filter_map and map_split, and an RwLock guard's map. A mapped RefMut lends a place, which RefMap's copy can't be.

Review

mechanical fix by codex / Codex: Merged base and reconciled generated census totals, preserving both sides. (head 44f51fa)

Codex (quest review), gpt-6.1-sol, medium effort, head 7577774: no findings.

Round 1 (head 7107284) findings:

  • ts/src/lower/task.rs: a clone of a &RefCell, &OnceCell, or &OnceLock made a new cell. Fixed, with Arc, Weak, and Waker too, and covered by differential aliasing cases.
  • ts/src/lower/mir/mod.rs:964: boxed scalar aliases removed. Refuted: main's fix(ts): a &mut into a Box is the place holding the box #369 landed after my merge, so the two-dot diff showed it reversed; the PR never touched the file.

Head 85b9d91: review skipped as trivial. It merges main (#369, #376) and regenerates the reject snapshots. The land fixer's merge (44f51fa) failed the batch check because reject/mistyped.txt kept line numbers from before this PR removed the mutex_number case; this head's tree is the regenerated merge 0e77b8f, on which local just ci passed.

🤖 Generated with Claude Code

kixelated and others added 7 commits October 31, 2026 22:21
Quest-Claim: 3c47261cd62fb24a
Clone, Debug, get_mut, and get_or_try_init of OnceCell and OnceLock; Clone,
get_mut, into_inner, try_borrow, try_borrow_mut, Ref::map, and Ref::clone of
RefCell, and get_mut and into_inner of RwLock and Mutex, lending an rt.Place
where JS copies the value. Completes the shared-ownership quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and tree-shake the borrow errors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	ts/fixtures/lang/expected/harness.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	ts/fixtures/lang/expected/core/bool.ts
#	ts/fixtures/lang/expected/core/result.ts
#	ts/fixtures/lang/expected/harness.ts
…hat reference

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Shared ownership in the TypeScript translator feat(ts): translate the rest of the cells' and locks' methods Nov 1, 2026
@kixelated
kixelated marked this pull request as ready for review November 1, 2026 07:03
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

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: 0bc6f9a7-44e8-4943-a365-f520602bb5c1
  • 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 07:04
@moq-bot
moq-bot Bot disabled auto-merge November 1, 2026 07:17
@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

quest land removed this pull request from the queue: Conflicts with the base: ts/fixtures/reject/census.md
.

@moq-bot moq-bot Bot removed the quest:merge label Nov 1, 2026
@moq-bot
moq-bot Bot enabled auto-merge (squash) November 1, 2026 07:20
@moq-bot moq-bot Bot added the quest:merge label Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moq-bot
moq-bot Bot disabled auto-merge November 1, 2026 07:32
@moq-bot moq-bot Bot removed the quest:merge label Nov 1, 2026
@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

quest land removed this pull request from the queue: the batch check failed (exit 101).

    |     ^^^^^

warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
   --> fixtures/task/src/drops.rs:424:2
    |
424 |     drop(counts.entry(counted(20)).or_insert(guard(21)));
    |     ^^^^^----------------------------------------------^
    |          |
    |          argument has type `&mut Guard`
    |
    = note: `#[warn(dropping_references)]` on by default
help: use `let _ = ...` to ignore the expression or result
    |
424 -     drop(counts.entry(counted(20)).or_insert(guard(21)));
424 +     let _ = counts.entry(counted(20)).or_insert(guard(21));
    |

warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
   --> fixtures/task/src/drops.rs:425:2
    |
425 |     drop(counts.entry(counted(22)).or_insert_with(|| guard(22)));
    |     ^^^^^------------------------------------------------------^
    |          |
    |          argument has type `&mut Guard`
    |
help: use `let _ = ...` to ignore the expression or result
    |
425 -     drop(counts.entry(counted(22)).or_insert_with(|| guard(22)));
425 +     let _ = counts.entry(counted(22)).or_insert_with(|| guard(22));
    |

warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
   --> fixtures/task/src/drops.rs:426:2
    |
426 |     drop(counts.entry(counted(20)).and_modify(|_| ()).or_insert(guard(23)));
    |     ^^^^^-----------------------------------------------------------------^
    |          |
    |          argument has type `&mut Guard`
    |
help: use `let _ = ...` to ignore the expression or result
    |
426 -     drop(counts.entry(counted(20)).and_modify(|_| ()).or_insert(guard(23)));
426 +     let _ = counts.entry(counted(20)).and_modify(|_| ()).or_insert(guard(23));
    |

warning: for loop over an `Option`. This is more readably written as an `if let` statement
  --> fixtures/task/src/drops/iters.rs:22:11
   |
22 |     for g in Some(guard(7)) {
   |              ^^^^^^^^^^^^^^
   |
   = note: `#[warn(for_loops_over_fallibles)]` on by default
help: to check pattern in a loop use `while let`
   |
22 -     for g in Some(guard(7)) {
22 +     while let Some(g) = Some(guard(7)) {
   |
help: consider using `if let` to clear intent
   |
22 -     for g in Some(guard(7)) {
22 +     if let Some(g) = Some(guard(7)) {
   |

test crates ... ok
warning: `task-fixture` (lib) generated 12 warnings (run `cargo fix --lib -p task-fixture` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 49.87s
   Compiling share-fixture v0.0.0 (/work/ts/fixtures/share)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 49.38s
   Compiling share-fixture v0.0.0 (/work/ts/fixtures/share)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s
   Compiling share-fixture v0.0.0 (/work/ts/fixtures/share)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.24s
test share ... ok
test task ... ok
test stable_names ... ok
test lang ... ok

failures:

---- reject stdout ----

thread 'reject' (19665) panicked at tests/fixtures.rs:553:5:
the errors differ; rerun with UPDATE_EXPECT=1
- lib.Rows.ts:22:20 doesn't type-check, which is a bug in rust2-ts: error TS2339: Property 'data' does not exist on type 'u8[]'. at fixtures/reject/src/lib.rs:2161:3
- lib.ts:8:47 doesn't type-check, which is a bug in rust2-ts: error TS2740: Type 'ByteVec' is missing the following properties from type 'u8[]': pop, push, concat, join, and 28 more. at fixtures/reject/src/lib.rs:2167:4
+ lib.Rows.ts:22:20 doesn't type-check, which is a bug in rust2-ts: error TS2339: Property 'data' does not exist on type 'u8[]'. at fixtures/reject/src/lib.rs:2154:3
+ lib.ts:8:47 doesn't type-check, which is a bug in rust2-ts: error TS2740: Type 'ByteVec' is missing the following properties from type 'u8[]': pop, push, concat, join, and 28 more. at fixtures/reject/src/lib.rs:2160:4

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    reject

test result: FAILED. 11 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 474.65s

error: test failed, to rerun pass `--test fixtures`
error: recipe `test` failed on line 31 with exit code 101
error: recipe `test` failed on line 42 with exit code 101
error: recipe `ci` failed on line 37 with exit code 101

.

@moq-bot

moq-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

codex / Codex land fixer: This maintainer pick already used its mechanical fi·x attempt. Run /quest-iterate to diagnose the repeated failure, then pick it again.

(written by codex / Codex)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated enabled auto-merge (squash) November 1, 2026 07:45
@moq-bot
moq-bot Bot merged commit 826d56d into main Nov 1, 2026
@moq-bot
moq-bot Bot deleted the quest/m2/ts-shared branch November 1, 2026 09:14
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