Repository navigation
JS engine: generators and async functions (items 7.7–7.9) - #304
Merged
Merged
Conversation
The suspension ops the compiler already emits (GeneratorStart, Yield, YieldDelegate, Await) and the iteration ops of yield* and for await (GetAsyncIterator, IterCallMethod, IterComplete, IterValue) now run. A suspension copies the frame's header, registers and resume pc into the generator object's slots and returns as Return does; a resumption pushes the copy back with no caller and runs the loop on it. Async functions settle their promise on return and on an escaping throw. The promises come from the built-ins through PromiseOps. No op is new, and spec::fast_path already sends each of these to its handler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
%GeneratorFunction.prototype%, %GeneratorPrototype% (next, return, throw), %AsyncFunction.prototype%, %AsyncIteratorPrototype%, %AsyncGeneratorFunction.prototype%, %AsyncGeneratorPrototype% and %AsyncFromSyncIteratorPrototype%, and the Promise operations the VM's await uses. Tests of generators, yield*, async functions, async generators and for await. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the pinned commit e91219cb, byte for byte: language/statements generators, async-function and async-generator; language/expressions generators, async-function, async-arrow-function, async-generator, await and yield; built-ins GeneratorPrototype, GeneratorFunction, AsyncFunction, AsyncGeneratorPrototype, AsyncGeneratorFunction, AsyncFromSyncIteratorPrototype and AsyncIteratorPrototype. The table is regenerated with cargo xtask testdata (6939 cases). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The built-ins runner now runs async tests (doneprintHandle.js and a microtask checkpoint), the harness files the generator tests include, and assert.compareArray; it prints the counts of each generator and async function directory. Five tests that fail for gaps outside this change (eval, the unmapped arguments object, Function.prototype's restricted properties) are listed as known gaps. The interpreter-only runner classes built-ins/ and array iteration as needing the built-ins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lemma_suspendable_return_not_fast: in a frame of kind suspendable, Return always calls its handler, which is where the interpreter completes the generator or settles the async function's promise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atiernan
temporarily deployed
to
full-verification
November 24, 2026 20:16 — with
GitHub Actions
Inactive
Both sides' intrinsics are kept (38), with Date's World hook. SOURCE.md lists both vendored subsets; the Test262 table is regenerated (7,533 cases). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atiernan
temporarily deployed
to
full-verification
November 24, 2026 22:36 — with
GitHub Actions
Inactive
string_match_search_split_replace becomes match/matchAll, search/split and replace/replaceAll; json_parse moves its nesting and reviver cases into a test of their own. Every case is kept; each piece stays under the Miri time limit as the Runtime's setup grows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atiernan
temporarily deployed
to
full-verification
November 25, 2026 01:39 — with
GitHub Actions
Inactive
atiernan
added a commit
that referenced
this pull request
Nov 25, 2026
…s-input (#300) Conflicts in clazel-js-vm's interp.rs and clazel-js's runtime.rs: the lazy accessor maker and main's world hook are both kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
Phase 7 items 7.7 to 7.9: generators and async functions now run. The compiler and the op list already had them (
Yield,Await,GeneratorStart,YieldDelegate, theyield*/for awaititeration ops); the interpreter reported them as not implemented. This PR adds the runtime half.What works
function*,yield,yield*), generator objects withnext,returnandthrow(§27.5), includingreturn/throwthroughfinallyblocks, suspended-start and completed states, and the "already running" TypeError.for-of, spread, destructuring,yield*over any iterable (withthrow/returndelegation and the iterator result passed through as it is).awaitof values, promises and thenables, rejections thrown at theawait, errors in parameters rejecting the promise, job ordering.next/return/throwqueued, AsyncGeneratorAwaitReturn, DrainQueue),for await(over async iterables and, via%AsyncFromSyncIteratorPrototype%, sync ones), andyield*in async generators.%GeneratorFunction.prototype%,%GeneratorPrototype%,%AsyncFunction.prototype%,%AsyncIteratorPrototype%,%AsyncGeneratorFunction.prototype%,%AsyncGeneratorPrototype%,%AsyncFromSyncIteratorPrototype%; generator and async functions are not constructors.Design (
clazel-js-vm/src/suspend.rs): a call of one of these functions pushes an ordinary frame of kindKIND_SUSPENDABLE. A suspension op copies the frame (header, registers, resumepc, and the two registers the op names for the resumption) into slots of the generator object (a host object, so nothing is hidden from the future collector) and leaves the frame asReturndoes. A resumption pushes the copy back with no caller (RET_NONE), writes the sent value and the mode, and runs the loop on it, as a native's call into JS does. The compiled code after each suspension already dispatches on the mode. Async functions settle their promise onReturnand when a throw leaves the frame (inunwind). The VM has no Promise of its own: the built-ins installPromiseOps(NewPromiseCapability, PromiseResolve, PerformPromiseThen).Verification. No op is new and the spec is unchanged:
spec::fast_pathalready sends the suspension ops to their handlers, aReturnfrom a frame that is not plain is not fast, andFnInfo::fast_callableexcludes these functions. One lemma is added,lemma_suspendable_return_not_fast(aReturnfrom a suspendable frame always calls its handler), which the interpreter relies on. Because there is no new op or spec function, there is no new mutation. The crate stays at tier 0.Test262
Vendored from the pinned commit e91219cb, byte for byte (SOURCE.md updated, table regenerated; 7,533 cases with
Date's directory frommain):language/statements/{generators,async-function,async-generator},language/expressions/{generators,async-function,async-arrow-function,async-generator,await,yield},built-ins/{GeneratorPrototype,GeneratorFunction,AsyncFunction,AsyncGeneratorPrototype,AsyncGeneratorFunction,AsyncFromSyncIteratorPrototype,AsyncIteratorPrototype}.The built-ins runner (
conformance_builtins) now runsasynctests (realdoneprintHandle.js, then a microtask checkpoint), runs the harness files these tests include (propertyHelper.js,compareArray.js,asyncHelpers.js,isConstructor.js), and hasassert.compareArray.Whole table (7,533 tests after vendoring and the merge of
mainwithDate, #303;main's status table had 5,212 before both):mainclazel-js-builtinsconformance_builtins(with the built-ins)clazel-js-vmconformance_interp(interpreter only)built-ins/Datein the built-ins runner after the merge: 573 pass, 21 xfail, 0 fail. Part of the built-ins runner's gain outside these directories comes from running the included harness files andasynctests everywhere.The vendored directories (built-ins runner):
Of the 383 expected failures, 289 are negative parse/early tests (the parser's evidence, not run) and 9 are newer than the pinned edition. The other 85, by reason:
with(WithHasnot in the interpreter yet) 41; theGeneratorFunction/AsyncFunction/AsyncGeneratorFunctionconstructors (CreateDynamicFunction, asFunction) 24;$262.createRealm(one realm) 7;evalmissing 5;wellKnownIntrinsicObjects.jsnot run 4; the unmapped sloppyargumentsobject 2;Function.prototype'scaller/arguments1; BigInt literals 1. So 1,671 of the 1,756 tests that run pass, and none fails.Five tests are new
KNOWN_GAPSentries of the built-ins runner, each for a gap outside this change (eval, the parameter map ofarguments,Function.prototype's restricted properties). The interpreter-only runner classesbuilt-ins/and array iteration (noArray.prototype[@@iterator]there) as needing the built-ins, as theDatebranch does forbuilt-ins/.Checks
cargo xtask verify --part crate clazel-js-vm: Kani 10 of 10 harnesses, Verus 84 verified, 0 errors (83 onmain, plus the new lemma), mutations 237 of 237 killed by a theorem, conformance passed:CRATE PART PASSED.cargo clippy --workspace --all-targets,cargo fmt --check,cargo test --workspace --no-fail-fast(374 test targets, 0 failures) andcargo xtask checkpass.cargo xtask verify --changed(on the merged branch, before the test split): final lineRESULT: FAILED. The only failing step wastests under Miri: every test passed, butstring_match_search_split_replacetook 309.7 s, over the 300 s limit. Every other step passed: Kani (clazel-js-vm10/10,clazel-js-syntax7/7), Verus (clazel-js-lexer386 verified,clazel-js-syntax482, 0 errors), and mutations (clazel-js-vm237/237,clazel-js-lexer28/28,clazel-js-syntax6/6 killed by a theorem;clazel-jit39 killed by a theorem, 5 incidentally, 0 survived).json_parseare now split (commit bd15df1, no case dropped). Under Miri the pieces take 101 to 191 s (json_stringify, unchanged, 201 s). verify has not been rerun since the split.Not done
awaitin modules is compiled (the module body is an async body), butclazel-jsdoes not evaluate modules yet (Scope::evaluate_moduleis not implemented), so it is untested.GeneratorFunction,AsyncFunctionandAsyncGeneratorFunctionconstructors throw "not implemented", likeFunction(CreateDynamicFunction needs the compiler at run time).yield*nest one level per generator and count against the native depth limit (32 by default), past which the resumption is aRangeError.test/language/statements/for-await-of(1,234 files, mostly destructuring) is not vendored.for awaitis covered by the async generator directories and the unit tests.spec.rsis unchanged. The handlers stay tier 0, and Test262 is their evidence, as phase-7.md 7.4 says of handler ops.asynctests as needing the built-ins (it has noPromise).🤖 Generated with Claude Code