Commit Graph
5591 Commits
Author SHA1 Message Date
Chris Tate 635f732a34 Free a worker's group-arena pool when the worker exits
Each thread keeps up to 8 MB of arena chunks and up to 64 dropped arenas
for reuse (scr_arena.c). Nothing freed them when a worker thread finished,
so every worker that used a group arena left its pool behind: 40 workers
run one after another, each dropping a 12 MB arena, kept 328 MB resident.

scr_arena_thread_exit frees the calling thread's pooled arenas and chunks.
The worker thread calls it after its context cleanup, before it posts the
exit event. The new harness test runs 24 such workers in sequence and
checks that the resident set grows by less than 32 MiB over the last 20
(160 MiB before this change, 1 MiB after).
2026-10-27 07:17:08 -05:00
Chris Tate 331d3804a8 Decode short non-ASCII strings directly in charCodeAt (#2388) 2026-10-27 01:44:17 -05:00
Chris Tate 618243caa8 Generate code concurrently for optimized executables that stay one partition (#2387) 2026-10-27 01:10:09 -05:00
Chris Tate 47904df3c2 Decode short non-ASCII strings directly in charCodeAt
charCodeAt on a non-ASCII string mapped the UTF-16 index to a byte offset
through a string index entry, which the first read claimed and the
string's release purged. For a string of one character, such as each
character of a for-of loop that codePointAt(0) classifies, the entry cost
more than the read.

A non-ASCII receiver of up to 16 bytes is now decoded from its start on
each read, as scr_str_utf16_len already counts short receivers. Longer
receivers keep the index entry and its cursor.
2026-10-27 01:07:00 -05:00
Chris Tate 31fe5c5a8d Convert the base of an offset typed-array index once (#2385) 2026-10-27 00:56:23 -05:00
Chris Tate f64b25d103 Add --large-pages to move executable code onto huge pages (#2386) 2026-10-27 00:36:40 -05:00
Chris Tate 72732110ff Check offset typed-array indexes against the sum for fractional bases and keep the base the sum read
An index `base + c` converted `base` and took a fractional base as an
invalid index. A fraction smaller than the sum's precision is lost in the
sum, as in `1e-20 + 1`, which is the index 1. A base that is not an
integer now goes to the exact check of the sum itself.

The conversion also read the base local again when the access was
emitted. A write evaluates its right-hand side between the index and the
store, so `values[at + 1] = ((at = 5), 31)` wrote at the new base. The
sum now records the base value it was computed from, and the index
converts that value.

The corpus program covers both cases, and the emission test checks that
a write converts the base its sum read.
2026-10-27 00:28:04 -05:00
Chris Tate 640001b260 Generate code concurrently for optimized executables that stay one partition
Optimized executables with at most 1 MiB of LLVM text were compiled as one
module on one thread. With more than 128 KiB of LLVM text they now pass
several outputs and `--split codegen` to the LLVM helper. The helper
optimizes the module whole, as for a single output, then divides its
functions in module order into runs of about the same instruction count and
generates code for each run on its own thread.

- The output count is 4 or 8 and depends only on the module's size
  (nativeCodegenParts), so artifacts never vary with the host. Node and
  native compiler builds pass the same outputs.
- The helper writes the optimized module to bitcode once with its use-list
  order. Every output after the first parses it and turns the other
  outputs' definitions into declarations; the first output does the same to
  the optimized module in place. Each function's machine code matches a
  single-output build except for jumps to a definition that another output
  also uses.
- Only local definitions that another output uses become hidden. Dead
  constant users are dropped before unused declarations are removed, so no
  output names a thread-local variable it does not use.
- When one run would hold more than three quarters of the instructions, the
  first output is generated from the optimized module as for a single
  output and the others are empty objects.
- Dev builds, partitioned builds and program-object validation are
  unchanged.
2026-10-27 00:22:17 -05:00
Chris Tate 97850ea5d2 Give the production frontend lowering test's child process an 8 GB heap (#2384) 2026-10-27 00:16:15 -05:00
Chris Tate 98cc35de09 Find the code segment that holds the runtime under musl too
The constructor took the program object with an empty name for the main
program, which is how glibc reports it. musl reports the main program
with its path, or "/proc/self/exe" in a static executable, so on musl
targets --large-pages found no segment and left the code file-mapped.
The constructor now takes the executable segment that holds its own code:
the runtime links into the executable, so that is the main program's
code under either C library.

scr_text_pages.test.ts runs its check against a static musl build made
with zig as well as the glibc build.
2026-10-26 23:55:27 -05:00
Chris Tate 6d2e72367c Keep element reads through xs[xs.length - 1]! borrowed (#2383) 2026-10-26 23:54:36 -05:00
Chris Tate 140990d257 Add --large-pages: move executable code onto transparent huge pages
A large program's hot code spans hundreds of 4 KiB pages, more than the
instruction TLB holds. tsc-ts has 12 MB of code, and 90% of its
main-thread samples at --checkers 1 fall in 274 distinct code pages.

`scriptc build --large-pages` links the new runtime unit
scr_text_pages.c, whose constructor moves the executable's code onto
2 MiB transparent huge pages before main. It copies the executable
segment, from its first to its last 2 MiB boundary, into anonymous memory
advised MADV_HUGEPAGE, makes the copy read-only and executable, and moves
it over the original range with one mremap, so addresses and instructions
stay the same. The move runs only on Linux, only when THP is "always" or
"madvise", and only in executables. If a step fails, the code stays
file-mapped. Like Node's --use-largepages, it is off by default: without
the flag the unit is not linked, and executables are unchanged.

The move costs about 3 ms per 10 MiB of code at startup, and all of the
moved code stays resident as private memory. The flag is part of the
executable cache key and the runtime-pack selection, and is refused for
non-executable output, like --detached-exit.
2026-10-26 23:41:46 -05:00
Chris Tate 7c295a2b32 Version while loops on the integer range of locals they enter with (#2382) 2026-10-26 23:32:40 -05:00
Chris Tate e6eebcc517 Convert the base of an offset typed-array index once
A typed array read or write at `base + c`, `c + base` or `base - c`,
where `base` is a number local and `c` an integer literal of magnitude
below 2^31, now converts `base` to an integer and adds `c` as an
integer, instead of converting the double sum. Accesses at several
offsets from one base, such as `x[at]` through `x[at + 7]` with a number
parameter `at`, then share one conversion and integer test. Below a
length of at most 2^52 the sum is an integer index exactly when `base`
is an integer, so the accesses read and write the same elements as
before.
2026-10-26 23:32:08 -05:00
Chris Tate a2dd09679b Give the production frontend lowering test's child process an 8 GB heap
The lowering of the complete frontend holds about 3 GB of heap. Node sizes
its default heap limit from the host's memory, and on hosts with less
memory the limit is about 2 GB, where the child runs out of heap.
2026-10-26 23:31:17 -05:00
Chris Tate cb5882b97c Run the macOS arm64 no-clang contracts in their own job (#2378) 2026-10-26 23:28:57 -05:00
Chris Tate fc8fe7e619 Rename each shared libCall once when switching to child property tables (#2381) 2026-10-26 23:22:58 -05:00
Chris Tate 775a317edd Keep element reads through xs[xs.length - 1]! borrowed
A member read through a non-null asserted element read evaluates the
element's presence and then reads it, so a missing element throws Node's
TypeError. An index other than a local or a field read was held in a
hidden local first, which turned the receiver into a sequence: the
element was then read with a reference (retain and release) instead of
borrowed, and the fallback `genes[genes.length - 1]!.sc` of a search
made fasta's lookup loop 12% slower.

An index computed only from locals, field reads, number literals and the
lengths of arrays read through them (`xs.length - 1`, `i + 1`, `-i`)
has no effect and yields the same value when evaluated again with
nothing in between, so it is evaluated for the presence test and again
for the read, and the element stays a borrowed read. Other indexes keep
their hidden local.
2026-10-26 23:20:59 -05:00
Chris Tate 4046b17c65 Version while loops on the integer range of locals they enter with
A while loop whose remainder reads number locals that enter it without
range facts, such as copies of module globals, parameters or fields
(`const base = column;` before `(count + base - breaks) % 60`), now runs
as two copies. On entry, a test checks that each such local holds an
integer in [-2^48, 2^48] other than -0. The fast copy uses the facts the
integer range analysis proves when the function is analyzed again with
those entry ranges assumed: the loop's counters become bounded, and the
sums and remainders run as i64 arithmetic. When the test fails, the loop
runs as it did before.

- ir/loop-entry-ranges.ts picks innermost while loops with a remainder
  that the assumed ranges prove and the function's own analysis does
  not. The test covers only the locals the remainder depends on, directly,
  through the loop's writes or through its condition.
- ir/integer-ranges.ts takes the assumed entry ranges per loop, and keeps
  no fact about the assumed locals or the loop's writes after it.
- backend/llvm/loop-entry-versions.ts emits the test and both copies.
  The test is marked likely. A function called only from the loop gets
  `alwaysinline` on the fast copy's call, because the second copy would
  otherwise cost it the inlining of a single call site.

reverse-complement (25M bases): 2.08 s -> 1.19 s; Node 3.97 s.
2026-10-26 23:02:32 -05:00
Chris Tate 80b851d65f Write untyped stores into live records and keep one object across prefix casts (#2366) 2026-10-26 22:56:27 -05:00
Chris Tate f436bf5ede Give every native function an unwind table entry (#2377) 2026-10-26 22:54:13 -05:00
Chris Tate 7646ab5a6b Rename each shared libCall once when switching to child property tables
applyHandleProperties collects the libCalls to rename with a walk of
every function body and renames each one in place. A node the IR reaches
from several statements was collected once per statement, so its second
rename looked up the already renamed name and set fn to undefined. The
calls are now collected in a set, so each node is renamed once.

The lowering does not share such a node today, because devirtualization
rebuilds every function body before this step; the lowered IR of current
programs is unchanged.
2026-10-26 22:48:01 -05:00
Chris Tate a9fc5f50ee List the macOS arm64 contracts job in the macos lane test 2026-10-26 22:46:49 -05:00
Chris Tate 6131540bb2 Trace Array subclass instances in array-typed slots and test their class on element reads (#2372) 2026-10-26 22:36:57 -05:00
Chris Tate 79f456d665 Keep the static hello binary small under GNU ld (#2373) 2026-10-26 22:36:03 -05:00
Chris Tate 47fd397395 Expect the unwind table attribute in the --target-cpu test's attribute group 2026-10-26 22:24:00 -05:00
Chris Tate 5e6e1a9d85 Run the macOS arm64 no-clang contracts in their own job
Shard 1 of "test (macOS arm64 LLVM artifacts, no clang)" ran the no-clang
object, helper parity, packaged helper and packed npm installation
contracts around its LLVM differential slice: about 12 minutes on top of
a 35-minute slice, 45 to 49 minutes against the job's 50-minute timeout.
The contracts now run in "test (macOS arm64 LLVM artifacts, no clang,
contracts)", which the all-lanes check requires like the shards, and
every shard runs only its differential slice.
2026-10-26 22:21:48 -05:00
Malte UblandClaude Opus 5.5 d2abf522c8 Give the dynamic-dispatch test lowerer a source lookup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 20:16:41 -07:00
Malte UblandClaude Opus 5.5 70c39cca49 Keep frozen records frozen for untyped code and ignore refused sloppy writes
Object.freeze of a fresh record or array literal now sets the native
frozen bit instead of compiling to the literal, so an untyped reference to
the value sees it frozen: Object.isFrozen answers true and strict-mode
writes throw Node's TypeErrors.

Untyped property writes in sloppy-mode code (IrModule.sloppyDynWrites,
decided per write by isStrictCode) call scr_dyn_key_set_sloppy and its
computed form, which drop exactly the TypeError a refused assignment raises
(a read-only or frozen property, a non-extensible object, a frozen array
element) while a setter's exception still propagates. Computed-write
dispatch helpers are shared only by writes of the same mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 20:16:30 -07:00
Chris Tate 55cf42e9c0 Install ld.lld in the Sandbox toolchain so Sandbox links match CI (#2375) 2026-10-26 22:14:48 -05:00
Chris Tate da7aa5377a Key the gate's baseline cache on the linker clang finds (#2376) 2026-10-26 22:13:58 -05:00
Chris Tate 31f07e2d73 Read class instance fields inline at dynamic-tier property sites (#2374) 2026-10-26 22:13:38 -05:00
Chris Tate f7168d3fca Merge main 2026-10-26 22:04:34 -05:00
Chris Tate 80138011ed Allocate template literals at their exact length (#2369) 2026-10-26 21:55:50 -05:00
Chris Tate c9585ae48f Fail type checking when the generated IR field readers miss a field (#2370) 2026-10-26 21:52:07 -05:00
Chris Tate e1eead091f Give every native function an unwind table entry
LLVM emits an unwind table entry for a function that may unwind or that
has the uwtable attribute. Functions it infers nounwind, such as the
number-key Map probe sc_map_entry_f64_hashed, got none, so profilers and
debuggers could not unwind past them. The function attribute groups now
carry uwtable on native targets; wasm32-wasi modules are unchanged.
2026-10-26 21:49:14 -05:00
Chris Tate 079bad80be Leave out a header the compiler rejects in the implicit toolchain probe (#2371) 2026-10-26 21:47:29 -05:00
Chris Tate ad29d598f5 Merge main into the untyped-store branch 2026-10-26 21:44:47 -05:00
Malte UblandClaude Opus 5.5 b4ba4d38ac Key the gate's baseline cache on the linker clang finds
Linux links use ld.lld when clang finds it and the system linker
otherwise, and the two produce different executables. A baseline record
made with one must not settle candidates linked with the other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 19:43:02 -07:00
Malte UblandClaude Opus 5.5 9c42c8d74b Install ld.lld in the Sandbox toolchain so Sandbox links match CI
CI's pinned LLVM ships ld.lld, and the compiler links Linux executables
with it whenever clang finds it. The Sandbox image and the managed-image
bootstrap installed clang-22 without lld-22, so Sandbox builds linked
with GNU ld: static hello came out at 99 KB instead of 65 KB, and
runtime-tree-shaking failed only in Sandboxes. Install lld-22 in both
and check that clang finds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 19:40:54 -07:00
Chris Tate 2cbce33cd3 Read class instance fields inline at dynamic-tier property sites
An instance of a compiled class reaches untyped code as a capsule, which
a property site sent to its helper on every read: the helper normalizes
the capsule, tests each class's key in turn, and loads the field.

A read site now emits the helper's plain field branches inline. A
capsule whose key pointer is one of those classes' keys loads the field
from its instance and shares the inline hits' conversion. A branch is
emitted only when its field holds a plain dyn cell and every subclass
the helper's normalization can rebox the key to reads the same field
from the same slot. Getters, bag properties, unset fields and other
capsules keep the helper.
2026-10-26 21:39:18 -05:00
Chris Tate d99f355182 Give the native layout and metadata emission test 600 seconds (#2368) 2026-10-26 21:36:39 -05:00
Chris Tate 2795957867 Step untyped loops over the program's generators on the typed path (#2302) 2026-10-26 21:36:11 -05:00
Malte UblandClaude Opus 5.5 019fc51e31 Keep the generator tag reader and the glibc math unit out of hello
The static hello binary grew past the 96 KiB ceiling of the runtime
tree-shaking test on Linux hosts that link with GNU ld (99,040 B). CI does
not see it: its pinned LLVM ships ld.lld, which the compiler prefers, and
hello links to about 65 KB there. The Sandbox gate installs Ubuntu's
clang-22 without lld, so it links with GNU ld.

dd418b067 crossed the ceiling (98,032 -> 98,960 B). Its scr_glibc_math.c
defines floor, fmod, frexp and other glibc names as hidden functions so a
program can start without libm. With GNU ld that cannot work: ld decides
--as-needed before section GC, so the runtime's unreachable code keeps
libm needed, and it keeps every regular definition of a name a needed
shared library defines, hidden or not. Every executable carried the whole
unit (about 2.5 KB of code and unwind data) and still loaded libm. Links
without lld now leave the unit out; its functions answer what glibc's do.

192ea3247 installed scr_gen_tag_reader from a load-time constructor in
scr_async.c. A constructor is a link root on every format, so each
executable kept scr_gen_tag and, with GNU ld, all of scr_async.c's string
literals (about 1.1 KB). The generator runtime now installs the reader
when it creates a generator, the only time a reader can be needed.

Hello is now 93,928 B with GNU ld and 65,472 B with lld.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 19:35:52 -07:00
Chris Tate e3bd44d65b Trace Array subclass instances held in array-typed slots and test their class on element reads
An Array subclass's type maps to its element array type, so a field such
as TreeNode.kids holds a Kids instance in a slot typed as an array of
TreeNode. The collector visits such a slot as an array, which has a
collector header when its element ops trace, but the class only got a
header when its own class unit was on a cycle, and the collector read a
header the instance did not have. An Array subclass now carries a header
whenever an array of its element type does, and its collector descriptor
visits its elements instead of naming no children.

An element read of an array of Array subclass instances is a union with
undefined, and 'instanceof' against the class answered false for it. A
union now tests its array arms' class at run time.
2026-10-26 21:28:56 -05:00
Chris Tate 06bd585a53 Test two inline-cache entries inline at dynamic-tier property sites (#2367) 2026-10-26 21:20:00 -05:00
Chris Tate 2c09b499b2 Check a nested record of scalar fields by its own fields
The generator listed a field as a scalar when its walk read nothing, so
a nested record holding only numbers and booleans got a ValuesNotRead
check on the record itself, which fails because the record is an object,
even after regenerating. A field is now listed as a scalar only when its
type holds no string and no object; such a record is checked through its
own fields, so a field added to it or a scalar in it that starts to hold a
string still fails type checking with its name.

The generator exports generateIrFields(irText) for the new test, which
generates the readers for an ir.ts with such a record and type-checks
them. The generated file for the current ir.ts is unchanged.
2026-10-26 21:18:38 -05:00
Chris Tate e4fe30e084 Leave out a header the compiler rejects in the implicit toolchain probe
The implicit toolchain probe preprocesses every system header that the
runtime and vendored sources spell in one source file. When the compiler
rejected one of them, the whole probe failed, and the build continued
without the native cache and without program sharding.

When the compiler rejects the probe source, each header is now
preprocessed on its own, and a header that the compiler rejects on its
own is left out of the dependency set, as an absent header is. The probe
still fails when the compiler rejects every header.
2026-10-26 21:16:15 -05:00
Chris Tate 07f159accd Fail type checking when the generated IR field readers miss a field
fields.generated.ts reads IR nodes' fields by name, so a field ir.ts gains
after the last `pnpm generate:ir-fields` is skipped by the walkers until
someone regenerates the file; `--check` in CI reports it, but only on the
run that looks.

The generator now ends the file with type-level checks, one per node kind
and per nested record the walkers enumerate: a field outside the list the
file was generated from fails type checking with the field's name, and so
does a field read as a scalar (no string, no object) that can now hold a
string or an object. Fields the file reads already fail type checking when
they are removed or change type. The checks are types only and emit no
code.
2026-10-26 21:06:07 -05:00
Chris Tate e58def0299 Update tests for the record-ops store hook and the untyped-writes benchmark
- forin-keys.test.ts matches the record-ops table with its eighth field, the
  store hook, which is null for a record no untyped code writes.
- bench/record-untyped-writes writes typed records through `unknown` and
  `Object.assign` views, so it links dynamic-tier symbols; DYNAMIC_WORKLOADS
  lists it.
- The sanitized self-hosting emission test gets a 600 s timeout. It takes
  about half of the default 300 s on an idle 16-core host, with or without
  these changes, and exceeded the default on a loaded CI shard.
2026-10-26 21:04:31 -05:00