Skip to content

fix(ts): hold a byte vector's capacity as a heap or deque takes it - #417

Merged
moq-bot[bot] merged 5 commits into
mainfrom
ts-capacity/byte-heap
Nov 2, 2026
Merged

moq-bot[bot] merged 5 commits into
mainfrom
ts-capacity/byte-heap

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Problem

BinaryHeap<u8>::from(h.into_vec()), and VecDeque<u8>::from(Vec<u8>), convert a Vec<u8> (rt.ByteVec) to a JS array with rt.byteVecToVec. That conversion sets the array's capacity with capSet, which records nothing when the capacity equals what the length implies. Once the heap is cleared, its capacity falls back to what the new length implies, below what an earlier reserve guaranteed. Rust keeps it:

let mut h = BinaryHeap::<u8>::new();
h.extend(...10 items...);   // capacity 16
h.reserve(0);               // guarantees at least 10
h = BinaryHeap::from(h.into_vec());
h.clear();
h.capacity()                // native 16; translated 0

The lang differential found this once #414's two-byte selector moved random inputs onto capacity::heaps (reduced from input 695dff6e…).

Approach

byteVecToVec holds the capacity with capHold, as reserve does, so it survives the length dropping. No other capSet makes a fresh array from a container whose capacity may be held: the others either keep an existing hold (c.cap !== undefined) or start a fresh floor.

Impact

  • Output: unchanged; the runtime's byteVecToVec now keeps a u8 heap's or deque's capacity as Rust does. No API change.

Tests: a named capacity::heaps case of each element type: extended past its least capacity, reserve(0), remade from its Vec, and cleared. It differs from native on the u8 heap without the fix, and agrees with it.

Stacks on #414 (its two-byte op in caller.ts); land after it.

Alternatives

  • Make capSet always record the capacity. Rejected: it would put a cap on every cloned Vec, where the derived one already meets std's guarantee.

Review

  • Codex gpt-6.1-sol at medium effort (quest review --base origin/ts-harness/selector), round 1 on 7e814171: no findings.
  • just ci passes locally on 7e814171.

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 4 commits November 1, 2026 19:32
@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: ee7e48e1-c8c4-40fe-a9a1-91d5f7a984c2
  • 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 b1656c9 into main Nov 2, 2026
@moq-bot
moq-bot Bot deleted the ts-capacity/byte-heap branch November 2, 2026 05:21
kixelated added a commit that referenced this pull request Nov 2, 2026
…or settled

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moq-bot Bot pushed a commit that referenced this pull request Nov 2, 2026
…d, and share lang's translation (#419)

* chore(quest): claim quest/m0/checks/differential.md

Quest-Claim: b513aa5d0c89f7f9

* chore(ts): run the differential fixtures optimized and single-threaded, and share lang's translation

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

* chore(quest): finish the cheaper differential

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

* chore(quest): plan reaching every lang case

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

* chore(quest): drop the lang cases quest, which #417's two-byte selector settled

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: moq-bot <moq-bot@users.noreply.github.com>
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