Commit Graph
6750 Commits
Author SHA1 Message Date
Chris Tate 48a08dce8e Store arrays of ProgramLifetime instances in 4-byte slots on Linux (#1847) 2026-10-22 16:29:42 -05:00
Chris Tate d2408a09ad Match Node for reduce accumulators and callback arguments.length (#1828) 2026-10-22 16:27:50 -05:00
Chris Tate f45d8ba6dd Version while loops over typed arrays on their counters' bounds (#1841) 2026-10-22 16:27:30 -05:00
Chris Tate 7ef356137f Read the union payload inline when comparing it with a number or boolean (#1839) 2026-10-22 16:26:44 -05:00
Chris Tate e74bd658fd Inline Map retains and Map.size in release builds (#1862) 2026-10-22 16:24:56 -05:00
Malte UblandClaude Opus 5.5 73ab5b8d7f Run the libnode smoke test only on built packs; stamp the packs 0.4.2
CI's island lanes fall back to the development pack (dev-pack.json: Node
24.22.1, no package.json) until the libnode-packs cache exists, so the
smoke test, which verifies a @scriptc/libnode-<platform> package against
the 24.22.0 pin, failed there. It now runs only when SCRIPTC_LIBNODE names
a package directory. The pack package versions follow the 0.4.2 release
(scripts/sync-versions.mjs), which pin.test.ts checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 14:23:02 -07:00
Chris Tate 41af221ed1 Version functions on number parameters that bound their loops (#1853) 2026-10-22 16:21:01 -05:00
Malte Ubl fb0d7a99a8 Merge remote-tracking branch 'origin/ni/1-libnode-loader' into ni/13-libnode-packs 2026-10-22 14:17:35 -07:00
Malte Ubl 694d34bb44 Merge remote-tracking branch 'origin/ni/1-libnode-loader' into ni/3-hosted-loop 2026-10-22 14:17:32 -07:00
Malte Ubl 13b00dd78b Merge remote-tracking branch 'origin/main' into ni/1-libnode-loader
# Conflicts:
#	packages/compiler/src/frontend/lowering/lower-modules.ts
#	tests/harness/differential.test.ts
#	tests/harness/linux-differential.test.ts
#	tests/harness/llvm-differential.test.ts
#	tests/harness/windows-differential.test.ts
2026-10-22 14:10:07 -07:00
Chris Tate 14098794d0 Type the scenario promises of corpus 7119 and 7380 with JSDoc
tsgo rejects a call of `resolve()` without an argument when the
`new Promise()` that produced it has no type, and asks for a JSDoc hint;
tsc-ts accepts it. The two programs compiled under tsc-ts only, so the
checker-identity check failed on them. Each scenario function now
declares `@returns {Promise<void>}`, as corpus 1594 does. Their output is
unchanged.
2026-10-22 15:46:43 -05:00
Chris Tate 5c29845909 Support Readable.fromWeb over web ReadableStreams 2026-10-22 15:23:28 -05:00
Chris Tate 4d049fbb8c Merge pull request #1850 from vercel-labs/ctate/prepare-v0-4-37aaa7
Prepare v0.4.2 release
v0.4.2
2026-10-22 15:09:47 -05:00
Chris Tate f4365b7eea Cache each constant method name's id in a slot
A checked-dynamic method call looked its name up in the method table on
every call: a strlen, a hash and a byte comparison of the name.

The compiler now gives each method-name constant an i32 slot that starts
at -1 and passes it with the call (scr_dyn_invoke_prepared_id, and the
Buffer method entries, which forward it). The first call stores the
name's id in the slot, and later calls read it. Ids stay the runtime's
own, so the slot holds whatever this runtime's table says. Names are
still matched by content on the first call, and the slot is written with
a relaxed atomic store, since every thread writes the same id.

The runtime ABI is now 28.
2026-10-22 15:02:41 -05:00
Chris Tate f7ef188d96 Give the sanitized bootstrap seed job swap (#1864) 2026-10-22 14:34:41 -05:00
Chris Tate 5aae5531e0 Give the sanitized bootstrap seed job swap
The sanitized seed compiles the compiler's 700 MB LLVM module with one clang
process under AddressSanitizer. The compile peaks near 14 GB while the Node
process that emitted the module still holds about 6 GB, which exceeds the
runner's 16 GB of memory. The job now enlarges swap to 24 GB before it builds
the seed, as the sanitized emitter job does.
2026-10-22 14:30:37 -05:00
Chris Tate f5a3faf18d Bound the compiler's cyclic garbage to twice its live heap
The cycle collector widens the growth fraction that schedules full passes
up to 16 times the heap left by the last pass while passes find little.
Lowering a large program leaves hundreds of megabytes of cyclic garbage,
and whether a scheduled pass reclaims it before the build's peak depends
on where the growth rule fires: small changes to the compiler moved the
peak of a tsc-ts build between 1.66 and 2.05 GB.

The native compiler now sets the growth cap to 2 at startup, as
SCR_CYCLE_GROWTH_CAP=2 does, so a full pass runs once the heap has grown
to three times its size after the last one. scr_cyc_set_growth_cap sets
the cap for a program from its own code; the environment variable still
takes precedence, and child processes are not affected.
2026-10-22 14:25:55 -05:00
Chris Tate 18c2900937 Read web ReadableStreams as async iterable stream sources 2026-10-22 14:20:01 -05:00
Chris Tate 83b2b34b6e Inline Map retains and Map.size in release builds
Release builds no longer import runtime bitcode, so program code called scr_map_retain_v for every Map read out of a container and scr_map_size for every size read. A Map retain now uses the emitted increment helper, as string retains do, and Map.size reads the live count through an internal helper.
2026-10-22 14:19:04 -05:00
Chris Tate fbe4067b3b Skip emitter analysis walks whose answers are already known
The LLVM emitter's constructor walks the whole module about 33 times.
Several walks repeat work another already did, or run where the result
is provably empty:

- computePublishedTypes and computeCycleMutability run once and are
  shared (may-throw, immutable fields and traced shapes took their own).
- The WebCrypto-asymmetric and Ed25519 runtime-feature conditions join
  the feature scan's one walk instead of walking the module again.
- int32 slots: the fixpoint skips the write walk of a function without
  a candidate write, dynamicFieldStores stops once every field name is
  dynamic, and dynamicallyStoredFamilies returns early when no f64
  field can be named by a dynamic store.
- stableGlobals stops once no candidate is left, the second pass of
  findAppendedArrayLiterals and the target resolution of
  findConstantCallbacks run only when there is something to find,
  boxedUnionIds needs unions, and observesStacks walks for call sites
  and the "stack" literal only when a dynamic key asks.
- everyModuleNode visits type trees without a closure per node.

The emitted LLVM IR is unchanged.
2026-10-22 14:15:29 -05:00
Chris Tate d83c676705 Store compact values of string-key maps in 4-byte slots on Linux 2026-10-22 14:08:00 -05:00
Chris Tate ba80dc254d Iterate classes with object-literal iterators and close them on early exits 2026-10-22 13:56:21 -05:00
Chris Tate b074a5e20f Test for-in key presence in the overflow map instead of a fresh key list
for-in over a pure index-signature record (`Record<string, number>`) skips
keys deleted during the walk by testing each snapshotted key for presence
before visiting it. The test built the overflow map's whole key list and
searched it with includes() on every visit, so a walk over n keys took
O(n^2) time: 200 walks over 2000 keys took 8.7 s, against 31 ms under
Node. The test is now recordOvfHas, the overflow map's hashed presence
check, which answers the same question in constant time.

The new benchmark workload dictionary-walks walks, prunes and merges
Record<string, number> dictionaries with for-in and Object.keys/values/
entries. It takes 7.1 s before this change and 23 ms after (Node 116 ms).
Corpus program 7011 pins for-in's visit order and its handling of keys
deleted, re-added and added during the walk.
2026-10-22 13:49:49 -05:00
Chris Tate d8d75dfa18 Support Duplex.from over streams, pairs, promises and async functions 2026-10-22 13:32:25 -05:00
Chris Tate 27bc23b3c2 Include the refreshed optimization profile in v0.4.2 2026-10-22 13:24:44 -05:00
Chris Tate 8d4ee22009 Refresh the native compiler's optimization profile (#1858) 2026-10-22 13:23:05 -05:00
Chris Tate e39ddf3d00 Refresh the native compiler's optimization profile 2026-10-22 13:18:04 -05:00
Chris Tate dc9b60656d Index arrays with exact i64 products of int32 values
`a[i * n + k]` with int32 operands kept the index in doubles whenever the
product's range could pass 2^53: integer arithmetic needs a proven safe
range, and an int32 product can reach 2^62. Every access then converted
the double back with an exactness test.

Such arithmetic now also carries a wide view: the exact integer as an
i64, the magnitude it is bounded by, and a threshold below which the
double equals it. A product of two exact integers equals its double below
2^53 in magnitude, and a sum or difference of a wide view exact below T
and an exact integer of magnitude at most B equals its double below
min(T - B, 2^53). Every i64 result stays within 2^62 + 2^53, so none
wraps.

An array index below a length or capacity is below 2^32, under every
threshold kept, so the dense array guards and local array reads compare
the wide view, unsigned, with the array's counts and skip the round trip.
Any index that fails those comparisons, including every index whose double
rounds, takes the double's path as before. Typed arrays and strings are
unchanged.
2026-10-22 13:11:34 -05:00
Chris Tate 8f08cbbec5 Build Sets, Maps and weak collections from checked-dynamic iterables
`new Set(x)`, `new Map(x)`, `new WeakSet(x)`, `new WeakMap(x)` and
`Object.fromEntries(x)` now accept any checked-dynamic iterable, as in
Node: a native iterator (`map.keys()`, `set.values()`), a compiled
generator, an object with a Symbol.iterator method, or a Set. Before, a
Set seed that was not an array or a string threw "is not iterable", and a
Map, weak collection or Object.fromEntries seed that was a generator or a
collection other than a Map refused with SC2020.

The runtime drains native iterators, packs arrays, strings and
collections, and steps every other iterable through its iterator
(scr_dyn_seed_values). A program that builds these from an untyped seed
registers the compiled generators' next and return methods with the
runtime, as destructuring rest already did, so a generator seed can be
stepped.

The seed's values are all taken before the first one is added, so when an
entry of a Map seed is not an object the TypeError comes after the
iterable is exhausted; Node closes the iterator at that entry. The
limitations page says so.
2026-10-22 13:09:01 -05:00
Chris Tate b4a3bace60 Read compact array slots in dense loop fast copies, and their flag only on 64-bit targets 2026-10-22 13:08:42 -05:00
Chris Tate 35f2d8f791 Report dictionary copies of {} views, and keep method calls direct after writes into dictionaries of dictionaries
Fixes #1408
Co-authored-by: Chris Ainsley <c.b.ainsley@gmail.com>
2026-10-22 13:07:47 -05:00
Chris Tate ef8ee2b393 Emit a debug build's function bodies in one emitter
Debug metadata is numbered per emitter (debug-info.ts) and the range
journal does not carry it, so a debug build emitted in ranges or on
workers referred to metadata the merged module did not define. Debug
builds now emit every function body in the emitter itself.
2026-10-22 13:03:33 -05:00
Chris Tate 317ec98fa5 Close async generators on early for await exits and iterate untyped native streams 2026-10-22 12:31:21 -05:00
Chris Tate 83d426f9be Support FinalizationRegistry with bookkeeping and no cleanup callbacks
wasm-bindgen output constructs a FinalizationRegistry per exported class
when its module loads, so every wasm-bindgen package stopped at load with
SC2020. `new FinalizationRegistry(cleanup)` now creates a native registry:
- register(target, held, token) and unregister(token) check their
  arguments and answer as Node does, with Node's TypeError messages;
- the unregister tokens are keys of an internal weak map, so the registry
  keeps no token alive;
- the cleanup callback never runs, which ECMAScript allows, so the
  registry keeps neither the callback nor the held values.
The global answers typeof "function", instanceof, Object.prototype.toString
and util.inspect as Node does. Symbol targets and tokens are refused with
SC2020.

`"encodeInto" in encoder` on a TextEncoder, which wasm-bindgen's loaders
test at load, answered false because the encoder is a brand record without
fields for its methods. `in` over such a builtin brand record now answers
from the members the standard library declares, plus Object.prototype's.

The limitations page says that memory a package frees only from a cleanup
callback, such as the WebAssembly memory behind wasm-bindgen wrappers the
program drops without free(), is not reclaimed until the program exits.

Fixes #1678.
2026-10-22 12:14:23 -05:00
Chris Tate a6427a53c0 Find own toString assignments in the syntax tree, not the file text 2026-10-22 12:10:51 -05:00
Chris Tate 7ed4597407 Match the speculative loop site global by its numbered-site name in the bail test 2026-10-22 11:59:49 -05:00
Chris Tate 9e1027e13a Run async generator steps in the AsyncLocalStorage context of their resumer
An async generator kept the context of its creation for its whole life,
and a store its body entered carried into every later step. Node runs
each step in the execution that resumes it: a step starts with the
context of the next(), return() or throw() call, a store it enters
before its first await is the caller's after the call, and after an
await the step continues in its own copy.

Async generators now start each new step from the resumer's context and
hand the prefix's context back at the step's first suspension, as
synchronous generator steps and async function prefixes already do; the
continuation after an await keeps the generator's own. Two requests that
start from the settlement job, which runs from the loop, take Node's
contexts too: a request queued behind a running step starts in that
step's context, and a return() at a yield, whose unwind waits a turn,
runs in the return() call's context.

Corpus 7381 and 7382.
2026-10-22 11:46:44 -05:00
Chris Tate 6681b9407e Version functions on number parameters that bound their loops
A number parameter that every call site proves an int32 reaches the
function's i32 entry. One that some caller passes as an unproven number,
such as a value read from a worker message or parsed from text, kept its
double, so every loop it bounds compared an integer counter with a double
limit and the values derived from it stayed doubles.

When such a parameter bounds a numeric loop (arithmetic, element and
field reads and writes, Math calls, no allocation or other calls), the
function now gets a copy of its body. Its own body first tests
each such parameter for an int32 that is not -0 and, when all pass, calls
the copy with `p | 0`, the same double. The copy's only caller proves
those parameters int32s, so it gets the i32 entry and integer loops.
Other values run the body as before.

Only plain synchronous functions of at most 2048 IR nodes are versioned:
not class members or generated helpers, not capturing, not the entry,
not dynamic-tier, not calling themselves, and at most 16 per module. A
function holding the only call site of another function is kept whole
unless that callee only computes a number or boolean from scalar reads:
a second call site can stop LLVM from inlining the callee and leave the
records it builds in memory. Library builds and modules that observe
call stacks are left as they are.
2026-10-22 11:46:21 -05:00
Chris Tate 972e44a11a Hold any later value in JavaScript properties initialized to undefined or null
A JavaScript object literal's property whose initializer is `undefined` or
`null` (`[{ oldPos: -1, lastComponent: undefined }]`, `{ user: null }`)
mapped to the unit-only union, so a later write of another value threw:
the diff package's diffLines failed with "a '{ added: boolean; count:
number; previousComponent: unknown; removed: boolean }' value is not
representable in the target union" when it stored its first path
component. Nothing checks a JavaScript file's writes, so such a property
is now checked-dynamic and holds whatever the program stores. TypeScript
properties keep the unit-only union, and `__proto__: null` still sets the
prototype.
2026-10-22 11:40:01 -05:00
Chris Tate eace8e1a17 Give the zod 3 npm case the long per-case timeout 2026-10-22 11:31:36 -05:00
Chris Tate e5b2e62b45 Emit function bodies on forked workers that merge into one emitter's text
On hosts that can fork, the native compiler now emits a large module's
function bodies on worker processes (SCRIPTC_EMIT_WORKERS, 4 by default).
The function list splits into contiguous ranges, each emitted by a forked
child of the emitter, and the ranges merge in function order into the text
one emitter gives. A range whose worker fails is emitted in the parent.
Modules under 2,000 functions, Node and Windows keep the serial path.

A range's emitter records an ordered journal (emit-journal.ts):

- every helper it numbers from a counter (the dyn conversions and
  matchers, message listeners and readers, JSON writers, publication
  walkers, stream adapters and resolve thunks), recorded when its number
  is taken, with the entry point and arguments that create it;
- the first request of each key of a module-level table (declarations,
  literals, C strings, unit and absent instances, retype guards, regex and
  template-strings instances, map descriptors, alias tags) made outside a
  helper's definition;
- unkeyed sites (inline caches, speculative loop sites) taken outside a
  definition. A speculative loop site's global is now `@sc_spec_bails_N`,
  named like the other numbered sites.

The merging emitter replays each range's journal in order. Replay calls
the same entry points, so every helper gets the number and definition the
serial emission gives it, and table entries land in the serial order. The
range's text is then renamed to the merged numbers in one pass. Sets and
flags the ranges set (await callees, function values, RC helper requests)
merge after the replay. LlvmTargetOptions.functionChunks runs the same
merge in one process, for tests.

The fork, exit, wait and lock primitives come from the native host
(host.c, process-fork.ts); the native compiler passes them to the emitter
as LlvmTargetOptions.forkPrimitives.
2026-10-22 11:25:30 -05:00
Chris Tate 7cce36354f Dispatch checked-dynamic method calls on method ids
A method call on a value of unknown type (untyped JavaScript, `any`)
picked its builtin by comparing the method name with strcmp against each
candidate, in long ladders per receiver kind: a string method could test
dozens of names before it matched.

- The name is now looked up once per call in a generated hash table
  (scr_dyn_methods.h, from scripts/gen-dyn-methods.mjs), and each ladder
  compares the resulting id. The table verifies the name's bytes, so a
  name is matched by its content, as before.
- The worker event methods compare the first character before strcmp.
- bench/dynamic-methods calls string, array, Map, Set, number and own
  methods from untyped JavaScript.
2026-10-22 11:21:10 -05:00
Chris Tate f37dca56f0 Merge main 2026-10-22 11:20:04 -05:00
Chris Tate fd40a8c84a Try each PATH entry with exec when spawning with a replacement env
The PATH lookup for spawns with an `env` option picked the first
executable regular file and stopped there, so a script whose interpreter
is missing ended the search with ENOENT. Node's libuv runs execvp in the
child, which moves on to the next PATH entry when an exec fails with
ENOENT, ENOTDIR or EACCES. Each candidate now runs through posix_spawn in
order with the same rule, and relative entries are resolved by the child
in its cwd.
2026-10-22 11:18:30 -05:00
Chris Tate 74fcda0ad9 Evaluate every Promise.all entry before a dynamic entry's then lookup
A checked-dynamic entry's PromiseResolve reads its `then` property,
which can be a getter. The tuple form resolved each entry as the array
was built, so that getter ran before later entries evaluated; Node
evaluates the whole array first. With a checked-dynamic entry, every
entry now evaluates into a hidden local before the entries resolve.
2026-10-22 11:17:42 -05:00
Chris Tate 9aaebbab25 Prepare v0.4.2 release 2026-10-22 11:14:27 -05:00
Chris Tate 65a68470cf Free a typed teardown's blocks in the order it met them
A typed teardown freed each block onto its free list as it went, and the
free lists, which are LIFO, handed a torn-down structure's blocks to the
next allocations in the reverse order. A structure that a loop rebuilds
the same way each time was therefore laid out mirrored every other
generation, and every walk over it, its teardown included, ran through
memory backwards, which the hardware prefetchers handle three to four times
worse. A program that rebuilds a tree of 2^21 - 1 object literals 12
times, summing each generation before dropping it, took 26 to 28 ns per
node to build, 24 to sum and 16 to drop in those generations, against
6.8, 6.3 and 5.3 in the others. With this change, every generation runs
at the second set of times, and the program takes 0.50 s instead of
1.18 s (Node: 0.91 s).

The teardown of a class or record type with children of its own type now
keeps the blocks it frees in a segment, linked through their first words
and built in order through a tail pointer. A node releases its own block
first, places it ahead of its children's when its address is the lower
(object literals allocate before their fields) and behind them otherwise
(constructor arguments build the children first), and the chain's first
teardown frees the whole segment onto the free list in one step. A
teardown past DIRECT_DESTROY_CHAIN appends through scr_rc_destroy_seg,
which keeps scr_rc_destroy's depth budget and queue. Blocks outside the
calling thread's arena are freed as before, and targets without the
inline allocation paths keep the old teardown.
2026-10-22 11:12:23 -05:00
Chris Tate 2b657e6e3c Format the split tools' output with the tools checkout's oxfmt configuration
The split tools ran oxfmt in the checkout they rewrite. oxfmt looks up
its configuration from that directory and from the formatted files'
directories, and runs an oxfmt.config.ts it finds there, so a branch that
rehome-split rewrites could run code with the maintainer's permissions.
The tools now format through format.mjs, which passes the tools
checkout's .oxfmtrc.jsonc with --config and disables the nested lookup,
so no configuration file of the rewritten checkout is read or run. With
no files to format it does nothing, where oxfmt would format the whole
directory.

The split-tools tests cover split-methods and move-state on a checkout
whose root and src directory commit an oxfmt.config.ts that records it
ran.
2026-10-22 11:12:02 -05:00
Chris Tate 291587aae1 Scan regular expressions after jump statements, and give up on non-ASCII whitespace 2026-10-22 11:08:55 -05:00
Chris Tate 5ceec5659c Keep key orders exact through write values, live views and spreads
Three cases where a value's key order could differ from Node:

- A write of an optional key moved the key before its value was
  evaluated. A value that adds another key to the same record, as in
  `o.b = ((o.c = 1), 2)`, then put the keys in the wrong order. The write
  now evaluates its value first, then tests and moves the key.
- A value seen as a JavaScript value bound the field hooks of its order
  when it was boxed, and a later write that moved a key did not change
  them. Shapes whose values can change order after they are built
  (IrRecordShape.orderMoves) now read through the value's view, which
  follows the current order.
- A literal that spreads a value with orders and then sets a key the
  value may lack, as in `{ ...value, tag: "x" }`, put that key where the
  source's order has it. Node puts it there only when the value has it,
  and after the value's keys otherwise. The literal now picks its order
  from the source's order and which of those keys the source has.

Corpus 7136 and 7138 cover each case.
2026-10-22 11:06:14 -05:00