Commit Graph
2590 Commits
Author SHA1 Message Date
Malte UblandClaude Opus 5.5 fbcdb1d641 Compile inline require(), computed and chained CommonJS exports, and a module's own exports object
The npm compatibility probes ranked these CommonJS forms among the top blockers. They now compile with Node's semantics inside the static CommonJS model, where exports stay module globals or alias plumbing to declarations. Every remaining form keeps a refusal that names the construct.

- Inline require() of program modules (cjs-inline-require.ts). `require("./x").f`, `.f(...)` and `new (require("./x").C)()` over a table module run the module's run-once %init at the call's position, then resolve the member like a binding does. `require("./x")` as a value over a single-value module is that value (`require("debug")("ns")`, table entries, construction). Inline requires are preflight module edges. An edge in a function body is lazy: it orders the dependency after the requiring module and does not close initialization cycles. Other require() calls name their construct instead of reporting an unlowerable 'Require' value. A package that nothing installed resolves throws MODULE_NOT_FOUND.
- module.exports = require("./y") or a require binding (re-export), = TypeError (a builtin global), and = any computed value (`a || b`, ternary, `new X()`). Chained `exports.a = exports.b = v` evaluates v once. Export members assigned in value position (`const src = exports.src = []`) or inside functions write the export global. A fresh `exports = module.exports = {}` reset at the top of a module is a no-op. Any other rebinding of `exports` is refused by name.
- A module's own exports object (cjs-exports-object.ts). Identity comparisons, typeof and truthiness of `exports` / `module.exports` use the object that top-level `this` already represents, while the module keeps its original exports. This covers the `root === module.exports` statement that used to vanish from `.call(this)` wrappers. `exports.f(x)` calls the member's export global when no assigned value can read `this`. Other value uses are refused by name, including in CommonJS files where the message used to say "ES module".
- tsc interop (cjs-tsc-interop.ts). `const x_1 = __importDefault(require(...))` and `__importStar(...)` are require bindings, stamped and unstamped. The helper declarations lower to nothing once every call is such a binding.
- Export tables: method entries compile, and `...require("./x")` spread entries now evaluate x at their place. Before, the module was never initialized.
- TypeScript reads of members a JavaScript module attached to an exported function go through the function's own property table.
- Nested require destructuring of program modules, `const { codes: { E } } = require("./errors")`, destructures the named export at the require (SC1012). `const { A } = ns` over a module binding snapshots the export.

The capture-buffer fence tests merged from opt/cjs-exports-value used `root === module.exports`, which now compiles. They use eval() to keep testing the fence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 13:29:28 -07:00
Malte UblandClaude Opus 5.5 a2707ac8d6 Name the inner location in package-anchored npm-static refusals
A package-anchored preflight diagnostic that makes the build drop an npm package was reported only at the consumer's import, as `SC2013 cannot compile npm package 'ws' statically: SC1012: …`, with the package file and line lost. The refusal reason now carries them (`SC1012 at ws/lib/websocket.js:30: …`), in the SC2013 diagnostic and in the coverage report's package status. This is how the SC1012 construct behind ws, readable-stream, through2, socket.io and fastify was identified (nested require patterns, and a rest element in fastify), and how openai's SC1013 is located (`openai/internal/auth/x509-transport-state.mjs:2`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 13:07:01 -07:00
Malte Ubl a273999cb0 Merge branch 'opt/cjs-exports-value' into opt/cjs-exports-model 2026-10-18 12:05:24 -07:00
Malte UblandClaude Opus 5.5 8531a45509 Record baselines for the capture-buffer fence fixtures
The diagnostics snapshot for speculative-function-refusal.ts and the ts7 order-parity baselines for it and 6110-cjs-speculative-wrapper-fences.cjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 12:04:28 -07:00
Chris Tate 329ea4387e Convert a Date to local time once for its local getters and follow TZ changes (#1313) 2026-10-18 13:57:42 -05:00
Malte UblandClaude Opus 5.5 b0ce48f168 Fence refused statements inside capture buffers instead of dropping them
A refused statement in a JavaScript function body was dropped without a diagnostic or runtime fence when the body lowered inside a capture buffer whose owner kept the result. tryLowerExpression lowers the receiver of `(function () { ... }).call(this)` or `.apply(...)` and a computed class base that way: the refused statement (for example `console.log(root === module.exports)`) was missing from the kept function, its diagnostic was handed back to the enclosing statement, and that statement, having lowered cleanly, filed it as an informational runtime-fence entry. The program printed nothing for that statement.

lowerStmts now emits the statement's runtime fence inside a buffer as well (Lowerer.capturedRuntimeFence, the same message deferToRuntimeFence would give), leaving the diagnostics with the buffer's owner. The three JavaScript class initializer sites that skipped their fence under a buffer (static field, instance field, static initializer block) do the same. An owner that discards the candidate discards the fence with it, so every program that compiled before keeps byte-identical IR unless it contained such a dropped statement: all 3006 corpus programs produce the same IR as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:47:04 -07:00
Chris Tate 2d9604eff5 Fix get-or-create records, local-class type queries, builtin typeof and CommonJS top-level this (#1303) 2026-10-18 13:44:35 -05:00
Chris Tate fe7b1cd199 Convert a Date to local time once for its local getters and follow TZ changes
Each local-time getter (getFullYear, getMonth, getDate, getHours, ...,
getTimezoneOffset) called localtime_r and walked the calendar for its
own field. The thread now keeps its last local conversion, keyed by the
instant and a timezone generation, so reading several local fields of
one Date converts it once. The UTC walk and the second computation use
integer division instead of floor.

Writing or deleting process.env.TZ calls tzset and starts a new
generation, so later local-time reads use the new zone, as in Node.
Before, the zone the process started with stayed in effect.
2026-10-18 13:33:41 -05:00
Chris Tate 359bd29b1b Stop repeating two frontend scans (#1312) 2026-10-18 13:30:45 -05:00
Chris Tate 761252e173 Expect the run-time refusals of node24-file-url-conversion and stream-shims
Both fixtures declare a function-local class whose base has no static
lowering (`class FileURL extends URL {}`, `class Counter extends
Readable`). The SC1090 for it used to come from the whole-program type
queries, which collected the class outside any statement, so the build
failed. Those queries now keep a refused local class out of their
results and drop its diagnostics; the class declaration reports the
refusal when it lowers, and in a JavaScript source a refused statement
becomes a runtime fence. Both programs therefore compile and throw the
fence when they reach a construct without a lowering, like the other
fixtures listed with a run refusal.
2026-10-18 13:20:51 -05:00
Chris Tate 16da839c62 Merge main 2026-10-18 13:16:06 -05:00
Chris Tate 09b0dffebc Walk dead cycles once in the cycle collector (#1286) 2026-10-18 13:09:16 -05:00
Chris Tate f3b5696d5d Stop repeating two frontend scans
Class dynamic dispatch decides whether a class family keeps a fixed
field layout from the property names a delete can remove. It cached that
set with ??=, but the scan returns null when the program reflects on
properties, so a program that does recomputed it, walking every source
file, for each class in every dispatch wave. Only an undefined value now
means the set has not been computed.

npm-static re-export pruning read and parsed a package's package.json
for every file whose purity it checked, and for every package boundary
an import crossed. Each plan now parses each package.json once.

Output is unchanged. three.js nodes lowering takes 6 s less and an
Effect fixture's frontend load 4 s less.
2026-10-18 13:08:49 -05:00
Chris Tate 13f44cac9c Report unhandled rejections after each timer and immediate callback (#1311) 2026-10-18 13:06:56 -05:00
Chris Tate a08aada5f5 Name 5980-cycle-components.ts in its order baseline
The program moved from 5973 with its baseline, but the baseline still
recorded the old path as the module order.
2026-10-18 12:48:38 -05:00
Chris Tate 7cfb6b16d2 Report unhandled rejections between timers and between immediates
Node runs runNextTicks after each timer and each immediate callback, which
reports the unhandled rejections the callback left before the next one runs.
The event loop now leaves the timer phase when a callback leaves the
rejection ledger non-empty, the check phase waits for that report, and the
check phase reports the ledger after each immediate's checkpoint.

When several timers expired in the same turn, a later timer ran before an
earlier timer's rejection was reported. On macOS the 2 ms and 3 ms timers in
5809-process-exit-and-rejections.cjs expire together, so its uncaught
'thrown string' was printed before the TypeError rejection.

5996-rejections-between-macrotasks.cjs makes five timers expire in the same
turn and checks the order across three immediates.
2026-10-18 12:47:01 -05:00
Chris Tate 4b8b5e3b81 Revert "Read fields as undefined before their assignment" (#1310) 2026-10-18 12:38:47 -05:00
Chris Tate debbd359d7 Merge main 2026-10-18 12:30:17 -05:00
Chris Tate 29f6d8e47f Merge main 2026-10-18 12:28:02 -05:00
Chris Tate f59049112f Compile chalk 5 through the dynamic object model (#1309) 2026-10-18 12:25:45 -05:00
Chris Tate da1af7437f Revert "Read fields as undefined before their assignment (#1292)"
This reverts commit ff90245b27.
2026-10-18 12:20:36 -05:00
Chris Tate 9ef9c038da Merge main 2026-10-18 12:01:19 -05:00
Chris Tate 3c638d5537 Add the zero-cost gate (#1304) 2026-10-18 11:57:52 -05:00
Chris Tate 65d849e6b8 Merge main 2026-10-18 11:56:36 -05:00
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 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 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 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