Repository navigation
Conversation
Runs the reference's pinned test262 file set, synced by the reference's own script, with the reference harness semantics. test262/rust-skipped.txt lists the files that fail here but pass in the reference; the runner fails on an unlisted failure and on a listed file that passes.
Each bench program gets an equivalent, differently written variant in bench/variants/, run next to its original on both implementations, with the variant / original ratio per side. A plugin-event benchmark runs the conformance reducer with a git.status tool as a 226-byte and a 3 KB source. RESULTS.md labels medians, mins and means, computes speed-ups from medians only, and notes that the reference tools validate through Effect Schema.
Runs fmt, Clippy and the tests including conformance; regenerates every conformance expectation from the reference and fails on a diff; runs the test262 parity check; and runs the benchmarks into the job summary without gating. The toolchain is pinned in rust-toolchain.toml with a minimal profile, and every cargo call is --locked. The workflow file itself follows in a separate commit.
Runs format, Clippy and tests, checks the conformance expectations against the TypeScript reference, runs test262 against the committed gap list, and posts informational benchmarks to the job summary.
The runner now checks the files in the reference's skipped.txt too: those that pass here are gaps on the TypeScript side, listed with a category in test262/reference-gaps.txt. The check fails when an unlisted one passes, a listed one fails here or leaves the reference's skipped.txt, or the reference's own runner, through test262/reference.ts, passes a listed one. Each category says whether Rust really has the behaviour or passes through a looser check where the reference is strict on purpose.
… extensions to the Rust port Tools take validating or render-only JSON Schemas (the Rust form of Effect Schemas and the reference's JsonSchema), render byte-identical TypeScript signatures, and report InvalidToolInput and InvalidToolOutput. Namespaces, freeform tools, the catalog, toolExpression, searchSignature and the BM25 search built-in follow tool-runtime.ts; conformance/catalog.ts regenerates the expectations from the reference. Tools and extension globals may return futures. execute_async runs on any executor; execute drives it with a small built-in block_on, and a shared timer thread enforces timeouts while host work is pending. Dropping a run cancels its calls, which after hooks see as interrupted. Extensions cross values as copies both ways, including functions in results, errors, maps and sets, and programs load them with import, require and import() by Node module name. Runtime::program adds the reference's program API with run ids.
# Conflicts: # packages/codemode-rust/AGENTS.md # packages/codemode-rust/crates/psychoscript/src/lib.rs
… copy path Schema::validated compiles its document into a validator once, so checking a value does no keyword lookups and builds a path only when it fails. A failed host call is boxed, so a successful one stays small in the inbox; synchronous tools share one context; a program compiles when it is made and borrows its source; the run id is made on first use. The benchmark tools now declare the reference's schemas, so tool fan-out also validates each input and output, as the reference does.
Adds host- conformance cases for invalid input, unknown tools, namespaces, search browsing, chaining, validation and counting, and missing modules, with expectations generated from the reference, and Rust tests mirroring the reference's extension tests. HostValue::to_json keeps integral numbers as integers.
A run defines search, require, the import hook and extension globals only for the names its program refers to, and a module import makes the one it asks for. The run id is made the first time a call's key is read.
…Primitive Operators and built-in arguments now call their valueOf/toString like any other object, as JS does: fn + 1 is "[object Function]1" and -fn is NaN. Promises and tool references still reject, so a missing await cannot hide.
EvaluateNew evaluates the callee and its arguments before IsConstructor, so an argument's side effects and throws come first. Bumps the compiler version, since NEW no longer emits a separate check.
PutValue checks the base, so null.x = f() calls f before it throws, and (1).x = f() surfaces f's throw.
…owns the key delete "abc"[5] and delete (1).x are true, as they delete from the wrapper; a string's own index or length still throws in strict mode.
Resolving functions are anonymous, Set.prototype.keys is values, built-in iterators report their kind (Array Iterator, Map Iterator, ...), AggregateError has no own message unless given one, and generator and async functions inherit from their own non-callable function prototypes.
The fast path for an integer in an array answered false for a hole; it now answers only for a present element and leaves the rest to the prototype walk, so forEach, some, and reduce visit an index inherited from Array.prototype.
…ough ToPrimitive The integer arguments of the Array methods, length = object, and the elements a default sort compares call the program's own valueOf/toString, as do String.fromCharCode/fromCodePoint, JSON.parse, and the string iterator's receiver. repeat(NaN) is "", as ToIntegerOrInfinity makes NaN 0.
openapi::from_spec ports OpenAPI.fromSpec: one tool per representable operation with dotted operationIds as namespaces, the reference's skip reasons, readOnly/writeOnly projection solved over reference cycles, OpenAPI 3.0 and 3.1 schema normalization, host-side auth resolution, and request building over an HttpClient trait the host implements. conformance/catalog.ts now also runs the documents of the reference's openapi.test.ts and its fixtures, recording signatures, schemas, skipped operations, and each call's requests, credentials and result; the Rust test replays them with a fake client.
…ce freshness check
A tool returning ToolError::interrupt() stops the run, as a tool interrupting its fiber does in the reference: Program::run, run_async and execute_async end with Interrupted instead of an outcome, calls still running are interrupted with it, and tool.after sees the call as interrupted. The blocking execute keeps its signature and reports an ExecutionFailure.
A rejected promise nothing handles by the end of a successful run becomes a warning in Outcome.warnings, in promise creation order, as in the reference, after completed host calls settle. Warnings get their own output budget and a Truncated marker. The VM side is two hooks in promise.rs: a rejection with no reactions, and a reaction attached to a rejected promise.
…callbacks and iteration Mutating Array methods run the reference's check of what their first write would hit: adding to a non-extensible array, deleting from a sealed one, or writing a frozen one each fail with the reference's message, sealed arrays no longer pop or shift, and reverse leaves a frozen array of fewer than two items alone. sort checks its comparator first and leaves the array as it was when the comparator throws; it used to empty it. Callback methods of Array, Map, Set and Uint8Array.sort name themselves in the reference's 'Array.map expects a function callback.' forEach, map, filter, some, every, flatMap and reduceRight skip indexes a callback cut off by shrinking the array, and includes and indexOf on an empty array return before converting fromIndex. Array.from checks its mapper first, maps an iterable as it reads it and closes the iterator when the mapper throws (an endless iterator ran out of memory), and rejects primitives and promises. Object.fromEntries reads its entries one at a time, closes the iterator on a bad entry, and accepts only entries without opaque references, like the reference. Array.prototype is an array, and an arguments object is never frozen merely by being non-extensible. On top of the array holes: mutating methods check mutability once (push returns at once for an array with no such flags), and an index read past an array's end or at a hole finds Array.prototype's own items, which store an index without interning it. Touches ops.rs (inherited_elem).
localeCompare used a case-folding heuristic that disagreed with the reference on 634 of 4,841 sampled pairs (accents, punctuation, canonical equivalence, scripts). It now uses ICU4X's root collation, which the reference's host uses for its en-US default, and agrees on all of them. Dependency: icu_collator 2.4 with compiled data (pure Rust, Unicode's ICU4X). It adds 1,247,048 bytes to the stripped embed example (4,785,968 -> 6,033,016; bench/RESULTS.md (d) updated); nearly all of that is the root collation table, so generating data for the root locale alone saves under 1 KB.
Strings are UTF-8, which cannot hold a lone surrogate, so every one became U+FFFD: '\ud800' === '\udc00' was true and s[0] + s.slice(1) lost the pair. A string that is not well-formed UTF-16 now keeps its code units behind a flag (Strings::wtf), and its text is a canonical carrier: UTF-8 in which each lone surrogate is U+10FFFF followed by a private-use character that encodes it, and a real U+10FFFF is doubled. Text equality stays string equality, so comparisons, Map and Set keys and property keys need nothing new, and every allocation decodes the carrier, so a high and a low surrogate brought together by concatenation, repeat, padding or replacement become their character. Code that counts or cuts code units reads them through StrRef (length, charCodeAt, slice, comparison, search, split); iteration, String.raw, fromCharCode, JSON.parse escapes, literals and regex matches produce lone surrogates; JSON.stringify and RegExp.escape write them as \u escapes; isWellFormed, toWellFormed, encodeURI (URIError, with the reference's message) and localeCompare see them. localeCompare weighs them as the reference's ICU does, where ICU4X would weigh them as U+FFFD. URL, URLSearchParams, TextEncoder and Buffer's UTF-8 take USVStrings, so a lone surrogate becomes U+FFFD there, as in the reference; Buffer's latin1 and utf16le take the code units. At the host boundary the reference hands its strings over as they are; a Rust host value is UTF-8, so results, tool arguments, logs and diagnostics carry U+FFFD for a lone surrogate, the bytes the reference's own TextEncoder writes for them. Text from the host has a real U+10FFFF doubled on the way in. Snapshots save the carrier and restore it exactly. Instructions (5 iterations) stay within 0.1% on all nine programs; JSON round-trip 1922M -> 1923M, Map/Set 1021M -> 1017M, string building 717M -> 713M. Touches strings.rs, compiler.rs (literals), convert.rs (JSON, host values), host.rs (host values), ops.rs (string iteration), run.rs (diagnostics) and vm.rs (char_str). Eight test262 files leave rust-skipped.txt.
new RegExp reported regress's errors ('Unbalanced parenthesis'), and
regress accepts a few patterns JavaScriptCore rejects, such as \b* outside
the unicode flags. The new regexp_syntax module ports the error checks of
JavaScriptCore's YarrParser as Bun ships it (escapes, classes, v-mode class
sets and string disjunctions, groups and modifiers, quantifiers, named and
numbered references with the legacy reparse), and finds the first error in
the order that parser meets it, with its message ('missing )', 'nothing to
repeat'). regress answers the Unicode questions: property names and the
characters of group names. A random sample of 9,000 patterns over the three
flag modes matches the reference's validity and message for every one.
It also covers \k inside a class with named groups, which the duplicate
named groups rewrite used to check.
An array's numeric read took any integer as an element index, so a[2 ** 32 - 1], which is stored as a plain property, read through to the prototypes and came back undefined. Only indexes below 2^32 - 1 are elements, as the writes already knew. Touches ops.rs (get_elem). Two test262 files leave rust-skipped.txt.
…he reference does Both read their input as iteration yields it, reject an entry that is not an object (Object.fromEntries also one holding an opaque reference) with the reference's message, and close the iterator first.
…e next is not a function Like the reference, stepping an iterator whose next is not a function fails with "<callee> is not a function.", naming the call that made the record: Iterator.from(...) or helpers.map(...) for a helper, which keeps the name (snapshots included), and the running call for toArray, reduce and the other eager methods. An inner flatMap iterator is "The called value".
… top level When the script reparse cannot be used because the program also awaits at the top level, the awaits the reference reads as names (bindings, names inside non-async functions, escaped labels; never inside an async function's parameters or body) are renamed for the module parse to a same-length identifier the source lacks, which compiles as await again. Top-level arrow parameters named await are rejected, as the reference reads them as an expression first.
The reference hands queued host calls over whenever its interpreter returns to its driver loop: at a job, after a synchronous extension call, when a throw unwinds, and when its fuel runs out. The fuel is a fixed step count (10,000: one per back-edge, function call and job, fifty per native call, including the Symbol.iterator, next and return calls of iterators it does not walk itself), not a time slice, so a busy loop sees locked and bodyUsed change at a fixed iteration. The VM now counts the same fuel; its own clock check shares the one hot step budget, so no step pays for two counters. streaming.ts records busy loops of every shape, and a suspend while a fetch result waits undelivered: the reference saves it and fails the resume on the response's bodyUsed accessor, as Rust already did.
The reference keeps an array's elements in a host JavaScript array, which
JavaScriptCore stores sparsely, so a[4294967294] = x works and makes the
length 4294967295. Here a write that far failed with 'Invalid array length'.
An array now turns sparse when a write lands past the longest dense array
(MAX_ARRAY_LEN): its items keep the dense prefix, the SPARSE object flag is
set, and its other elements and its length are its own properties, so
snapshots and reachability carry them unchanged. Element reads and writes,
in, hasOwnProperty, delete, keys, for-in, length (which makes it dense again
once short enough), push, pop, at, slice, includes, indexOf and lastIndexOf
work on it as in the reference, and the callback methods, reduce, flat and
flatMap visit only the elements it holds. Code that walks every element
makes the array dense first and fails with the reference's errors when it
is too long ('Invalid array length', 'Out of memory' for sort), where the
reference either fails or runs on for minutes. Logs show its first
elements. Arrays at most MAX_ARRAY_LEN long, every one the benchmarks make
among them, stay dense and take the same paths as before.
Setting length out of range and spreading too many values now say
'Invalid array length' without a period, as the reference does. Touches
object.rs (SPARSE), ops.rs (element and length paths, define, iteration),
convert.rs, host.rs, web.rs (structured clone), object.rs, buffer.rs.
The last nine test262 files leave rust-skipped.txt, which is now empty.
The reference's Response.json hands lone surrogates from \u escapes to the program as they are. The JSON parser now builds its strings and keys as run text (strings::from_units), and the json method is marked carrier, so its result crosses in without the escaping host text gets; the flag travels with the settlement, snapshots included. The recording adds bodies with lone surrogates, escaped pairs and U+10FFFF, as escapes and as UTF-8.
…built-ins The reference writes the built-ins that call program code in its bytecode prelude, so they spend that bytecode's fuel, not one native call's fifty: one unit to enter a prelude function, one per loop back-edge, fifty per $ helper ($Receiver, $Callback, $Table, String). builtins/fuel.rs holds the units and the prelude's for...of; each built-in spends them in its bytecode's order, since the reference refills its fuel where it runs out. A built-in entered as a prelude function ends with Vm::bytecode_builtin, so its call costs no native fifty; callbacks are called with Vm::call_counted, as bytecode calls them. Covered: the Array callback methods, flatMap and toLocaleString, Array.from, new Map/Set/WeakMap/WeakSet from an iterable, Map and Set forEach, Object.groupBy and Map.groupBy, getOrInsertComputed, the Set composition methods, and Function.prototype.call and apply, which cost their fifty before they hand on. streaming.ts records busy loops over each.
…the rest More built-ins the reference writes in its bytecode prelude, or hands on to it, now spend that bytecode's fuel: the Uint8Array callback methods, Uint8Array.from and new Uint8Array and set from an iterable, sort and toSorted with a comparator (now the reference's top-down merge sort, its merges planned in post-order, so the comparator sees the same pairs in the same order) and the stepped default sort past 4096 values, replace and replaceAll with a callback, JSON.parse with a reviver, Object.fromEntries, Math.sumPrecise, AggregateError, new Headers and new URLSearchParams from pairs, and their forEach. A sparse array's skipped holes cost the back-edges the reference's loops spend on them, counted at once (Vm::fuel_steps). streaming.ts records each.
The reference's iterator helpers are prelude generators and its consumers prelude functions. Making a helper now spends its method, $Direct, $Callback, the generator call, prime and the first next; each next goes on through the generator's loop as its bytecode does: a back-edge when it resumes from a yield or skips an item, flatMap's flattenable and inner loop, take's closing of the record when nothing is left, and closeIterator for a return before the first value. toArray, reduce, forEach, some, every, find and Iterator.from spend theirs; an iterator the reference does not step itself costs its next call. A helper is opened by a for...of or a spread with a call of its Symbol.iterator, and a spread opens a generator so too.
…JSON.stringify walks Two built-ins run the reference's internal bytecode rather than its prelude: Promise.all, allSettled, any and race add their items in $vmCombine, a back-edge each after the native's call; JSON.stringify walks in $vmJsonWalk when it has a replacer or a property list, or meets a toJSON other than Date's and URL's or a promise. That walk costs per value its visit generator, yield* and next, String of an index and $Define of a property; a toJSON or replacer is called as bytecode calls it. A native stringify that meets such a value starts over as the walk, before it calls anything, as the reference's fast path gives up. Headers are a record of their own there: the replacer no longer sees their entries, though a property list still picks among them.
…tives The reference converts an object to a primitive in its internal bytecode ($vmToPrimitive): one unit to enter, and toString and valueOf called as bytecode calls them, fifty for a native one. An operator that converts (arithmetic, relational, bitwise, + and loose equality against a primitive) runs it on both operands once either is an object, a primitive one costing its unit too.
A built-in's back-edge counts for the VM's own checks too, so it is one decrement; call_counted inlines its closure path; reduce walks holes only for a sparse array; JSON.stringify checks for a promise where it already did. Instructions over the nine benchmarks against the commit before the prelude's fuel: array callbacks +0.6%, promise fan-out +2.4%, JSON round-trip +2.0%, the rest within -2.3%..+0.8%.
The reference steps its own iterators and helpers without calling their next, but calls any other iterator's next as bytecode calls it, fifty for a native one.
kommander
force-pushed
the
codemode-rust
branch
from
November 17, 2026 21:49
ef5f4ef to
05daeda
Compare
…rns through its next The reference steps a built-in iterator itself only when it opens the iterable directly. One that a Symbol.iterator method returned goes through ITER_INIT, which keeps the iterator's next and calls it each step, the done step included, for fifty as a native. for-of, spread, destructuring and the prelude's for-of loops now keep that next in the record and call it.
…mConvert does A built-in that needs primitives lists the values (withPrimitives); once one is an object, the reference returns, converts the list in its internal bytecode and runs the built-in again. A call from bytecode has spent the native's fifty by then, before the first conversion; a later list costs the loop's back-edge, and each listed value, a primitive too, a back-edge after its ToPrimitive. A constructing call spends no fifty. The String.prototype methods (receiver and the arguments each reads, then includes, split, replace, match and concat's own lists), fromCharCode, fromCodePoint, raw, String, Number, parseInt, parseFloat, isNaN, isFinite, Math, the Number formatting methods, JSON.parse, the Error constructors, new Date, Date.UTC and the setters, and the array join, toString and integer-argument methods now list what the reference lists, convert it first, and run on the primitives. An array element of join converts through its own toString, as any object does. String.prototype.toString and valueOf convert an object receiver, as the reference's do.
…ables for await and an async generator's yield* step a sync iterable through an adapter. One the reference does not walk itself (a generator, a helper, a custom iterable) it opens in its internal bytecode, entered for one unit, calling the Symbol.iterator method as bytecode does, and each step calls the sync next there: fifty for a generator's or helper's before its body runs, a custom next as bytecode calls it, a built-in iterator a custom method returned through its next. A native Symbol.asyncIterator costs its call. An async generator resumed after an await inside yield* no longer spends the loop's back-edge, which belongs to a resume at the yield, and a call of its next, return or throw from bytecode spends its fifty before the body runs, as the reference's native returns first.
A sort without a comparator lists every defined value for ToString in the reference (withPrimitives), so once one is an object the native's fifty is spent before the conversions, each value costs its back-edge, and the bounded sortDefault past 4,096 values is entered for its unit alone.
…red objects The reference's native JSON.stringify gives up at its 2,048th visit of an object it has seen already, before looking at its toJSON, and starts over as its internal walk with that walk's fuel. The native walk now counts visits: each object it reaches carries the stamp of the walk that last saw it, in padding the object had, so a first visit costs a compare and a store; a stringify nested in another's native walk keeps a set instead. Instructions on the JSON round-trip benchmark: +0.6% against the commit before.
It read the CPU and memory from /proc, sizes with GNU stat, peak RSS with GNU time and cold starts with bash 5's $EPOCHREALTIME. On macOS it now asks sysctl, BSD stat and time, and times cold starts with perl's clock around each run.
bash bench/compare.sh on an Apple M5 Max (macOS 26.7.1, bun 1.4.3), formatted with the repository's prettier.
Since runs can be suspended, every run() takes the resumable flag and checks the run depth to decide whether a back-edge may stop it. A callback a built-in calls (map, filter, sort, reactions) paid that on each call, about 11 instructions, though only a driver's run, flagged resumable_run, can stop. Callbacks now test the flag and run their frames directly otherwise, keeping the run depth counted. Array callbacks, 11 iterations, on top of the prelude's fuel: 3,450M -> 3,445M instructions (-0.2%, three runs); the other eight programs are within noise or slightly lower. Touches vm.rs (call_packed, call_slow).
A tool's or search's arguments and the program's result cross to the host as the reference's boundary crosses them. Plain data takes the fast path, now a port of the reference's: it throws at depth 32, and gives up on a promise, a toJSON of the program's, or the 2,048th revisit of an object. The rest crosses through the reference's internal walk, a heap object here (Kind::Cross), which awaits each promise it meets, calls toJSON as bytecode calls it, and spends what $vmCross and its visit generators spend. A tool call returns its promise at once; its arguments' walk runs inside the call until it awaits, and the call starts once they have crossed, or its promise rejects with the walk's error. The result is crossed in the VM before the run ends, a thenable result awaited first. search(...) from bytecode parks the frames from the nearest async function up to the call while its walk awaits, as the reference parks them, then answers or throws into them; a search that cannot wait there, inside a built-in's callback or a generator, fails instead. A pending walk or parked search is saved with the run and continues on resume. Crossing failures reject or throw the reference's error itself instead of "Invalid input for tool ...". Recorded from the reference in streaming.json: values, errors, ordering, fuel, and suspends while a walk awaits.
The reference's walk throws past depth 100 through $Throw, a native that throws, and a native's fifty is spent only once it returns. Recorded: a busy loop of tool calls whose argument is 101 deep.
The reference's native stringify throws past depth 32 and its internal walk, with a replacer or a property list, past 100, a primitive included: RangeError "Value exceeds the maximum depth of N.". Rust allowed 512. Recorded in the std-json-stringify-depth case and a busy loop of failing walks.
This branch has not been 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.
Issue for this PR
None.
Type of change
What does this PR do?
Adds
packages/codemode-rust(cratepsychoscript), a second implementation of Code Mode that Rust programs embed without Bun or Node: parser (oxc_parser), bytecode compiler and stack VM, with the host API of the TypeScript package in Rust form (schema tools as functions or futures, OpenAPI tools, the catalog andsearch, hooks, extensions, programs, suspending and resuming runs, limits).packages/codemodestays. The rule is parity in both directions: a language feature, built-in or host API lands in both packages or in neither. Rust-native forms of a reference API (futures for Effects) are fine; Rust-only capabilities are not. Every expectation is generated frompackages/codemodeand never edited by hand, and that includes when queued host calls start in a busy loop, because the Rust VM spends the reference's fuel.Known difference: a
search(...)whose input holds a promise waits for it by parking its caller's frames, as the reference does, but inside a built-in's callback (such asmap) or a generator Rust cannot park them, so it throws there instead.Results from
bench/RESULTS.md(Apple M5 Max, againstpackages/codemodeon Bun 1.4.3):return 1Follow-ups (not in this PR)
How did you verify your code works?
bash test262/run.sh);test262/rust-skipped.txtandtest262/reference-gaps.txtare empty.packages/codemode; the cases also pass when every run is saved and restored at each host stop (PSYCHOSCRIPT_ROUNDTRIP=1).cargo fmt --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepass; the Rust checks run in theunitjob ofcheck-test.ymlwhenpackages/codemodeorpackages/codemode-rustchange.Screenshots / recordings
N/A
Checklist