ReviewOS

zig-utils/zig-js

Optimizer: cover environments, closures, classes, iterators, and general control

#467
Open chris opened this 9 days ago ·
9 days ago

Parent: #459 Depends on: #465, #466

Goal

Expand the optimizing tier from its released bounded subset to the full language/runtime effect surface needed by representative applications.

Current boundary

The optimizer supports broad primitive/call/property/array runtime operations and reducible loop regions. 5b73904e (#1090) adds exact this and new.target activation reads with rooted runtime effects and activation-safe entry. 2eeae7a5 (#1095) adds all regular/mapped/lexical captured-binding loads and stores with exact activation coordinates, recovery, synchronization and guarded numeric access. 136178ae (#1096) adds missing-name reads, environment stores/declarations, retained Reference effects and logical-assignment merge diamonds, including rooted WithBaseObject recovery. ed872e60 (#1097) and that integration preserve exact budget/termination after callbacks. 03f45cbb (#1098) adds synchronous iterator acquisition, result validation and normal/completion-preserving closing with exact rooted recovery, plus effectful entry regions ending before control transfer. 4010bc51 (#1102) adds canonical closure-template allocation, synchronized regular/mapped/lexical live bindings, local-preserving recovery and OSR, and scoped roots for suspended native callers. For-in preparation, one-candidate advancement, exact multi-result recovery and rooted native transport are implemented in ceeb5abc and 89fec617 (#1106). Proxy prototype and candidate-descriptor semantics are corrected in 3100f072 (#1107), with 276 affected tests passing in Debug/ReleaseSafe/unsuppressed TSan, 8,339 exact-parent conformance cases per mode unchanged, and full no-GIL gates passing 253/253 in both modes. Broader hosted full-unit integration remains unresolved on #494; this evidence does not complete the parent acceptance. Asynchronous iterator suspension, class effects, broader array regions, and irreducible multi-entry cycles still side-exit or reject. The pre-existing primitive Symbol/BigInt close-result validation defect is resolved in 80e45951 (#1100). The separate arguments snapshot and length-reflection defects are resolved in #1092 and #1093.

Scope

  • Model environment and closure values in SSA, including captured loads/stores, lexical this, super, new.target, private fields, class initialization, and direct-eval barriers.
  • Lower closure allocation/call, iterator protocol, generator/async state transitions, class construction, accessors/proxies, spread, destructuring, and module/global bindings with exact effect edges.
  • Support irreducible control through verified node splitting/region formation or another backend-neutral strategy with exact OSR/deopt states.
  • Replace blanket shared-mode fallbacks with immutable synchronized assumptions where sound; preserve canonical dispatch where not yet proven.
  • Version the optimizer operation/IR coverage inventory and record every rejection reason.

No-workaround rules

  • No semantic subset disguised as “full,” no skipped exception/finally/suspend edge, no assumed purity of iterator/accessor/proxy/user callback, and no lossy environment reconstruction.
  • Unsupported cases remain exact lower-tier execution until individually proven.

Acceptance

  • Seeded forced optimizer-off/on differentials cover every new IR/effect family in serialized and no-GIL modes, normal and TSan.
  • OSR/deopt reconstructs exact locals, environments, operand stack, handlers, suspend state, completion, and step budget.
  • Moving-GC stack maps include every live managed value across runtime re-entry and suspend/resume.
  • Admission evidence shows expanded #460 workloads enter real optimizer artifacts without recompile loops.
  • Full unit, test262, PR-249, threadfuzz, debugger, termination, OOM/fault, and artifact-retirement gates pass.

Foundation

#146, #431–#440, #448, #450–#452; optimizer contract.

9 days ago

The activation-read boundary is implemented in #1090 / 5b73904e, following the separately pinned parser fix #1091.

this and new.target now have ordered zero-input SSA/runtime effects with exact recovery, exception continuation, and managed root coverage in entry and reducible-region lowering. Immutable artifact admission preserves the callee activation before observable work; explicit entry tests prove both refusal of activation elision and native completion through the proper activation. Eight-seed JIT off/on serialized/no-GIL differentials, canonical TDZ/initializer contexts, real moving-GC native-loop witnesses, OOM, worker, and step cases pass. Debug has 194 optimizer cases; ReleaseSafe and unsuppressed TSan qualification is detailed on #1090. Exact-parent outcomes match for 9,145 corpus cases, with zero new failing or diverging paths.

Only this scoped boundary is complete. Upvalue loads/stores, broader environments, iterator/class/closure effects, suspension, irreducible control, coverage inventory expansion, and workload/performance acceptance remain open. Hosted integration is pending.

Sign in to comment on this issue.