Skip to content

fix(ts): measure offset_from across views of one byte buffer - #455

Merged
moq-bot[bot] merged 3 commits into
mainfrom
quest/m3/ts-byte-offset
Nov 2, 2026
Merged

moq-bot[bot] merged 3 commits into
mainfrom
quest/m3/ts-byte-offset

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Problem

offset_from between two byte pointers into one buffer threw rust2-ts: offset_from of pointers JS keeps in different arrays when they came through different views of it. Example: a slice's as_mut_ptr and the pointer of an element its iter_mut gives. Native Rust measures the distance. Each pointer is an rt.AtIndex into its own Uint8Array, and subarray makes a fresh one sharing the buffer. Found by review on #418 and recorded in quest/m3/ts-unsafe.md.

Approach

rt.ptrOffsetFrom treats two Uint8Arrays over one ArrayBuffer as one array, measuring by each view's byteOffset plus the pointer's index. Every other pair of arrays still fails loudly. It is the only runtime operation that compares a pointer's array by identity: ptr::copy already copies between views through Uint8Array.set, and translation refuses comparisons of element pointers.

Impact

  • Output: unchanged.
  • Runtime: rt.ptrOffsetFrom returns the distance where it threw. No public API change, no MIGRATE.md entry.
  • Quest: drops the item from quest/m3/ts-unsafe.md.

Tests: fixtures/lang/src/elements.rs's edges, differential against native wasm32: within a subslice of a byte array, pointers from as_mut_ptr, from iter_mut's first and last elements, and from split_at_mut's second part, measured against each other both ways, then a write through a pointer moved by one such distance. Before the fix, those cases threw (181 differences); after it, they agree with native.

Alternatives

  • One canonical Uint8Array per buffer, made by elemOf. Rejected: it would also let a pointer reach past its view into the rest of the buffer, such as a ByteVec's spare capacity, which today fails loudly. That needs its own decision.

Review

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 2, 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: 46da44d4-f022-4471-b9b0-a7b23022d425
  • 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

@moq-bot
moq-bot Bot merged commit 4e63d4c into main Nov 2, 2026
@moq-bot
moq-bot Bot deleted the quest/m3/ts-byte-offset branch November 2, 2026 21:50
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