ReviewOS

zig-utils/zig-js

JIT: execute optimizer loop bodies with resumable invalidation polls

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

Parent: #432 Blocks: #429 Depends on: #431 Follow-up: #438

Extend the first loop-header OSR region into native loop bodies and backedges without losing exact VM semantics.

Acceptance

  • Lower loop-carried block arguments with correct parallel edge copies.
  • Execute supported numeric loop bodies and backedges natively across multiple iterations.
  • Poll owner invalidation and VM safepoints inside generated loops, reconstructing the exact header/body state before any stale operation.
  • Preserve exact instruction-step, budget, 1,024-step checkpoint, termination, and bytecode fallback behavior.
  • Cover zero/one/many iterations, multiple loop-carried locals, nested control, guard failure, and invalidation races under normal and TSan gates.

Landed checkpoints

  • c152d97: OSR-only tier arbitration reaches optimizer backedges; AArch64 copies header-to-body SSA arguments, executes and path-accounts one complete numeric body iteration, and recovers updated loop-carried values.
  • e65880c: supported numeric bodies apply body-to-header copies and stay native across multiple iterations; every header polls invalidation and budget/checkpoint distance, side-exiting exact current state before a pending boundary.
  • e9d0dac: edge assignments use deterministic parallel-copy scheduling with reusable cycle scratch; swapped multi-local backedges, exact checkpoint recovery, and non-number guard refusal pass normal and TSan JIT gates.
  • 9bf1034: one equal-cost inner branch diamond stays native through both arms, a shared merge/latch, exact per-iteration accounting, and header checkpoint recovery; unsupported shapes still fail closed.
  • 6852f5f: an instrumented release marker deterministically races invalidation after completed native work; the next header poll reconstructs exact state under full normal and TSan JIT gates.

All declared first-region acceptance is complete. General unequal/deeper reducible CFGs continue in #438. Closure awaits the exact current main CI run.

9 days ago

Checkpoint c152d97a is on main.

  • OSR-only optimizer artifacts now retain bytecode control at function entry instead of being starved by the baseline tier.
  • Lowering emits explicit header-to-body SSA block-argument copies.
  • AArch64 executes either the exit header or one complete straight-line numeric body iteration, with path-specific step accounting.
  • The body backedge recovers updated loop-carried locals at the next header without replaying the header or body.
  • Budget/checkpoint preflight remains conservative and exact.

Compiler recovery tests verify the incremented local; the VM test separately proves exact manual eligibility and real run-loop backedge entry. Normal and TSan focused JIT both passed 113/113 with zero leaks.

No acceptance box is checked yet: native code still returns at each backedge, so parallel backedge copies, multi-iteration execution, and internal safepoint/invalidation polls remain.

9 days ago

Checkpoint e65880ca is on main.

  • Body-to-header SSA copies now feed a generated native backedge.
  • Supported numeric loops execute multiple iterations per OSR entry.
  • Every native header polls the owner generation and checks remaining budget/checkpoint distance.
  • A pending poll side-exits the exact current header before more work; completed iterations remain accounted and recoverable.
  • Compiler coverage now includes zero, one, and many iterations plus an exact checkpoint-boundary zero-work exit.
  • End-to-end VM coverage proves real backedge entry, exact results, and unchanged total step deltas.

Normal and TSan focused JIT both passed 113/113 with zero leaks. Three acceptance items are now checked; general parallel-copy cycles and broader/nested loop stress remain open. Benchmark scores remain unchanged because the published workloads do not enter this optimizer subset.

9 days ago

Checkpoint e9d0dac0 is on main.

  • Edge block arguments are now lowered as true parallel assignments.
  • A deterministic scheduler emits safe acyclic moves and breaks arbitrary cycles with one reusable scratch slot.
  • A four-local native loop swaps two values on every backedge while advancing a third, proving exact exit and checkpoint reconstruction.
  • End-to-end OSR now explicitly verifies a non-number guard refusal leaves IP, state, and step accounting untouched.
  • README and optimizer documentation describe the current boundary without stale loop/stack-map claims.

Normal and TSan zig build test-jit both passed 115/115 with zero leaks. The parallel-copy acceptance item is complete. The final coverage item remains open for nested/broader control and a deterministic invalidation race during an active native loop. Published benchmark scores remain unchanged because those workloads do not enter this optimizer subset.

9 days ago

Checkpoint 9bf10349 is on main.

A loop OSR region may now contain one equal-cost inner if/else diamond. Both arms receive exact SSA edge assignments, execute only the selected operations, merge into a shared latch, and return through the native backedge. The compiler proves equal instruction cost with checked arithmetic and rejects every unsupported shape before publication.

The regression exercises both arms over multiple iterations, verifies the merged result and 84-step exit, then forces a header side exit after exactly two 20-step iterations and reconstructs all locals. Normal and TSan loop-OSR filters each passed 4/4 with zero leaks. README/docs describe this narrow boundary; benchmark scores remain unchanged.

The aggregate coverage item stays open for a deterministic invalidation race during active native execution and unequal/deeper nested control (or a separately linked follow-up boundary).

9 days ago

Checkpoint 6852f5f2 is on main and completes the declared first loop-region evidence.

Instrumented test artifacts now release-publish a marker only after a complete native backedge. A waiting invalidator changes the atomic owner generation, and the subsequent generated header poll side-exits with a positive whole-iteration step count, exact header IP, block-entry recovery, and the matching loop local. Production artifacts do not emit the observer load/store.

Combined normal and TSan zig build test-jit passed 117/117 with zero leaks. All #435 boxes are checked; broader unequal/deeper reducible control is explicitly tracked by #438. README/docs are current, and benchmark scores remain unchanged because the published workloads do not enter this subset. I will close #435 only after the exact current main CI run passes.

9 days ago

Closed against exact main SHA 612340d6: CI run 29877847695 completed successfully with 42 successful jobs, one expected skipped nightly lane, and zero failures. All declared first-region acceptance remains checked; broader reducible CFGs continue in #438.

Sign in to comment on this issue.