ReviewOS

zig-utils/zig-js

Compiler: lower earlier-parameter default references into VM frames

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

Parents: #465, #498 Depends on: #740 Related: #736, #738, #739

Implemented by: 1be84900

Problem

The ordered VM parameter prologue already completes each formal before moving to the next, but a later default that is exactly a bare reference to an earlier parameter binding still falls back. function f(first, second = first) {} needs neither general parameter-environment lookup nor expression coercion: the earlier frame binding is initialized before the later raw-undefined selection runs.

Scope

  • Admit a complete default expression that is one IdentifierReference bound by a strictly earlier formal, including names introduced by initializer-free array/object patterns.
  • Preserve left-to-right initialization, earlier defaults, object identity, undefined values, unmapped arguments, recursion/reentrancy, methods/arrows/base constructors, moving GC, and shared-chunk no-GIL execution.
  • Reject self references, later-parameter references, unresolvable/outer/body identifiers, and every embedded unary/binary/logical/conditional/sequence/member/call/new/assignment/update expression.
  • Reuse the existing frame slots, exact default/destructuring index metadata, ordered BindingInitialization bytecode, activation roots, malformed-layout validation, and native guards.

No-workaround rules

  • No source-text recognizer, pre-evaluation, copied value cache, TDZ weakening, global/outer lookup guess, permissive identifier admission, tree-walker callback, or alternate metadata path.
  • No stacks, queues, jobs, Promise, microtask, Worker lifecycle, or Map/Set iterator changes.

Acceptance

  • Compiler admission proves simple, defaulted, and destructured earlier bindings and rejects self/later/outer/embedded references.
  • Forced tree-walker and required bytecode agree on values, object identity, missing/provided bypass, recursion/reentrancy, methods/arrows/base constructors, and moving GC.
  • Shared no-GIL/TSan, OOM/malformed metadata, debugger, and native activation guards remain exact.
  • Full units, focused compiler/frontend/VM, threadfuzz, and exact nonzero Test262 accounting pass with zero regressions.
  • A conventional commit lands directly on main and cross-links #465, #498, #740, #736, #738, and #739.
9 days ago

Landed on main as feat(compiler): lower earlier parameter defaults (#741).

A complete bare IdentifierReference now enters the ordered VM default prologue only when a strictly earlier formal owns the exact binding. Earlier simple/defaulted parameters, initializer-free destructuring bindings, and an explicitly named arguments formal are supported. Self, later, outer/global, inherited arguments, and every embedded operation remain explicit barriers; no TDZ or environment lookup is approximated.

Verification on the landed tree: full units 1,882 passed / 1 skipped / 0 failed / 0 leaked; focused frontend 20/20; compiler admission, 3-way tree-walker/VM parity, and four-lane shared no-GIL witnesses pass normally and under TSan; deterministic threadfuzz is 400/0 in default and TSan builds. Exact nonzero Test262 accounting is byte-identical at 10,296 → 10,296 across function expressions/statements, arrows, object methods, class expressions/statements, and the Function constructor.

9 days ago

All acceptance criteria are complete on main; closing as implemented.

9 days ago

The follow-on composition issue #742 has landed on main in 54c54afe, reusing this issue's proven leaf semantics inside a fail-closed recursive expression grammar. Test262 remained byte-identical at 10296 -> 10296; full units, TSan, shared no-GIL, allocation-failure restoration, and 400-iteration default/TSan threadfuzz all passed.

9 days ago

The follow-on public property-read slice #743 has landed on main in 1b7e8e58, composing this issue's proven parameter-default semantics through canonical named/computed [[Get]]. Test262 remained byte-identical at 10296 -> 10296; full units, TSan, shared no-GIL, getter-OOM restoration, and default/TSan threadfuzz all passed.

9 days ago

The follow-on parameter-local call slice #744 has landed on main in 402e805a, composing this issue's proven defaults through canonical value and receiver-preserving call opcodes. Test262 remained byte-identical at 10296 -> 10296; full units, TSan, shared no-GIL, nested-call OOM restoration, and default/TSan threadfuzz all passed.

9 days ago

Follow-up #745 landed on main as feat(compiler): lower parameter construction defaults (#745). It composes the parameter-safe value/property/call grammar into canonical non-spread new_call lowering, remains fail-closed for unsupported forms, and records 10,296 -> 10,296 exact relevant Test262 cases with 0 flips. Derived and field-initializing constructor activations are separated into #746.

Sign in to comment on this issue.