ReviewOS

zig-utils/zig-js

Debugger: seed the shared statement-location registry

#860
Closed chris opened this 9 days ago ·
9 days ago

Parent: #493 Related: #461, #478, #495, #501, #857

Problem

The Context-owned debugger statement-location registry is a persistent AutoHashMapUnmanaged(*const ast.Node, DebugStatementLocation). JavaScript controls source size, statement count, dynamic Function/eval creation, and AST allocation order. Deterministic pointer hashing therefore exposes collision-amplified insertion and lookup work. In a no-GIL realm, every registry miss holds the shared reentrant debugger lock, so a collision family also amplifies cross-thread latency.

The fixed-size interpreter-local hot cache bounds repeated hits but cannot protect cold statements, dynamic scripts, inspector enumeration, JIT source lookup, or registry publication.

Scope

  • Replace the default pointer map with one Context-owned exact AST-identity index using a realm-secret keyed hash context derived from the root Shape key source.
  • Keep empty/no-location scripts seed- and allocation-free.
  • Make first non-empty publication failure-atomic: entropy or capacity failure publishes no context, location, script id, or partial registry entry.
  • Preserve exact script ids, source coordinates, debugger-statement flags, late attach/history, reentrant notifications, interpreter-local cache behavior, and existing no-GIL lock ownership.
  • Route interpreter, inspector, JIT observability, and test iteration through the same context-aware index.

No-workaround rules

  • No statement filtering, history truncation, linear fallback, address-secrecy assumption, larger fixed cache, disabled dynamic code, or inspector-only special case.
  • No new per-statement entropy call, global mutable hash seed, or lock held outside the existing registry transaction.
  • No change to JavaScript/debugger protocol semantics or source-location precision.

Acceptance

  • The default AST-pointer map is gone and every read/write/iteration uses the exact keyed index.
  • Empty registries remain seed-free; failed first capacity acquisition leaves context, count, scripts, and next id unchanged.
  • A direct legacy AutoHashMap(*Node, ...) collision family disperses under a fixed realm seed without changing pointer equality.
  • Dynamic Function/eval publication, late inspector attach, JIT source mapping, and the four-way interpreter cache remain exact.
  • Focused Debug/ReleaseSafe/TSan, full unit, threadfuzz, public C API inspector, and Home private-ABI gates pass without regressions.
9 days ago

Landed as fix(debugger): seed statement location registry (#860).

The Context now owns one lazy exact AST-identity index keyed from the root Shape secret. Empty scripts remain seed/allocation-free; complete location capacity is acquired before the context or script id is published; every interpreter, inspector, and JIT lookup uses the same index under the existing registry lock.

Evidence:

  • Focused registry tests: 7/7 Debug; 3/3 ReleaseSafe; 3/3 TSan.
  • Public debugger behavior: 10/10 in Debug, ReleaseSafe, and TSan.
  • Full units: 2,275 passed, 1 skipped, 0 failed, 0 leaked across 10 shards.
  • Exact-parent Test262 test/language/statements: 9,337/9,337 on both revisions, byte-identical diagnostics, 0 flips.
  • threadfuzz: 400 programs, 0 failures.
  • Public C API: 117/117 complete.
  • Home private ABI: 447/447 implemented; 392/392 runtime shims passed in Debug, ReleaseSafe, and TSan.

Sign in to comment on this issue.