ReviewOS

zig-utils/zig-js

Compiler: lower class heritage across bytecode tiers

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

Parents: #465, #496 Related: #619, #714

Problem

The bytecode compiler rejects every class expression with ClassHeritage, including otherwise supported generator and async bodies. Computed class element names already lower in source order and can suspend, but the heritage expression is still delegated wholesale to the tree-walker. This prevents correct bytecode admission for class extends Base {}, class extends (yield Base) {}, and class extends (await Base) {}.

Heritage cannot simply be evaluated before the existing eval_class opcode: a named class binding must already exist in TDZ, constructor/prototype validation must complete before any computed element name runs, and the class lexical environment must remain live through class construction and deferred member capture.

Scope

  • Enter one activation-local class lexical Environment before heritage evaluation and predeclare a named class binding with the exact TDZ/const contract.
  • Evaluate the heritage expression in strict class code, then immediately validate the constructor and its prototype once.
  • Preserve the prepared superclass constructor/prototype as precise VM operand roots across yield/await, then evaluate computed element names in source order.
  • Build the class in the already-active class Environment without re-evaluating heritage or re-reading prototype.
  • Preserve extends null, named-class TDZ, getter/throw ordering, private-name rewriting, static initialization, method/field capture, abrupt environment unwinding, moving GC, and native-tier fallback.

No-workaround rules

  • No eager tree-walker evaluation, duplicate prototype lookup, source rewriting, global scratch, shared mutable staging, skipped class environment, broad class admission, or stacks/queues/jobs/Promise/Worker changes.

Acceptance

  • Program, plain-function, generator, async, and async-generator admission covers ordinary, suspended, and awaited heritage where the surrounding tier supports it.
  • Forced tree-walker/required-bytecode witnesses prove exact result, TDZ, prototype getter, computed-key, throw, extends null, and static initialization order.
  • Moving-GC and suspension tests prove prepared heritage values and the class Environment remain precise roots.
  • Focused compiler/VM/frontend, TSan, full units, and exact nonzero Test262 class-heritage accounting pass with zero regressions.
  • Parent/related issues and the landed commit are cross-linked with quantified evidence.
9 days ago

Landed in 4740df55 (feat(compiler): lower class heritage across bytecode tiers (#718)).

Evidence:

  • Focused #718 compiler/context coverage: 3/3 pass.
  • Compiler admission-reason coverage: 10/10 pass.
  • Frontend coverage: 12/12 pass.
  • Focused TSan: 3/3 pass with no race diagnostics.
  • Full units: 1,840 pass, 1 skip, 0 fail, 0 leak across 10 shards.
  • Moving-GC suspension coverage verifies prepared constructor and prototype roots survive compaction, while the observable prototype getter executes exactly once.

The implementation covers program, plain-function, generator, async, and async-generator bytecode admission while preserving strict class evaluation, TDZ/const named-class bindings, extends null, computed-key ordering, and interpreter fallback parity.

Exact Test262 heritage accounting was not used as landing evidence because the available candidate corpus run overlapped another corpus job. No Test262 delta is claimed here.

Parent tracking: #465 and #496. Related conformance work: #619 and #714.

Sign in to comment on this issue.