oven-sh/bun · error

stage1 offsets no longer fit in uint16_t

Error message

stage1 offsets no longer fit in uint16_t

What it means

Encoding invariant in the 3-stage table rebuild: stage1 stores byte offsets into stage2 as uint16_t. If stage2 grows beyond 0xffff+256 bytes the offsets no longer fit, so the generated C table would be wrong and the generator aborts instead of emitting it.

Solutions

  1. Improve block deduplication so fewer stage2 entries are emitted
  2. Widen the stage1 offset type in the header if growth is legitimate
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at scripts/generate-stringwidth-tables.mjs:229 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/3b11bf6be02d69b7. Report an issue: GitHub.

Appendix: source

Thrown at scripts/generate-stringwidth-tables.mjs:229

    if (index === undefined) {
      index = newStage3.length;
      if (index > 255) throw new Error("more than 256 distinct packed values");
      valueToIndex.set(value, index);
      newStage3.push(value);
    }
    block[low] = index;
  }
  const key = block.join(",");
  let offset = blockKeyToOffset.get(key);
  if (offset === undefined) {
    offset = newStage2.length;
    blockKeyToOffset.set(key, offset);
    newStage2.push(...block);
  }
  newStage1[high] = offset;
}

if (newStage2.length - 256 > 0xffff) throw new Error("stage1 offsets no longer fit in uint16_t");

// Verify the rebuilt table roundtrips for every codepoint and preserves the
// original grapheme classes exactly.
for (let cp = 0; cp <= 0x10ffff; cp++) {
  const got = newStage3[newStage2[newStage1[cp >> 8] + (cp & 0xff)]];
  if (got !== packed(cp)) throw new Error(`roundtrip mismatch at U+${cp.toString(16)}`);
  if ((got & 0x1f) !== classOf(cp)) throw new Error(`class mismatch at U+${cp.toString(16)}`);
}

// ---------------------------------------------------------------------------
// Emit
// ---------------------------------------------------------------------------

function formatArray(values, perLine) {
  const lines = [];
  for (let i = 0; i < values.length; i += perLine) {
    lines.push("    " + values.slice(i, i + perLine).join(", ") + ",");
  }

View on GitHub (pinned to 8c5296ac45)