A class behind an interface whose method is generic now dispatches to
the method's erased instance, so the boundary test compiles the program
instead of expecting the old refusal.
Fixes#905
Co-authored-by: Konstantin Mikheev <8560582+konmik@users.noreply.github.com>
An override whose return type is part of the base method's union return
(`Meta` for `Meta | undefined`, `number` for `number | undefined`, or a
subclass of one of the union's class arms) was refused with SC1090,
although TypeScript accepts it. The override now returns through the
base's union ABI, so calls through the base type receive the value
unchanged, and calls resolved to the override narrow the result back to
its declared type.
`value.valueOf()` on a dynamic receiver was refused at compile time, a
class's own toString was not reached by `value.toString()`, and classes
could not declare a `[Symbol.toPrimitive]` method.
- `value.valueOf()` lowers to dyn.valueOf, which answers each kind's own
valueOf: a primitive itself, a Date its time value, an object with a
valueOf member that member's result, and any other object itself. A
null-prototype dictionary throws "<spelling> is not a function", and
null and undefined throw Node's property-read TypeError.
- When a boxed class declares valueOf or toString, `value.valueOf()` and
`value.toString(argument)` call the class's method for its instances
and keep the runtime call for every other value.
- Classes can declare `[Symbol.toPrimitive](hint)`. The dynamic
conversions call it with "default" for `+` and `==`, "number" for the
numeric operators and conversions, and "string" for template literals,
String() and property keys, and throw Node's TypeError when it returns
an object.
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.
The worker series adds 16 corpus programs without measured costs in
tests/harness/corpus-costs.json, which dropped the measured share below
shard.test.ts's 0.9. Their plain and san costs are local timings of each
program's differential and llvm-differential cases, scaled by the median
ratio between the recorded and local timings of four programs timed in
the same run (001-hello, 1000-json-stringify-basics,
5022-lifetime-region-workers, 5164-worker-field-callback-receiver).
5805 read its second message right after the first arrived; under load
the parent's second postMessage could still be in flight, so the read
answered undefined. The worker now waits on a shared flag that the
parent sets after posting its first three messages. The output is
unchanged.
Generic arrow properties and generic methods now have an erased runtime
value, their instance with every type parameter bound to unknown. Calls
through a round trip via any, a function result, an array element or a
class-backed interface call that value and convert the result to the
call's type, as JavaScript does. Direct calls on a known definition keep
their monomorphized path.
Fixes#905
Co-authored-by: Konstantin Mikheev <8560582+konmik@users.noreply.github.com>
- util.format %d and %i format bigint, symbol, null and undefined arguments
- util.format %j prints [Circular] for circular arguments
- util.types answers the remaining brand checks
- util.inspect prints WeakMap, WeakSet, Date and numeric typed array values as Node does
- util.inspect lowers the breakLength, compact and sorted options
- URLSearchParams iterators compile outside a for-of head
- URLSearchParams can be built from [string, string] tuple pairs
- querystring.stringify writes bigint values
- StringDecoder accepts an encoding known only at run time
- os.setPriority is lowered
- 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
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>
Index loops over arrays left the counter a double in several common
shapes, and every element access at the counter tested the array's
hole-free prefix on each pass:
- A syntactic proof (ir/array-length-stability.ts) shows that a loop never
changes an array's length: the body runs no user code, never rebinds the
array or lets it escape, and only resizes local arrays that no other
binding can hold. Element writes at a counter kept below the length are
accepted.
- Counted loops take a stable `a.length` as their limit, and an element
access at the counter makes an unversioned counted loop worthwhile, so
strided (`i += 2`) and descending (`i = a.length - 1; i >= 0`) loops get
an integer counter.
- Array lengths bound while-loop and for-loop counters by their range,
which needs no stability proof.
- A loop whose array length is stable and whose indexed arrays keep their
storage runs as two copies. One test before the loop (the length is at
most 2^31 - 1 and at most each indexed array's `filled` bound) selects a
fast copy whose element accesses at the counter skip the prefix test and
whose counter is an int32. LLVM can vectorize that copy.
- Loop counters whose ranges fit in 32 bits convert to double from their
low half, so an inlined callee's index conversion folds away.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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>
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.
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.
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.
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>
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>
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.
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>
When a write with a computed string key can replace any method, calls of
every method name read the receiver's property bag without checking for
the key, and the bag falls back to the class's prototype data. Generic
class instantiations, mixin classes and their subclasses have no prototype
data, so their methods read as undefined and calls threw "x.status is not
a function". Reads on these classes now check for an own property and
otherwise use the declared method.
Fixes#963
Co-authored-by: Quim T. <26749475+espetro@users.noreply.github.com>
`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>
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>
A union of two or more record arms and at most two unit arms (the
discriminated unions of object literals behind Result, token, shape and
AST types) now holds the record pointer instead of a reference-counted
%ScrUnion box, like nullable unions already do. NULL and the existing
null sentinel encode the unit arms.
Every record shape that is an arm of such a union carries its
module-wide shape number in a hidden i32 after the reference count; the
arm of a value is that word mapped through a per-union tag helper, which
LLVM folds into the consumer's switch. Records share one retain; release
and trace dispatch on the arm, and every arm of a union with a traced arm
carries a collector header. Wraps move the record, retypes between such
unions reuse the pointer, and equality is identity. Record field indices
come from the shape's field base.
Unions over records that are also arms of runtime-inspected unions (Map
keys, Set elements), library builds, lifetime-region programs and debug
builds keep boxes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
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.