Commit Graph
3704 Commits
Author SHA1 Message Date
Chris Tate bc46dbb239 Refresh the measured corpus costs from recent main runs (#1306) 2026-10-18 11:53:42 -05:00
Chris Tate 29c8ad237c Throw when nm cannot list an executable's symbols in the zero-cost gate
The gate read an empty symbol list when nm could not start, was killed by
a signal, or exited with a non-zero status, so the dynamic-tier symbol
check and the executable comparison passed without any symbols. nmOutput
now throws with the binary, the reason and nm's stderr.
2026-10-18 11:36:13 -05:00
Malte UblandClaude Opus 5.5 cd376c14f1 Refresh the corpus costs from main's newest green Linux shards
Rerun scripts/ci-corpus-costs.mjs over the 120 green Linux corpus shard
logs (plain and san, 20 shards each) of main CI runs 39142848734,
39142619508 and 39142079655 (307387c8e, 18c50b55d, b85dd44cd). Their
Linux lanes were all green; only macOS jobs were still queued.

This measures the programs added since the previous refresh, including
5770-5773, 5960-5962, 5973, 6041-6043, the CommonJS require programs
6140-6145 and 5023/5024. Coverage of current main's corpus goes from
2992/3012 (0.9934) to 3011/3012 (0.9997); the one unmeasured program,
scratch-string-slices.ts, landed after those runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 09:33:01 -07:00
Malte UblandClaude Opus 5.5 23981f0c95 Merge origin/main into opt/shard-costs-refresh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 09:32:57 -07:00
Chris Tate 4bba6c1e0b Keep this PR's refreshed corpus costs after the main merge 2026-10-18 11:30:08 -05:00
Chris Tate a0496cbe1e Merge main 2026-10-18 11:27:27 -05:00
Chris Tate 45aa58c433 Run module-level before and after hooks (#1305) 2026-10-18 11:26:46 -05:00
Chris Tate 20e5a2d7c6 Write borrowed string slices into stack buffers (#1203) 2026-10-18 11:24:42 -05:00
Chris Tate 414df19270 Merge main 2026-10-18 11:24:11 -05:00
Chris Tate ab5fa64c90 Prove array lengths stable in index loops and version dense array loops (#1247) 2026-10-18 11:21:01 -05:00
Malte UblandClaude Opus 5.5 023d6201bc Record TypeScript order baselines for the new corpus programs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 09:15:22 -07:00
Malte UblandClaude Opus 5.5 dfacb791a1 Call typed replace callbacks without a dyn box
s.replace(re, fn) and replaceAll boxed a typed callback into a dyn
function and called it through the dyn ABI: per match, a dyn argument
array, a dyn node per capture and for the offset, the box's argument
checks back to typed values, and a dyn result converted to a string.

When every parameter the callback declares receives a value of its
declared kind in each match, the box is unobservable (the runtime only
calls it, with `this` undefined), so the backend passes the closure to
scr_regex_replace_fn, which collects the matches as before and calls the
closure through its own ABI. That holds for callbacks returning a string
that take the match string alone, or, with a regex literal whose captures
the compiled-matcher parser reads, captures every match sets (strings),
then the offset (a number) and the subject (a string). Callbacks with
optional, union or rest parameters, `arguments`, or captures some match
leaves unset keep the dyn path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 09:15:22 -07:00
Malte UblandClaude Opus 5.5 1b8b44dd33 Release the replacement buffer when a replace callback throws
scr_regex_replace_callback freed its output buffer with free() when the
replacer threw after an earlier match had been written, but the buffer
is the body of a runtime string, so the process aborted with "free():
invalid pointer" instead of propagating the exception. It now abandons
the buffer through scr_jb_abandon, which releases the string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 09:15:21 -07:00
Malte UblandClaude Opus 5.5 577b0135a9 Add execution tiers to the IR and a report-only tier analysis
Stage S2 of the two-tier design. IrFunction gains a tier (absent means
static); lowering assigns it from function bodies, placing functions that
use the dyn vocabulary in the dynamic tier, and the validator enforces
invariant I1: a static function performs no dynamic operation, only
boundary operations (dynFrom, dynCheck, kind tests) and moves. Serialized
IR keeps the field out in this stage and loaders derive it again, so every
IR, LLVM and executable artifact is unchanged.

Every committed refusal and runtime fence becomes a recorded demotion
request attributed to the binding, field, function instance, class or
module the dynamic tier would take over, while the compiler still refuses
and fences as before. `scriptc coverage` reports dynamic-tier statements
(statementsDynamic), `--explain-dynamic[=<name>]` prints the demotion
chains, and `--tier=auto|static-only` is wired through build, run and
coverage for stage S6; both modes compile identically today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 09:12:27 -07:00
Chris Tate 2de6f617e6 Merge main 2026-10-18 11:08:54 -05:00
Chris Tate 56e472a225 Return undefined from generic functions that read a missing element
A generic function, arrow or method whose body returns an array element
or an index-signature entry now returns undefined for a missing one, as
in Node, instead of throwing. Only declarations whose bodies return such
a read change their instance result type.

Fixes #964
Co-authored-by: Quim T. <26749475+espetro@users.noreply.github.com>
2026-10-18 11:04:03 -05:00
Malte UblandClaude Opus 5.5 571ffb10a9 Refresh the measured corpus costs from recent main runs
298 of the 3008 corpus programs had no measured cost, which left main
three unmeasured programs above the shard harness's 90% coverage floor:
any PR adding a few corpus programs failed shard.test.ts. Rerun
scripts/ci-corpus-costs.mjs over the 120 green Linux corpus shard logs
of main runs 39131161610, 39130670620 and 39126633135 (31b52e215,
aba3c3a97, 572b26ef8), and drop the entry of the renumbered
5942-local-class-observed-methods.ts. 2989 programs are now measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 09:03:08 -07:00
Chris Tate d3dba4c07f Run module-level before and after hooks
node:test changes, matching Node 24.22:

- before and after hooks outside any suite run, with the root's context,
  whose name is "<root>". They did not run before.
- A module-level before hook runs at its before() call, as Node runs the
  hooks of its already-started root at once: its synchronous part runs
  before the code after the call, and the first top-level test waits for
  an async hook's promise. Every module-level before hook runs, and an
  async hook's rejection is not reported as an unhandled rejection.
- Module-level after hooks run after the last top-level test or suite.
- A throwing root before hook fails each top-level test with the first
  failure; the test's body and beforeEach hooks do not run, and its
  afterEach hooks do. Each top-level suite fails with the error, and the
  tests and suites in it are cancelled before they start: they report
  without a duration and fail with "test did not finish before its parent
  and was cancelled", listed in the failing section in completion order.
- A throwing root after hook reports the entry file as a failed result,
  after the top-level results, and lists it in the failing section at the
  hook's location. It is not counted, and the exit code is unchanged.
- Hooks record the "file:line:col" of their call for that location.

The root-hooks, root-before-throws and root-after-throws fixtures compare
the reporter output, the order of the hooks against the module code, and
the exit codes with Node, plain and with SCRIPTC_SAN=1.
2026-10-18 10:59:27 -05:00
Chris Tate 307387c8ea Answer undefined for missing Record and index-signature keys (#1236) 2026-10-18 10:58:02 -05:00
Malte UblandClaude Opus 5.5 1090c05dfe Compile chalk 5 through the dynamic object model
chalk's callable builder (a function whose prototype chain is set with
Object.setPrototypeOf, with style getters from Object.defineProperties)
already ran on the checked-dynamic model. What failed was the code
around it. Each fix is general and sits on a path that used to end in a
refusal or a runtime fence, or is confined to JavaScript files:

- package.json "imports" inside a --npm-static package resolve to the
  shipped JS with the "node" condition hoisted, like the tsgo fs shadow;
- JavaScript object literals that the file reshapes at run time (keyed
  writes with runtime keys, delete, Object.defineProperty/ies) map to
  the checked-dynamic type, with the literals nested in them;
- a JavaScript class whose only member is a constructor that returns a
  value and never reads `this` answers that value from `new` (the return
  used to be discarded silently);
- `const { env } = process` binds the data member in JavaScript;
- `o && x` / `o || x` with an always-truthy object, array or function
  left operand;
- Number.parseInt/parseFloat over checked-dynamic values apply ToString;
- Function.prototype as a value is one compiler-emitted function;
- calls of String.prototype-only names (bold, italics, ...) on untyped
  receivers call the receiver's own or inherited member; a string
  receiver throws the refusal at run time.

Programs without these patterns compile to identical bytes: the runtime
benchmark workloads, the self-hosted compiler (LLVM and executable) and
the TypeScript corpus IR were compared against the baseline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:57:56 -07:00
Malte UblandClaude Opus 5.5 4128e6f6f5 Count instructions for differing corpus executables in the zero-cost gate
--cachegrind now also runs differing corpus executables (without
arguments, accepting intentional non-zero exits), so emitter changes that
only touch corpus programs get per-function instruction deltas. AGENTS.md
mentions the dynamic-tier symbol rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:57:34 -07:00
Chris Tate 18c50b55db Pass the SuiteContext and hook contexts (#1302) 2026-10-18 10:54:53 -05:00
Chris Tate b85dd44cd6 Renumber the local-class corpus program to 5945 (#1301) 2026-10-18 10:47:37 -05:00
Chris Tate 888726a06c Select the discriminated member for asserted object literals (#1300) 2026-10-18 10:46:09 -05:00
Chris Tate 835ee0a08d Drop the cost entries of a corpus program this PR doesn't add 2026-10-18 10:36:41 -05:00
Chris Tate aee210e184 Read named groups through optional chains and keep their null prototype (#1299) 2026-10-18 10:34:42 -05:00
Malte UblandClaude Opus 5.5 5a6efaf010 Bind top-level this in CommonJS modules to the module's exports object
Top-level `this` in a CommonJS JavaScript file, also inside top-level arrow functions, read as undefined; Node binds it to the module's original exports object. It is now a per-module object created when the module starts: typeof, truthiness, identity and passing it along (the UMD wrapper `(function (root) { ... })(this)`, CoffeeScript's `.call(this)`) behave as in Node. Exports stay the static export table, so a property access through top-level `this` is a named refusal rather than a write no requirer would see. ES modules keep undefined.

The UMD host test `typeof module !== "undefined" && module.exports` read `module.exports` through the module handle as undefined inside functions, so such modules took the non-CommonJS branch (this is what broke ipaddr.js). `module.exports` used only for its truthiness now answers true when every `module.exports =` in the file assigns an object or function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:33:04 -07:00
Malte UblandClaude Opus 5.5 15096a47ed Answer typeof on builtin import bindings by the export's kind
`const { inspect } = require("util"); typeof inspect` printed "string", as did `import { inspect } from "node:util"` in an ES module and `typeof promises` from `fs`. JavaScript sources represent builtin values without their own lowering as identity tokens (strings), and typeof answered from that representation. typeof on a builtin import binding in a JavaScript source now answers "function" for exported functions and classes and "object" for exported objects; the binding read has no effects. TypeScript sources compile as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:32:58 -07:00
Malte UblandClaude Opus 5.5 95712ea590 Keep refused local classes out of speculative type queries
Whole-program analyses that query types before reachability is known (the computed-key write census for JavaScript method dispatch, and the runtime-optional array analysis) can name a function-local class whose collection is refused. No statement owns that refusal there, so it escaped as an uncaught PoisonError from collectClassShapeInner and crashed the compiler (the ts-api-utils probe, @typescript-eslint/typescript-estree, and small TypeScript programs). These analyses now run under Lowerer.speculativeTypeQueries: a refused local class is unmappable for the query and its diagnostics are dropped, and the class's own declaration collects it again and reports them if the program reaches it. Collection and body lowering keep their poison handling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:32:52 -07:00
Chris Tate 9638f0b4ef Close three TypeScript gaps: Error.cause redeclaration, match-result object patterns, union-stored string indexing (#1298) 2026-10-18 10:32:50 -05:00
Malte UblandClaude Opus 5.5 ce87ba722d Read missing record keys as undefined before every absence guard
`let e = map[k]; if (e === undefined) { e = {}; map[k] = e } e[c] = v` on a `Record<string, Record<string, string>>` compiled, then aborted with "record has no key (typed slot…)" where Node prints the result. Without noUncheckedIndexedAccess a keyed record read keeps its typed trap unless the next statement tests the binding for absence, and only `if (!e)` counted. Comparisons with the missing value now count too (`=== undefined`, `== null`, `!== void 0`, `typeof e === "undefined"` and their mirrored forms) for index-signature record reads whose checker type lacks undefined. Module-scope declarations get the same treatment: their pre-registered global takes the undefined arm before any body reads it, and the initializer lowers as the absence probe. Array reads, annotated bindings and noUncheckedIndexedAccess programs compile as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:32:46 -07:00
Malte UblandClaude Opus 5.5 dcdca2b810 Read and write records through a binding that may hold a missing record
Under noUncheckedIndexedAccess, `let e = map[k]; if (e === undefined) { e = {}; map[k] = e } e[c] = v` failed with SC9001 "recordKeySet receiver: expected record, got union". A runtime-optional binding read with a computed key reaches the record read and write lowerings as its `record | undefined` storage. Those lowerings now hold the receiver, the key and, for writes, the value in temporaries and throw Node's TypeError for an undefined receiver ("Cannot read properties of undefined (reading 'k')", "Cannot set properties of undefined (setting 'k')") after evaluating them in Node's order. Every other receiver builds the same IR as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:32:40 -07:00
Chris Tate 03e65fbba9 Merge main 2026-10-18 10:31:54 -05:00
Chris Tate c73f363906 Pass the SuiteContext and hook contexts
node:test changes, matching Node 24.22:

- A describe or suite body may take its SuiteContext, with name,
  fullName, filePath, attempt, passed and diagnostic. Its passed is false
  until the suite has finished, after its after hooks.
- before and after hooks may take the suite's context, and beforeEach
  and afterEach hooks the test's. A test's t.before, t.after,
  t.beforeEach and t.afterEach hooks may take the test's context.
- SuiteContext maps to the runner node that TestContext maps to, so the
  TestContext members that SuiteContext shares lower the same way.

The suite-context fixture compares the reporter output and the order of
the bodies and hooks with Node, plain and with SCRIPTC_SAN=1.
2026-10-18 10:31:11 -05:00
Chris Tate 3c264cf0d9 Renumber the local-class corpus program to 5945
The program shared the number 5942 with 5942-callback-specialization-throws.ts.
Its cost entries and order-parity baseline move with it.
2026-10-18 10:26:31 -05:00
Chris Tate 4d417da7b8 Select the discriminated member for asserted object literals
An object literal asserted to a discriminated union keeps its own record
layout, and that layout can equal another member's layout: in
`{ kind: "return", value, loc } as Stmt`, a non-null `value` gives the
fields of a `throw` member. The value was wrapped as that member, so a
switch on `kind` read it with the `return` member's layout. The compiled
program aborted with an invalid union tag or read past the record; the
native compiler crashed this way while lowering three.js.

The literal's discriminant now selects the member through type
assertions too, as it already did through parentheses and `satisfies`.
2026-10-18 10:22:24 -05:00
Chris Tate cd61e0fb46 Add the TestContext filePath, attempt, passed, workerId and tags values (#1297) 2026-10-18 10:21:30 -05:00
Chris Tate 675388805c Read named groups through optional chains and keep their null prototype
`m?.groups?.year` compiles on exec and match results, including a null
match, where the read was refused before. The matchAll row callbacks also
cover findIndex and findLastIndex.

Reshaping an index-signature record into another index-signature type
keeps the source's null prototype, since the two are one object in
JavaScript. A match's groups read through `m?.groups`, or assigned to a
declared type such as `{ [k: string]: string } | undefined`, now prints
"[Object: null prototype]" as in Node, where it printed a plain object.
2026-10-18 10:18:12 -05:00
Malte UblandClaude Opus 5.5 8e6986c561 Add the zero-cost gate
scripts/zero-cost-gate.mjs compiles a fixed good-code set (the runtime
benchmark workloads, the self-hosted compiler, and the TypeScript corpus)
with a baseline and a candidate checkout. It requires byte-identical IR,
LLVM and release executables, and names the first differing IR function,
LLVM function or executable symbol when something changes. Programs that
match the change's pattern signature (--allow) may differ. It also checks
compile time (paired builds, bootstrap interval), binary size, optional
per-function cachegrind instruction counts, and the two-tier I3 symbol
rule: no executable gains dynamic-tier runtime symbols, and fully typed
benchmark workloads define none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:17:51 -07:00
Malte UblandClaude Opus 5.5 4b23d34efe Format toString(radix) with a number radix without a dyn box
n.toString(radix) passed the radix as a dyn value, so every call boxed a
number and converted it back, and kept scr_json.c's dyn machinery linked
into programs that use nothing else of it.

A number-typed radix now calls scr_num_to_string_radix_f64, which
truncates it as ToIntegerOrInfinity does and holds the formatting that
moved from scr_json.c to scr_lib.c. Other radix types keep the generic
entry point, which converts and then calls the same function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:17:31 -07:00
Malte UblandClaude Opus 5.5 06e987b848 Skip the record-source lookup in typed JSON.stringify unless one was kept
Every closed record written by a typed JSON.stringify called
scr_jb_try_record_source first, an out-of-line call and table probe for
records that almost never keep a source (2% of json-records samples).

The record writer now tests the record-sources constant first, so a
program without a checked conversion that can keep a source emits no
lookup. Where one can, the writer tests the dispose hook inline before
calling: keeping a source installs the hook, so a NULL hook means the
table is empty, and only a program that has kept a source pays the call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:17:30 -07:00
Malte UblandClaude Opus 5.5 fd6145f627 Test the dispose hook only in programs that can install it
Every emitted free loaded the runtime's dispose hook and branched on it,
and every runtime array, map and byte-store free made an out-of-line call
to scr_weak_dispose to do the same. The hook has two clients, weak
collections and the kept sources of checked records, and a program that
has neither never installs it.

The emitted frees now test two module constants the emitter defines after
every helper is emitted: whether the program constructs a WeakMap or
WeakSet, and whether some helper can keep a record source (a checked
record builder that notes one, or a JSON schema of a closed record).
Class instances test the first, closed record layouts both; LLVM folds the
test away, so a program without either frees with no hook load at all.
The runtime's hot frees test the hook inline instead of calling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 08:17:24 -07:00
Chris Tate 2e2a29426d Support zlib stream classes as const aliases and instanceof targets (#1296) 2026-10-18 10:15:42 -05:00
Chris Tate 910ed5e027 Widen nested record fields with the records that hold them (#1293) 2026-10-18 10:08:00 -05:00
Chris Tate 2210773942 Merge main 2026-10-18 10:01:12 -05:00
Chris Tate 8cfb5f789f Lower util.promisify over the crypto callback functions and dns lookups (#1291) 2026-10-18 10:00:38 -05:00
Chris Tate acc920ab85 Add the TestContext filePath, attempt, passed, workerId and tags values
node:test changes, matching Node 24.22:

- t.filePath is the entry file's path, as Node's entryFile, fixed when the
  program is compiled.
- t.attempt is 0, since a test runs once.
- t.passed is false while the body runs and the test's outcome once the
  body ends, so afterEach and t.after hooks see it, as Node's pass() and
  fail() set it before them.
- t.workerId is Number(process.env.NODE_TEST_WORKER_ID) || undefined.
- t.tags is [], since the tags option has no lowering.
- A test's t.before, t.after, t.beforeEach and t.afterEach hooks are
  released when the test ends. Hooks whose closures capture the test's
  context no longer keep it alive in a cycle, which the SCRIPTC_SAN=1
  audit reported as live closures at exit.

The ctx-members fixture compares the reporter output with Node, plain and
with SCRIPTC_SAN=1.
2026-10-18 09:57:26 -05:00
Chris Tate 3de60e4332 Merge main 2026-10-18 09:55:59 -05:00
Chris Tate 0bed1421b0 Verify checker-proven narrowings at run time (#1295) 2026-10-18 09:54:12 -05:00
Chris Tate b4ef932b72 Support zlib stream classes as const aliases and instanceof targets
`const C = zlib.Gzip` stopped at SC2020, and `instanceof zlib.Gzip`
(any zlib class) stopped at SC1090. A const binding of a zlib class is
now a compile-time alias with no runtime slot: `new C()`, `typeof C`,
`C.name` and `C === zlib.Gzip` lower at the use. `instanceof` against a
zlib class asks the runtime for the stream's mode when the operand is a
Transform, tests for a Transform first when it is typed as one of
Transform's bases, and answers false for other static types, as in Node.
Other uses of an alias as a value report SC1090 at the use.
2026-10-18 09:52:17 -05:00