Skip to content

fix(runtime): route for-await async generator values#4408

Open
andrewtdiz wants to merge 3 commits into
PerryTS:mainfrom
andrewtdiz:codex/async-generator-for-await-variable
Open

fix(runtime): route for-await async generator values#4408
andrewtdiz wants to merge 3 commits into
PerryTS:mainfrom
andrewtdiz:codex/async-generator-for-await-variable

Conversation

@andrewtdiz
Copy link
Copy Markdown
Contributor

Refs #4405

Summary

  • adds a ForAwaitToArray HIR materialization path for untyped for await...of receivers
  • routes that path through the existing js_array_from_async collector, so async-generator values held in variables or returned from methods use async-iterator/.next() semantics instead of the sync for...of array fallback
  • keeps the existing for await array fast path intact, including awaiting array elements
  • adds a focused parity fixture covering direct async-generator calls, variable-held async generators, async-generator method results, custom async iterables, and arrays of promises

Why Batched

The variable-held and method-result cases fail for the same reason: after the direct named async-generator call special case is missed, lowering falls through to the untyped for...of materializer. A single async materializer fixes both without changing the direct named-call path.

Non-Goals

  • broader async generator scheduling rewrites
  • Promise/microtask ordering changes outside the existing Array.fromAsync collector
  • adding [Symbol.asyncIterator] shape metadata to Perry async-generator objects
  • unrelated for await stream/timer special paths

Validation

  • Node 26 oracle for test-parity/node-suite/globals/async-generator-for-await-variable.ts matched Perry direct output
  • CARGO_TARGET_DIR=/tmp/perry-async-generator-for-await-check cargo check -p perry-hir -p perry-codegen -p perry-codegen-js passed
  • cargo build -p perry-runtime -p perry-stdlib -p perry --release passed
  • PATH=/root/.npm/_npx/bac97da9607b7ef2/node_modules/node/bin:$PATH PERRY_NO_AUTO_OPTIMIZE=1 PERRY_NO_CACHE=1 ./run_parity_tests.sh --suite node-suite --module globals --filter async-generator-for-await-variable passed: 1 pass / 0 fail
  • same harness with --filter generator passed: 6 pass / 0 fail
  • same harness with --filter array-from-async passed: 1 pass / 0 fail
  • cargo fmt -p perry-hir -p perry-codegen -p perry-codegen-js -- --check passed
  • git diff --check HEAD passed
  • git diff --cached --check passed
  • jq empty test-parity/known_failures.json passed
  • ./scripts/check_file_size.sh passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants