Commit graph

10 commits

Author SHA1 Message Date
Sebastian Herrlinger
0e3de44007 refactor(codemode): size compile threads by a conservative nesting scan, not source size 2026-11-19 03:22:37 +01:00
Sebastian Herrlinger
7bddc79372 feat(codemode): keep unpaired surrogates in diagnostics and host failures 2026-11-19 03:02:33 +01:00
Sebastian Herrlinger
9257f8889f feat(codemode): keep unpaired surrogates in the result and the logs (Data, HostString) 2026-11-19 02:53:56 +01:00
Sebastian Herrlinger
6cfcfcf628 feat(codemode): cross strings to the host losslessly, unpaired surrogates included (HostString) 2026-11-19 02:41:41 +01:00
Sebastian Herrlinger
6d7e96a399 refactor(codemode): make the Rust crate the language layer only
The crate becomes the Rust implementation of the reference's language layer (`src/language/`): its public API is
the Rust form of `Language` (`Runtime::make` with `globals(run)`, modules, limits and translation; `HostFunction`
for `Host.fn` with sync, async and sync-thenable types, idempotent, constructible and takes-functions;
`DurableFunction`; `Namespace`; `Failure` for `Host.fail` and `Host.missing`; `Run` with its metadata; programs,
suspend and resume; snapshots). Code Mode (tools, schemas, the catalog, `search`, OpenAPI, hooks, max tool calls,
extensions) is removed, and the language files move from `src/language/` to `src/`.

Host calls follow the reference's language runtime: arguments cross under the runtime's translation (functions and
promises fail the call unless dropped or awaited), a function from a result crosses back only to a function that
takes functions, async and durable calls start at the next handover, sync work can block (`Returned::Block`) or
stay pending (`Returned::Pending`), and a suspend is refused while a call that can't be detached runs. Namespace
paths carry their root label, and their `keys` may fail. Snapshots save the run's metadata and its calls by global
path, and restart them by resolving that path again.

The replays define the generators' host globals (`conformance/reference.rs` shares `tools` with
`conformance/reference.ts`): the cases, `host.json`, `boundary.json` and `streaming.json`. `tests/host.rs` mirrors
the reference's `test/language.test.ts`; the API tests are ported, and the Code Mode tests are removed.
2026-11-19 01:54:11 +01:00
Sebastian Herrlinger
3cf39e761d test(codemode): record unsupported syntax at run time and acorn's parse errors from the reference
Programs in frames/core.ts record, with message and location, unsupported syntax that
runs or is never reached (classes, with, debugger, new.target, import.meta, super,
nested exports), the bindings it hides, using declarations, nested imports, names
located inside parentheses, and parse errors in acorn's words; a suspension reaches
unsupported syntax after resuming. New cases record values around it, and the api
test checks the suggestion, which the recordings do not capture. streaming.json is
to be regenerated at integration.
2026-11-19 00:28:20 +01:00
kommander
54f0d1e41a feat(codemode): hold huge sparse arrays
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.
2026-11-18 18:56:11 +01:00
kommander
d0ea5e8e79 feat(codemode): keep lone surrogates in strings
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.
2026-11-18 18:56:11 +01:00
kommander
03066b4ba3 fix(codemode): delete, arguments, await names and iterator errors match the reference
- delete: optional and parenthesized targets delete; an identifier fails when it runs; built-in constants and prototypes refuse; a function's name and length can be deleted; strings and nullish bases get the reference's errors; tool references refuse.
- arguments: delete leaves a hole, length is a hidden writable property, the binding can be reassigned, and iterating it reads its enumerable own values.
- await is a plain name at the top level unless an expression starts with it, and an escaped await is a label.
- A named function expression's own name is bound before its parameters, so their defaults see it read-only.
- Iterators that break the protocol get the reference's errors everywhere they are opened, stepped or closed, including async yield* over a non-iterable.
- Promise.all, allSettled, any and race reject when their input is not iterable or iterating it fails.
- An accessor in an object literal fails when the literal runs, and export is a parse error, as in the reference.

Drops 77 files from rust-skipped.txt.
2026-11-18 18:56:10 +01:00
Sebastian
f71cdee242 feat(codemode): add embeddable Rust port 2026-11-18 18:53:56 +01:00