ReviewOS

zig-utils/zig-js

Compiler: lower yield-aware object rest assignments

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

Problem

The bytecode compiler already lowers object destructuring assignments when a computed key, default initializer, or target contains yield, but compileObjectPattern rejects every assignment pattern with an object rest property. For example, a generator containing ({ key: value = yield, ...rest } = source) is forced back to the tree-walker even though the suspension requires resumable bytecode.

This is a real admission gap under #465, independent of stack/queue/job work.

Required semantics

  • Preserve ECMA-262 RestDestructuringAssignmentEvaluation ordering: evaluate the rest assignment target before creating/copying the rest object, then perform PutValue.
  • Preserve computed member target evaluation and ToPropertyKey timing exactly once.
  • Support identifier, ordinary member, and super rest assignment targets accepted by the parser.
  • Retain CopyDataProperties own-key ordering, exclusion, getter, symbol, and abrupt-completion behavior through the existing object_rest opcode.
  • Add compiler admission and runtime coverage for suspension plus observable rest-target/copy ordering.

Acceptance

  • Yield-aware object assignment patterns with rest compile in generator bytecode.
  • Rest target evaluation precedes CopyDataProperties and PutValue follows it.
  • Existing focused unit and Test262 boundaries show no regressions.

Related: #465

9 days ago

Implementation audit found an adjacent ordering defect in the same resumable object-assignment lowering: for {[keyExpr]: target = default, ...rest} = source, the code evaluated target before keyExpr even though KeyedDestructuringAssignmentEvaluation requires PropertyName evaluation first. The implementation will correct and test keyExpr → target Reference → GetV/default/PutValue → rest Reference → CopyDataProperties → rest PutValue as one coherent lowering change.

9 days ago

Causal trigger confirmed: nodeHasYield scanned object-pattern properties but not obj_pattern.rest. A rest-only suspension such as ({...target[yield key]} = source) was therefore misclassified for non-resumable bind_pattern delegation before compileObjectPattern could even apply its rest rejection. The candidate now scans the rest target, preserves the target base/key in activation-owned roots across suspension, CopyDataProperties getter calls, and moving GC, and defers ToPropertyKey/PutValue until after copying.

9 days ago

Landed in 3c752e8c.

Acceptance evidence:

  • Yield-aware object assignment patterns with identifier, member, and super rest targets now lower through resumable bytecode.
  • PropertyName evaluation precedes the ordinary assignment target Reference; the rest target Reference precedes CopyDataProperties; ToPropertyKey/PutValue remain after copying.
  • Member/super base and raw key values remain activation-rooted across suspension, source getters, and moving GC, with mirrored tree-walker ordering.
  • Focused unit: 1 passed, 0 failed, 0 leaked.
  • Focused TSan: 1 passed, 0 failed, 0 leaked.
  • Full units: 1,845 passed, 1 skipped, 0 failed, 0 leaked.
  • Exact-parent Test262 assignment/dstr boundary: 368 -> 368 passes; flips 0; regressions 0.

Sign in to comment on this issue.