Skip to content

ref(vlq): Overhaul API - #145

Open
loewenheim wants to merge 9 commits into
masterfrom
sebastian/ref-vlq
Open

loewenheim wants to merge 9 commits into
masterfrom
sebastian/ref-vlq

Conversation

@loewenheim

Copy link
Copy Markdown
Contributor

This removes the vlq module from the public API (a breaking change) and totally reworks its API:

  1. Everything is based on u32/i32 since sourcemap VLQs are restricted to that value range by the spec. No more i64 everywhere.
  2. The basic type is Vlq, a newtype around a u32. The inner value cannot be accessed directly; you need to use signed or unsigned depending on whether the number is to be interpreted as a i32 or u32.
  3. VLQs are no longer parsed into vectors. Instead, the decode_vlqs function returns a FallibleIterator that reads VLQs one by one off the front of a string slice.
  4. VLQs are encoded back into BASE64 via their Display impl.

@loewenheim
loewenheim requested a review from a team November 27, 2026 13:58
Comment thread src/vlq.rs
use crate::errors::{Error, Result};

const B64_CHARS: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const B64: [i8; 256] = [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now manually check that a character is ASCII before accessing this array, meaning the latter 128 slots are pointless.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/vlq.rs Resolved
Comment thread src/hermes.rs Resolved
Comment thread src/decoder/mod.rs Resolved
Comment thread src/decoder/mod.rs
if running_name_id >= names.len() as u32 {
return Err(Error::BadNameReference(running_name_id));
}
current_name_id = running_name_id;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative source or name deltas clamp to zero

Low Severity

running_src_id and running_name_id now update via saturating_add_signed, so a negative delta that underflows below 0 silently clamps to index 0 instead of failing the bounds check with Error::BadSourceReference or Error::BadNameReference.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7f90cc0. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ba0394a. Configure here.

Comment thread src/vlq.rs Resolved
Comment thread src/vlq.rs Outdated
Comment on lines +86 to +88
if val.highest_one().is_some_and(|idx| idx + shift >= 32) {
return Err(Error::VlqOverflow);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vlq::decode calls non-existent u32::highest_one

val.highest_one() is not a stable u32 method, so this crate fails to compile on the stable toolchain used by CI. Use checked_ilog2() (or an equivalent bit-width check) instead.

Evidence
  • Vlq::decode calls val.highest_one() on a u32 (src/vlq.rs line 86).
  • No local trait, helper, or #![feature(...)] gate defines highest_one for integers.
  • .github/workflows/ci.yml installs and builds with stable Rust (cargo test / cargo clippy), which does not provide this method.

Identified by Warden · code-review · R28-MZL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stable since 1.97.0.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant