Commit graph

43 commits

Author SHA1 Message Date
Sebastian Herrlinger
8943a0a540 test(codemode): bound the streaming busy loops by wall-clock time, so a resumed run leaves them at once 2026-11-19 02:17:01 +01:00
Sebastian Herrlinger
5208cfd308 test(codemode): record streaming and crossings through the reference's language runtime 2026-11-19 01:53:45 +01:00
Sebastian Herrlinger
e072d3c69c test(codemode): regenerate the streaming recording with unsupported syntax at run time 2026-11-19 00:29:56 +01:00
Sebastian Herrlinger
fcc9ebcd46 test(codemode): record unknown-tool suggestions and regenerate the streaming recording 2026-11-18 23:55:55 +01:00
Sebastian Herrlinger
a0ab788627 fix(codemode): refuse calling the namespace itself and hide an uncaught value that isn't data
Left over from the boundary sweep, outside its files: tools() fails with
tools is not a function, delete with a number or symbol key on a
namespace fails as reading one does, and a thrown value that holds a
function, a promise, a namespace or a built-in object, at any depth,
fails as Uncaught: a non-data value, as the reference's
containsRuntimeReference has it.

Recorded: boundary-namespace-calls and six uncaught values.
2026-11-18 23:11:59 +01:00
Sebastian Herrlinger
505a33d1e6 test(codemode): regenerate the streaming recording with the boundary fuel programs 2026-11-18 23:05:18 +01:00
Sebastian Herrlinger
eea63a8980 test(codemode): regenerate the recordings with dev's extension and host-call cases 2026-11-18 21:55:08 +01:00
Sebastian Herrlinger
462f1b82c8 test(codemode): regenerate the recordings from the rebased reference
The reference now carries dev's changes: tool and search arguments cross
through the host-call path (functions dropped, promises awaited, toJSON
not called), imports that can't resolve say why, namespace references are
no longer called tool references, extension arguments are passed to the
host, and an un-awaited promise's hint names load(...). The suspension
that started tools.wait inside a toJSON in tool arguments is removed: the
reference no longer calls that toJSON, so the wait never starts.

The Rust side follows in the commits after this one.
2026-11-18 20:50:32 +01:00
Sebastian Herrlinger
ff703af7d0 test(codemode): keep one busy-loop fuel case per cost rule 2026-11-18 18:56:14 +01:00
Sebastian Herrlinger
1361c6f9a1 chore(codemode): write conformance recordings one entry per line 2026-11-18 18:56:14 +01:00
Sebastian Herrlinger
d507a5971a test(codemode): record the call depth limit and its RangeError
The deepest level and the error there, with one frame per level (plain,
method, call, apply, generator, async, and built-ins calling the
recursing function back: map, forEach, toString, replace, toJSON,
Array.from, reduce, sort), two frames and three, probed from the
program's top level; exactly the limit succeeding while one more level
fails; and the uncaught RangeError with its location.
2026-11-18 18:56:14 +01:00
Sebastian Herrlinger
7c7c332639 test(codemode): record conversions with no primitive to give 2026-11-18 18:56:14 +01:00
Sebastian Herrlinger
e73f2595a0 feat(codemode): resume a sync generator's throw and return from the async adapter's frame
for await and an async generator's yield* over a sync generator called
its own throw and return from Rust, through call_counted: the adapter's
frame now calls them, counted as before, and closes a generator without a
throw through its return for nothing, so a search in the generator's
catch or finally parks.

Recorded: search parking in a sync generator's finally and catch under for
await and an async generator's yield*.
2026-11-18 18:56:14 +01:00
Sebastian Herrlinger
161cc82bb4 test(codemode): record fuel of abrupt requests through yield* and for await closes 2026-11-18 18:56:13 +01:00
Sebastian Herrlinger
64be1f3c2d feat(codemode): park a search inside the program result's toJSON
The program result's crossing runs in a native frame at the base of the
run, which a search(...) inside a toJSON there now parks with a fresh
coroutine, as a promise job's frame does.

Recorded: search parking inside a toJSON in tool arguments, in search
input and in the program's result.
2026-11-18 18:56:13 +01:00
Sebastian Herrlinger
e077d7a261 feat(codemode): park a search inside an async generator's frame
An async generator runs from native code, so its frame is a run's base: a
search(...) inside it, or in what its yield* or for await calls, now parks
the generator's frame and those above it with a fresh coroutine, the VM
going back to the resumer's stack as the generator's await does, and the
generator taking the resumer's stack again when they are restored.

Recorded: search parking under yield* over the program's iterator, in a
delegated generator's return() and throw(), in for await over a
generator, and in async generators.
2026-11-18 18:56:13 +01:00
Sebastian Herrlinger
71de7331cb test(codemode): record search parked inside running sync generators 2026-11-18 18:56:13 +01:00
Sebastian Herrlinger
a7d43a320a feat(codemode): convert with the program's valueOf and toString in native frames
A conversion that would call the program's valueOf or toString no longer
calls it from Rust, as the reference converts in its internal bytecode:

- A built-in called from bytecode converts with conversions restartable: one
  that calls the program records its request instead, and a convert frame
  runs ToPrimitive as calls, then runs the built-in again with the answers
  replayed in order ($vmConvert). A built-in's list of conversions is one
  request answered with the whole list, so state it kept in the list (a
  Date setter's time) is the one read before the conversions.
- An instruction whose operand converts by calling the program hands the
  operation to a convert frame, which runs its slow path the same way and
  gives the result back as the instruction would, a jump included.
- A sort comparator's, a replace callback's and toLocaleString's result is
  converted from their frames.

A replay rewinds the fuel it spends until it takes its last answer, and
starts no queued host calls meanwhile, so the fuel and its order are those
of the conversions made inline. A message that converts a value and
ignores a failure converts it inline, never leaving a request behind.

Recorded: search parking in each kind of conversion, a Date setter whose
argument changes the date, a suspension inside valueOf, and busy loops
through converting operators and built-ins.
2026-11-18 18:56:13 +01:00
Sebastian Herrlinger
d6709ca88d fix(codemode): leave a native frame's handlers to the VM when a generator ends
native_resume no longer pushes a handler itself: the frame that resumes a
generator with return or throw pushes one, as the families' helpers do, and
the VM drops a native frame's handlers when it receives a throw or a
generator's completion, so a step never pops a handler that is not its
own. An iterator helper popped one on a generator's completion, which took
the try handler of the frame below once the VM dropped its own; a throw
from a helper's callback over a generator then escaped every catch.

Regenerates conformance/streaming.json with the families' cases.
2026-11-18 18:56:13 +01:00
Sebastian Herrlinger
c2f375aaea test(codemode): record streaming programs independent of machine speed 2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
3f11192225 feat(codemode): run JSON revivers and call/apply in native frames
JSON.parse with a reviver walks the parsed value from a native frame, its
recursion kept as a stack of levels in the frame's slots, and
Function.prototype.call and apply call their function from one. A native
frame's calls are named for the bytecode frame below it, as a built-in
that called from Rust named them.

Recorded: search parking inside a reviver, call and apply.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
38be59b00c feat(codemode): run iterator consumers in native frames
forEach, some, every, find, toArray and reduce of Iterator.prototype run on
the for-of driver from the iterator's record: a callback that throws or
decides closes the iterator, a built-in iterator, generator or helper is
stepped as the reference steps its own, and any other next is called from
the frame. A next that is not a function fails before the first step, as
it did.

Recorded: search parking inside each of them.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
ddf53d8020 feat(codemode): run more callback built-ins in native frames
Map and Set forEach (visiting entries added while it runs),
URLSearchParams and Headers forEach (on a generic frame over a fixed list
of calls), flatMap, Array.from over an array-like with a mapper,
toLocaleString, Object.groupBy and Map.groupBy (on the for-of driver), and
replace and replaceAll with a callback (string and RegExp patterns, the
matches found first as the reference's replaceWith receives them) now run
their callbacks from native frames.

A frame's caller no longer keeps a bytecode-builtin flag set before the
frame was pushed: the frame says how its call ends when it finishes.

Recorded: search parking inside each of them.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
132b030900 feat(codemode): run sorts, iteration and promise jobs in native frames
A sort with a comparator keeps its values, merge buffer and plan in its
frame's slots and makes one comparison per step. Array.from over an
iterable and new Map/Set(iterable) run on a shared for-of driver that
opens, steps and closes the iterator as the reference's prelude loop does:
a custom iterator's next and return and a Symbol.iterator method are calls
from the frame, and a generator is stepped without a nested run (a new
Resume::Native mode hands its yields to the frame and marks its end in the
frame's pc).

Promise handlers, finally cleanups, thenable jobs, executors and
Promise.try callbacks run in a Settle frame, entered at the reference's
cost. A job's frame is the base of a resumable run, so a handler can
suspend, and a search(...) inside one parks the job's frames with a fresh
coroutine, as the reference parks a job that has no async function.

Recorded: search parking inside each of them, and suspending while a then
handler runs a busy loop or waits in a parked search.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
5174c6aea8 feat(codemode): run array callbacks in resumable native frames
A built-in that calls back into the program now pushes a native frame
instead of calling the callback from Rust: the frame keeps the built-in's
state in its slots, and the dispatch loop runs its step function whenever
the frame is on top. A step asks for a call, whose frame the loop pushes
above it as a call instruction would, or finishes with the built-in's
result. No Rust frame waits on the callback, so the callback can park for
search(...), suspend and be saved in a snapshot like any other frame, and
recursion through a callback reaches the reference's depth (native frames
do not count toward it, as the reference's internal code does not).

forEach, map, filter, some, every, the find methods, reduce and
reduceRight are the first built-ins to use it. Their steps work on packed
slots, so a callback costs what it did.

Recorded: search parking inside each of them, and suspending while one's
callback runs a busy loop or waits in a parked search.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
36a9080b98 fix(codemode): enter promise handlers at the reference's cost
The reference enters a promise reaction's handler, a finally cleanup, a
thenable job's then, an executor and a Promise.try callback without a call
(enterSettlingCall): a plain function's frame costs nothing beyond the job,
and a promise's resolve function nothing; anything else goes through
$vmSettleCall, so an async or generator function costs a call and a native
fifty. Rust charged every closure a call and every native nothing, so a busy
loop through rejected tool calls, or any then, refilled fuel at another step.
Promise.try spends its fifty before the callback runs, as the native returns
first.

A finally cleanup's outcome now passes through one more promise, a job
later, as the reference chains finallyCleaned and finallyOutcome.

Recorded: busy loops through invalid and failing tool calls, an unknown
tool, and each kind of handler, and the order of finally against other jobs.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
a7f1c106a1 fix(codemode): JSON.stringify stops at the reference's depths
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.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
c06b887222 fix(codemode): a crossing's depth error costs no fuel
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.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
6f7986e591 feat(codemode): await promises nested in what crosses to the host
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.
2026-11-18 18:56:12 +01:00
Sebastian Herrlinger
d96b76b094 fix(codemode): stringify through the walk after 2,048 revisits of shared 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.
2026-11-18 18:56:11 +01:00
Sebastian Herrlinger
572aa2e0de fix(codemode): convert the default sort's values as one list
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.
2026-11-18 18:56:11 +01:00
Sebastian Herrlinger
2cab125547 fix(codemode): spend the reference's fuel in for await over sync iterables
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.
2026-11-18 18:56:11 +01:00
Sebastian Herrlinger
f66f9b6523 fix(codemode): convert a native's listed values as the reference's $vmConvert 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.
2026-11-18 18:56:11 +01:00
Sebastian Herrlinger
b7d45bc99d fix(codemode): step a built-in iterator a custom Symbol.iterator returns 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.
2026-11-18 18:56:11 +01:00
kommander
fc824d42c7 fix(codemode): a custom iterator's native next costs a call
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.
2026-11-18 18:56:11 +01:00
kommander
b9faee4c01 fix(codemode): spend the reference's fuel converting objects to primitives
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.
2026-11-18 18:56:11 +01:00
kommander
904a3f7487 fix(codemode): spend the reference's fuel in Promise combinators and 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.
2026-11-18 18:56:11 +01:00
kommander
102a3b1c4f fix(codemode): spend the prelude's fuel in the iterator helpers
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.
2026-11-18 18:56:11 +01:00
kommander
7d3902f066 fix(codemode): spend the prelude's fuel in sorts, bytes, replace and 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.
2026-11-18 18:56:11 +01:00
kommander
8ce9b4d271 fix(codemode): spend the prelude's fuel in array, collection and set 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.
2026-11-18 18:56:11 +01:00
kommander
22e185b8bd fix(codemode): keep lone surrogates in a streaming response's json()
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.
2026-11-18 18:56:11 +01:00
kommander
85ad9512cb fix(codemode): start streaming reads where the reference's fuel runs out
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.
2026-11-18 18:56:11 +01:00
kommander
a5b41a572c feat(codemode): stream HTTP responses to programs through extensions
HostValue::Response carries a StreamingResponse whose body the host streams
through the HttpBody trait (poll_chunk, cancel), with no HTTP crate. The
program gets what the reference's fromHost makes of Extension.StreamingResponse:
the response fields, a live bodyUsed, text/json/bytes/arrayBuffer, and a body
with a live locked, cancel, getReader and async iteration. Reading, locking,
cancelling and json() follow the reference's host runtime, its error messages
included. Reads and cancels take effect where the reference starts queued
calls: at the next job or after a synchronous extension call.

Live accessors are a small Kind::Live hook: own, read-only, non-enumerable
and deletable, and otherwise an ordinary object. A snapshot keeps them only
while the run can reach them, and then the resume fails as in the reference;
reach.rs marks what is reachable. A lost host function now throws at the call
with its location, naming an unnamed one (anonymous).

conformance/streaming.ts records the reference with a fake streaming fetch,
since it has no tests of its own here; tests/streaming.rs replays it.
2026-11-18 18:56:10 +01:00