Commit Graph
2330 Commits
Author SHA1 Message Date
Chris Tate 9fd5c8a73f Widen ASCII to UTF-16 sixteen bytes per step in Buffer.write
Buffer.write(text, "utf16le") zero-extended an ASCII run eight bytes per
step with shifts and masks in 64-bit words. Where the target has vector
unpacks (SSE2 on x86-64, NEON on AArch64) it now widens sixteen bytes
per step: one load, a test of the high bits, and two unpacked stores.
The word loop stays for the remaining bytes and for other targets. A
scanner that fills a Uint16Array of code units this way, as tsc-ts does
once per source file, spends about half as long in the copy.
2026-10-17 18:59:01 -05:00
Chris Tate 7980eb4345 Match Node 24 in events and timers/promises (#1227) 2026-10-17 18:11:06 -05:00
Chris Tate 96a03aec71 Call factory-defined static methods with their receiver class (#1226) 2026-10-17 17:50:47 -05:00
Chris Tate 6ae3eb5cc8 Match Node 24 in events and timers/promises
- The EventEmitter leak warning reaches process 'warning' listeners on the next tick
- The events listener-count and max-listener helpers work over EventEmitter instances
- timers/promises setTimeout, setImmediate and scheduler.wait accept an AbortSignal
- timers/promises scheduler.wait and scheduler.yield are lowered
2026-10-17 17:48:42 -05:00
Chris Tate a5675b2279 Call factory-defined static methods with their receiver class
A static method that a function-local JavaScript class defines at
runtime and a program class inherits (Animal.extend("Dog")) is now
called directly with this bound to the receiver class when it captures
nothing from the factory's scope, so the subclass it builds has a static
base and constructs like Node.

Fixes #938
Co-authored-by: phall <25888173+phall1@users.noreply.github.com>
2026-10-17 17:31:30 -05:00
Chris Tate 1783196f60 Resolve host names in net.connect (#1224) 2026-10-17 17:17:13 -05:00
Chris Tate a3b2c24b23 Document the wasm32-wasi runtime pack and fix the SC3003 hint (#1223) 2026-10-17 17:13:16 -05:00
Chris Tate a4a2472bd6 Lower Error.isError (#1221) 2026-10-17 17:01:01 -05:00
Chris Tate c9de7a351d Read .groups on matchAll rows passed to array callbacks (#1222) 2026-10-17 16:55:56 -05:00
Chris Tate 8bc797779a Group Sets, Maps and generators with Object.groupBy and Map.groupBy (#1220) 2026-10-17 16:49:35 -05:00
Chris Tate e02834f078 Use asserted key types in the method replacement census (#1218) 2026-10-17 16:43:49 -05:00
Chris Tate 55005ef73d Resolve host names in net.connect
net.connect and net.createConnection dialed only IP literals and
"localhost"; any other host name failed with getaddrinfo ENOTFOUND
without a lookup, so names served by /etc/hosts or a container's DNS
(such as Docker service names) did not connect. The dial now resolves
the name with getaddrinfo using Node's hints, orders the addresses as
Node's autoSelectFamily does, and tries them in order.

Fixes #1156
Co-authored-by: Quim T. <26749475+espetro@users.noreply.github.com>
2026-10-17 16:42:55 -05:00
Chris Tate 89a6991278 Expose Promise.prototype methods on promises in untyped bindings (#1219) 2026-10-17 16:41:39 -05:00
Chris Tate 8fbc1d9b77 Document the wasm32-wasi runtime pack and fix the SC3003 hint
The WebAssembly and platform docs now say that wasm32-wasi builds need
zig and the @scriptc/runtime-wasm32-wasi package where the target is
introduced. A missing cross-target runtime pack still reports SC3003
with the package name and version; its hint now says that scriptc
includes the runtime pack for its own platform only, instead of
suggesting a reinstall with optional dependencies.

Fixes #717
Co-authored-by: guest271314 <4174848+guest271314@users.noreply.github.com>
2026-10-17 16:39:20 -05:00
Chris Tate 69fe16ac0f Keep the identity of checked-dynamic objects placed in JavaScript literals (#1207) 2026-10-17 16:37:43 -05:00
Chris Tate b7eb8255f9 Read .groups on matchAll rows passed to array callbacks
m.groups on a match row compiles when the row's regex is statically
known. The row can now also be the element parameter of an inline
callback over a matchAll drain (map, forEach, filter, find, findLast,
some, every, flatMap) or Array.from's mapping function over s.matchAll(re).
In JavaScript sources such a parameter holds the row as a checked-dynamic
value without its groups, and the read is refused instead of reading
undefined.
2026-10-17 16:35:27 -05:00
Chris Tate f1a4b364fb Report program type errors instead of npm package refusals (#1216) 2026-10-17 16:32:09 -05:00
Chris Tate adc2190bd6 Widen Result<T, never> and Result<never, E> unions (#1213) 2026-10-17 16:28:15 -05:00
Chris Tate 983058a3a7 Lower Error.isError
The ESNext error lib is now part of the type world, and Error.isError(value)
compiles. A catch binding tests its payload against the Error class, an
unknown value tests the checked-dynamic error encoding, and a union tests its
runtime tag against the arms whose class extends Error. Other values answer
statically: true for instances of Error and its subclasses, false for
everything else, including objects that only have an error's shape. The
argument is always evaluated. Unions with unknown arms are refused.
2026-10-17 16:26:42 -05:00
Chris Tate ed380babe9 Treat type-asserted values as present in the optional-value analysis (#1214) 2026-10-17 16:24:44 -05:00
Chris Tate 1f04c0b544 Group Sets, Maps and generators with Object.groupBy and Map.groupBy
Object.groupBy and Map.groupBy accepted only arrays. They now also take a
Set (its elements), a Map (its [key, value] entries) and a synchronous
generator. Sets and Maps are walked live, as forEach walks them, and a
generator is pulled one element per callback call and closed when the
callback throws. In JavaScript sources, unannotated callback parameters
take the element and its index.
2026-10-17 16:23:24 -05:00
Chris Tate 6ce668b213 Compile switch statements over object values (#1211) 2026-10-17 16:21:43 -05:00
Chris Tate a1d5d9e1b9 Expose Promise.prototype methods on promises in untyped bindings
Reading then, catch or finally from a promise held in a JavaScript or
checked-dynamic binding now answers the shared method values, so
typeof checks, thenable detection and "then" in p match Node. Calling a
method value uses its receiver; a receiver that is not a promise throws
Node's incompatible-receiver TypeError.

Fixes #978
Co-authored-by: Quim T. <26749475+espetro@users.noreply.github.com>
2026-10-17 16:18:56 -05:00
Chris Tate b91882d684 Use asserted key types in the method replacement census
An element write whose key is asserted to a number, such as
`slots[at as number] = x` or `slots[at!] = x`, was judged by the type of
the key before the assertion. A `number | undefined` key counted as a key
that can name any string, so calls of every method in the program went
through the checked property lookup. The census now reads the type of the
key with its assertions, so these writes only mark methods with numeric
names.

Fixes #1148
Co-authored-by: Alan Leal <33952+alantriesagain@users.noreply.github.com>
2026-10-17 16:15:37 -05:00
Chris Tate 4e979b2c7e Lower Promise.try with arguments for the callback (#1212) 2026-10-17 16:15:20 -05:00
Chris Tate 1f999c7cf0 Print BlockList address rules in a platform-independent order (#1210) 2026-10-17 16:12:37 -05:00
Chris Tate 07aece4362 Expect the typed-callbacks npm program to match Node
Its package puts a cyclic object (cycle.self = cycle) in an array literal
with other values. The literal used to convert that checked-dynamic
object into a recursive record type and crashed; it now builds as a
checked-dynamic array that holds the object itself, so the program runs
as under Node and is no longer a known divergence.
2026-10-17 16:11:51 -05:00
Chris Tate 6b5adcf6e5 Store unknown and object class fields in checked-dynamic storage (#1208) 2026-10-17 16:08:57 -05:00
Chris Tate b666b6b1b1 Lower filter, find, findIndex, some and every on tuples (#1209) 2026-10-17 16:08:26 -05:00
Chris Tate 2f2f26d0d5 Report program type errors instead of npm package refusals
When the program still fails to typecheck against a refused package's own
declarations, the type errors are the program's. Report them at their
locations instead of an SC2013 refusal for every imported package.

Fixes #1155
Co-authored-by: Quim T. <26749475+espetro@users.noreply.github.com>
2026-10-17 16:06:08 -05:00
Chris Tate e161dc4446 Treat type-asserted values as present in the optional-value analysis
`hot(xs[i] as number)` and `hot(stack.pop() as number)` counted as
possibly undefined, so `hot(n: number)` took a boxed `number | undefined`
parameter and callers boxed every number they passed. An assertion to a
type without undefined already checks the value and throws a TypeError
for undefined, so its result is now treated as present, like `x!`.

Fixes #985
Co-authored-by: Tim Kendall <1427378+timkendall@users.noreply.github.com>
2026-10-17 16:00:54 -05:00
Chris Tate d00ccbe89e Widen Result<T, never> and Result<never, E> unions
A union arm whose object type has a required property of type never has
no values. When a conversion's source checker type proves an arm
uninhabited, the re-tag traps on that arm instead of requiring a matching
destination layout, so Result<T, never> widens into Result<T, E>.

Fixes #1170
Co-authored-by: BaoLei <50226652+blurname@users.noreply.github.com>
2026-10-17 15:58:16 -05:00
Chris Tate cd977bf200 Lower Promise.try with arguments for the callback
Promise.try(f, ...args) evaluates the arguments at the call and passes
them to f, which still runs synchronously; its result, a returned
promise or a synchronous throw settle the returned promise as in the
one-argument form. A callback with more parameters than arguments, or
an arguments list with a spread, is refused.
2026-10-17 15:55:37 -05:00
Chris Tate 6f4b569cb6 Compile switch statements over object values
A switch whose discriminant is an object, array, record, function or
other reference value was refused. It now lowers like the union and
checked-dynamic switches: the discriminant is evaluated once and each
case expression, in source order and only until one matches, is compared
with it by the same strict-equality lowering as ===, which compares
references by identity. The === and !== lowering is now a function the
switch lowering shares.
2026-10-17 15:52:58 -05:00
Chris Tate 8a2d9356c4 Print BlockList address rules in a platform-independent order
Corpus 5659 printed blockList.rules and the inspected BlockList in the
order Node lists them. Node lists the address rules first, in the
iteration order of the std::unordered_map that holds them, and that order
differs between platforms, so the expected output on macOS differed from
Linux. The subnet and range rules that follow keep Node's fixed order
(newest first).

The program now sorts the address rules before printing the rules lists,
and inspects a BlockList that holds a single address rule.
2026-10-17 15:52:14 -05:00
Chris Tate 0210e54e49 Lower filter, find, findIndex, some and every on tuples
Fixed tuples, readonly or mutable, lower these predicate methods like map
and flatMap: each position is read when it is visited, find, findIndex,
some and every stop at the first deciding position, and predicate results
and narrowing follow the array methods' rules.

Fixes #1171
Co-authored-by: BaoLei <50226652+blurname@users.noreply.github.com>
2026-10-17 15:50:17 -05:00
Chris Tate 6470c870ef Store unknown and object class fields in checked-dynamic storage
TypeScript class fields declared `unknown` or `object`, also with `null`
or `undefined` or as arrays of those, were refused with SC1090. They now
use the checked-dynamic storage that JavaScript class fields without a
declared type already use. This covers instance fields, static fields and
parameter properties. Fields declared `any` stay refused.

Fixes #1147
Co-authored-by: Alan Leal <33952+alantriesagain@users.noreply.github.com>
2026-10-17 15:47:37 -05:00
Chris Tate 318209abe6 Keep the identity of checked-dynamic objects placed in JavaScript literals
JavaScript file-scope object literals are stored as checked-dynamic
objects. An array literal holding one, directly or in a nested literal,
was built with a static element type, so the element was a copy:
arr[1] === marked was false and writes through the array missed the
original. Such array literals now build as checked-dynamic arrays, a
file-scope binding initialized with one stores it unchanged, and an
object literal whose property is a nested literal holding one builds as
a checked-dynamic object.
2026-10-17 15:44:45 -05:00
Chris Tate 4018a1d957 Compile async functions that suspend only at their awaits to stackless coroutines (#1204) 2026-10-17 15:38:36 -05:00
Chris Tate e331d7e53b Copy callback helpers per known callback target (#1206) 2026-10-17 15:36:18 -05:00
Malte UblandClaude Opus 5.5 3008edde94 Sequence the timer turns in the stackless async corpus programs
stackless-async-context.ts woke two concurrent workers from 2 ms and 1 ms
timers. The deadlines were taken when each worker scheduled its timer, so
on a slow build both could be due on the same tick in either order. Those
workers now wake from gates that chained timer callbacks open one per
turn in a fixed order. Each woken body still crosses a timer and
nested awaits with its own AsyncLocalStorage context. The sequential
chain workers keep one pending timer at a time.

stackless-async-ordering.ts scheduled setTimeout(0) and setImmediate from
the main module, where Node leaves their order to timing; the lines never
printed only because main finished first. Main now awaits a timer whose
callback schedules the immediate, a microtask and a tick, so the
macrotask order is pinned and printed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 13:14:54 -07:00
Malte UblandClaude Opus 5.5 1d1e934b4c Copy callback helpers per known callback target
Direct calls whose callback arguments resolve to known functions call a
copy of the helper made for that tuple of targets, so the constant-callback
analysis devirtualizes and LLVM inlines the callback. Constant callbacks
also resolve through recursion that forwards the callback, through other
consumers' parameters, and through unwritten captures.

Copies are limited to bodies of at most 300 IR nodes and 4 copies per
function, which keeps the self-hosted compiler within 1% of its size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 13:14:49 -07:00
Chris Tate d7ac988fec Return primitive receivers from Object.setPrototypeOf for any object prototype (#1202) 2026-10-17 15:06:23 -05:00
Chris Tate 8e3b32ee3c Convert class instances with their own valueOf and toString in dynamic operators (#1201) 2026-10-17 15:00:18 -05:00
Chris Tate 0b7e777689 Support net.SocketAddress and net.BlockList (#1200) 2026-10-17 14:56:25 -05:00
Chris Tate 8e061e6859 Keep power-of-two remainders on integer paths where truncation is a round trip (#1198) 2026-10-17 14:51:44 -05:00
Chris Tate fe611d3663 Add Int32[] element contracts (#1199) 2026-10-17 14:49:24 -05:00
Chris Tate 1ed65c27b6 Remove retain/release pairs through private-array precision and last-use moves (#1196) 2026-10-17 14:43:49 -05:00
Chris Tate 4e3138ceda Keep optional, nullable, and dictionary JSON members on the direct schema parser (#1193) 2026-10-17 14:39:47 -05:00
Chris Tate bff94f18ce Return primitive receivers from Object.setPrototypeOf for any object prototype
Object.setPrototypeOf with a boolean, number, string, bigint or symbol
receiver now returns the receiver when the prototype is null or any object
or function, including class instances, classes, Maps, Sets, typed arrays,
promises and Object.prototype. Other prototypes throw a TypeError, as in
Node.
2026-10-17 14:38:11 -05:00