Skip to content

feat(ts): translate Rc and Arc of a slice and of str - #500

Merged
kixelated merged 4 commits into
mainfrom
quest/m3/ts-shared-slices
Nov 3, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m3/ts-shared-slices

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Rc<[T]>, Arc<[T]>, Rc<str>, and Arc<str> were refused almost everywhere: From of a Vec, a slice, a &mut slice, a Box, an array, or a Cow; collect; Default; get_mut and make_mut; and Arc<[u8]>::from(Arc<str>). Only Arc<str> from a string translated. Reproduced with the new lang/shares fixture: 66 refusals on main. Found by #375.

Approach

The quest asked what form a u8 instance takes. An Arc<[T]> is already typed rt.Arc<what [T] is>, so it is an rt.Arc of whatever a Box<[T]> or Box<str> holds. It counts its owners, and its u8 form is rt.Arc<rt.ByteSlice>:

  • From: makes the box From would make of the same value, then wraps it in rt.Arc (task::shared_box). This replaces the old Arc<str>-only arm.
  • collect and Default: the box's collect and empty value, wrapped the same way.
  • get_mut and make_mut: now accept a slice or str pointee too. make_mut clones the value the way the box would.
  • Arc<[u8]>::from(Arc<str>): new rt.arcStrBytes. It returns an rt.ArcDyn that shares the string's count, because std shares the allocation. It is cached per Arc<str> so ptr_eq holds, and rebuilt when the text changed through a unique owner.

Differential test (lang/shares, 7 cases, against native wasm32):

  • elements: u8, u16, tuples and arrays JS copies, an item that logs its clones and drops, str; each made every way, including empty
  • reads: compared, hashed, printed
  • counts: cloned, ptr_eq, strong_count and weak_count, downgraded and upgraded
  • writes: get_mut and make_mut while unique, while shared, and with only a Weak left
  • drops: elements drop when the last owner drops
  • a generic Shared<T> { items: Rc<[T]> } at each element
  • HashSet<Rc<str>> and HashMap<Arc<[u8]>, _> looked up by borrow, plus AsRef, Borrow, from_iter, and clone_from

Breaking the arcStrBytes count sharing, or its cache refresh, fails the differential.

Impact

  • Output: these calls now translate instead of being refused. Existing output is unchanged.
  • Runtime: adds rt.arcStrBytes.
  • Not breaking, so no MIGRATE.md entry.

Alternatives

  • rt.ByteSlice alone for Rc<[u8]>, as Box<[u8]> is. Rejected: strong_count, ptr_eq, Weak, and make_mut need a count, and a generic Arc<[T]> would then take two forms.
  • Arc<[u8]>::from(Arc<str>) as a fresh rt.Arc. Rejected: it would lose the count std shares between the two.

Follow-ups

Gaps found writing the fixture, recorded as quests in this PR:

  • quest/m3/ts-slice-conversions.md: Vec::from(&[T]) and as_chunks.
  • quest/m3/ts-arc-pointers.md: Rc::as_ptr, Arc::as_ptr, and ptr::addr_eq.

Review

  • quest review by Codex, gpt-6.1-sol, medium effort.
  • Round 1 on 6f093b79, 2 findings, both fixed in 6d165a2a:
    • The arcStrBytes arm also matched identity From of an Arc (Rc::<str>::from(rc), Arc::<u32>::from(arc)). It now needs Arc<str> to Arc<[u8]>, and the slice-or-text arm skips a source that is already an Arc. Covered in the fixture.
    • The cached bytes went stale after the text was written through a unique Rc<str>. The cache now keeps the text it was made of and rebuilds on a change. Covered in the fixture.
  • Round 2 on f607f8bf0c249afe894ea75aeeeb94f07b97ecef: no findings.
  • just ci passes locally on f607f8bf.

🤖 Generated with Claude Code

kixelated and others added 4 commits November 2, 2026 22:56
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tes after a write

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Rc and Arc of a slice feat(ts): translate Rc and Arc of a slice and of str Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 08:53
@coderabbitai

coderabbitai Bot commented Nov 3, 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 56 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: be91ae65-939f-4561-9bd6-2a48c0f1a85c
Commits

Reviewing files that changed from the base of the PR and between 3660c29 and f607f8b.

Files ignored due to path filters: 1
  • ts/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 21
  • quest/m3/README.md
  • quest/m3/ts-arc-pointers.md
  • quest/m3/ts-shared-slices.md
  • quest/m3/ts-slice-conversions.md
  • ts/README.md
  • ts/fixtures/lang/shares/Cargo.toml
  • ts/fixtures/lang/shares/expected/core/option.ts
  • ts/fixtures/lang/shares/expected/harness.ts
  • ts/fixtures/lang/shares/expected/lib.ts
  • ts/fixtures/lang/shares/expected/shares.Held.ts
  • ts/fixtures/lang/shares/expected/shares.Logged.ts
  • ts/fixtures/lang/shares/expected/shares.Shared.ts
  • ts/fixtures/lang/shares/expected/shares.ts
  • ts/fixtures/lang/shares/src/lib.rs
  • ts/fixtures/lang/shares/src/shares.rs
  • ts/fixtures/lang/shares/ts.toml
  • ts/runtime/rt/task.ts
  • ts/src/lower/iter.rs
  • ts/src/lower/library.rs
  • ts/src/lower/task.rs
  • ts/tests/fixtures.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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@kixelated
kixelated enabled auto-merge November 3, 2026 08:53
@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit d341f7e Nov 3, 2026
5 checks passed
@kixelated
kixelated deleted the quest/m3/ts-shared-slices branch November 3, 2026 09:02
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