The error-path copy of a zlib callback reads its result from a hidden
local that was immutable, so a body that assigned a fallback Buffer to
the result (if (!out) out = Buffer.from("fallback")) failed to compile
with an internal compiler error. The local is now mutable, and an
assigned value is read back as a checked-dynamic value, as in Node.
A nested callback lowered inside an outer error path passed the absent
Buffer on into a Buffer slot even when its own operation succeeded, so a
callee such as (err, out) => cb(err, out) received undefined instead of
the result. The forwarded value is now the Buffer when there is one.
A named function expression passed to zlib can call itself, and a
function expression can reach itself through arguments.callee, with an
error and a Buffer. Such functions no longer count as called only by
the adapter, so their success copy keeps the runtime error checks
instead of folding them to the success case.
Node calls a zlib callback with (err, undefined) when the operation
fails. The callback adapter passed a NULL Buffer in the result's static
Buffer slot instead: member reads crashed and typeof printed "object".
This applied to deflate, inflate, deflateRaw, inflateRaw, gzip, gunzip
and unzip, with and without options, for callback literals and for
function values.
A function shaped (err, out), with err typed Error | null and out a
Buffer that the body reads, now tests out on entry (bytes.isAbsent).
With a Buffer, the body runs as before. With the NULL Buffer, a second
copy of the body runs with out read as any holding undefined, so typeof,
comparisons, templates, optional chains and console.log give Node's
answers and member reads throw Node's TypeError. Passed on into a Buffer
slot, out stays the NULL Buffer, which a callee with the same entry test
reads as undefined. The parameter keeps its static type, so callers and
adapters are unchanged. A copy that has no such lowering throws SC2020
when it runs.
Conditions on the error parameter fold in the error-path copy, and in
the success copy for a literal that only the adapter calls. Inside an
error-path copy, a nested callback lowers once with its result read as
any, so nested callbacks grow linearly in code size.
An event that typed code only listened to with a listener taking no
parameters had no bridge entry: the scan marked a listener as typed only
when one of its parameters was not a checked-dynamic value. Emitting the
event through an `any` reference then threw instead of calling the
listener. A TypeScript listener with no parameters now marks the event as
typed. A JavaScript function without parameters still registers as before,
since it can read `arguments`.
The first Object.freeze, Object.seal or Object.preventExtensions of a typed
function creates its property table from the function's dynamic box. The
box had no name, so later `f.name` reads answered "". The box now carries
the function's JS name, as a closure flowing into any checked-dynamic slot
does.
The runtime's own callers (published values, os and node constants, the
private-range block list, Wasm exports) freeze data they built, and now
call scr_dyn_freeze_data, the freeze for values that are not functions.
Object.isFrozen, Object.isSealed and Object.isExtensible read a
function's existing table and answer false, false and true when it has
none. Fully typed programs therefore link no dynamic-tier object code
for these calls again.
tsc wraps every CommonJS import in its helpers: `const events_1 =
__importDefault(require("events"))`, `const path =
__importStar(require("path"))`. cjs-tsc-interop.ts reads such bindings of
program modules as plain require bindings, so the helper declarations go
dead, but a builtin module is not a program module: its binding kept the
helpers live, and their probe of the module's top-level `this`
(`(this && this.__importDefault) ||`) failed at load ("property access
through top-level 'this'"). That is the shape of hundreds of tsc-compiled
files in a typical dependency tree.
A builtin carries no `__esModule`, so `events_1.default` is the module and
the namespace copy reads the module's members. When every reference has
that form, a package-file stage now respells the binding as the plain
require() of the builtin and `x.default` as `x`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AstWireFile read every node field with DataView.getUint32 after checking
the index with Number.isInteger and a range compare. In the compiled
compiler the DataView read, Number.isInteger and its trunc are runtime
calls on every access, and parent, kind, next and data run on every child
of every walk.
The node table is now a Uint32Array: a view of the response when the
table starts on a 4-byte boundary on a little-endian host, otherwise a
copy decoded once with astU32. Each accessor checks its index with
index >>> 0 === index and the node count, which accepts the same indices
as before, and throws the same error through an out-of-line function.
Decoded strings are cached in an array indexed by string slot instead of
a Map. The checks of sibling, parent, list and named-child links are
unchanged and still run when each node is read.
The emitter's analyses repeated whole-module work. dynamicFieldStores
walked every function five times on the emitted module (the emitter
constructor, the int32 slot analysis, the final field analysis and both
cycle mutability analyses), findInitializerBindings ran twice,
functionCallFacts walked every function three times, the int32 slot
analysis walked every function four more times before its fixpoint, and
the runtime feature scan ran two to four times.
The constructor now computes dynamic field stores and initializer
bindings once and passes them to the analyses, which compute them
themselves when a caller does not. functionCallFacts and the int32 slot
analysis collect their call, arity, box and reader facts in one walk per
function and apply the facts that depend on earlier steps, in walk
order, where those steps complete. The emitter reads one runtime feature
scan, taken the first time any feature is needed. Emitted LLVM is
unchanged.
Revert 3a27a92cb ("Forward at most four emit arguments through
EventEmitter method values") and 0cf62ebec ("Answer EventEmitter methods
read as values off compiled emitters"). Under the scope-B plan,
EventEmitter methods read as values, `EventEmitter.prototype.on` in
JavaScript and constructor-function emitters belong to Node islands, not
the native compiler. The typed/untyped listener sharing and the
catchable throw in place of the trap stay.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A union, unknown or any value is converted to a dynamic value before it
is thrown, and promise rejections and other runtime throws carry dynamic
values too. A catch binding then holds a dynamic payload, which the
native class test does not recognize: `e instanceof C` was false for
every class of a hierarchy, and a read narrowed by it trapped. A test
through a parameter of type unknown was already correct.
When a class or one of its subclasses crosses into unknown, the class
dynamic-dispatch pass now routes the catch-binding tests of that class
(`e instanceof C`, the reads it narrows and `e as C`) through helpers
that keep the native test and answer a dynamic payload with the dynamic
class test, as standalone classes already do. The new "dynamic" caught
test selects that payload, so native payloads are not converted.
Programs whose classes never cross into unknown compile as before.
fs.promises.rm(path, options) accepts the { recursive, force, maxRetries,
retryDelay } literal options that rmSync accepts. It runs the same removal
and rejects with its errors.
Removing a directory without recursive now throws Node's ERR_FS_EISDIR
SystemError from rmSync and fs.promises.rm. A retryDelay outside int32 >= 0
or a maxRetries outside uint32 throws ERR_OUT_OF_RANGE. rmSync checks these
options before the path, and fs.promises.rm checks the path first, as Node
does.
Fixes#1615
Co-authored-by: jlucaso1 <55464917+jlucaso1@users.noreply.github.com>
The runtime's ToIntegerOrInfinity for string index arguments (slice,
substring, charAt, indexOf, startsWith, padStart, repeat and the others
in scr_string.c) converts through int64 instead of calling trunc, which
is a libm call on baseline x86-64. Each slice made two such calls.
The frontend's syntax trees and program state refer to each other, so
reference counting frees almost none of them when a build disposes the
frontend. Whether a cycle pass reclaimed them before the build ended
depended on where the collector's schedule happened to be. Passes during
the frontend found its data live and widened the growth fractions, so the
next pass waited until the heap had grown well past its size at disposal,
and the dead frontend and the emitter's garbage stayed until the build
ended.
The native compiler now runs scr_collect_cycles_phase right after it
disposes the frontend, through a host function. The runtime entry point
sweeps, then restarts the growth fractions and the death rule's backoff
from the heap the sweep leaves, as after a productive pass. Under Node
the hook is unset.
When a script thread parks its allocator arena, each class slice still
holds the pages past its bump pointer that were faulted in but never
carved: the rest of the huge page the bump pointer is in, and the pages
the pre-fault helper faulted in ahead of it. The same applies to region
chunks when the thread exits. Until another thread claims the arena,
nothing carves there, so a program that continues on threads that never
claim it (parse threads ahead of a check on the main thread) kept them.
- scr_sa_park_arena returns those pages with MADV_DONTNEED. The next
thread to claim the arena faults them in again as it carves, and they
read as zero, as fresh pages do.
- scr_rgn_thread_exit returns each chunk's pages past its bump on worker
threads; nothing carves in an exited thread's regions.
- scr_mem_release_ahead drops pre-fault requests that overlap the range
and waits for one in progress before returning it, so the helper does
not fault the pages in again.
- scr_alloc.test.c checks that a worker that shares and carves past the
huge-page switch leaves no resident pages past its frontier, keeps its
blocks, and that the next thread carves on from the frontier, zeroed.
A generic arrow or method held by an object literal is also lowered with
its type parameters erased, for the literal's own value. In that lowering
the object it returns builds as a checked-dynamic value, so a callback
member with an optional or defaulted parameter, such as
`decode(value, at = [])`, met a slot type that maps to a dynamic value.
The completed-signature check refused it with SC1090, although the same
code in a standalone generic function compiled.
A slot whose type maps to a dynamic value now takes the function the same
way an 'any' slot does: the value boxes into a checked-dynamic function,
which completes omitted arguments with undefined.
Fixes#1373
Co-authored-by: blurname <50226652+blurname@users.noreply.github.com>
TypeScript accepts parentheses and non-null assertions around the
reference an assignment, a `++`/`--` update or a for-in/of head writes
(`(x) = 1`, `h.sums[k]! += 10`), and both are erased at run time. The
compiler now reads its source files with the AstFile writeTargets option:
the writer's `left`, `operand` or `initializer` is the reference itself
and the reference's `parent` is the writer, so lowering and every analysis
of a binding's or member's writes see one shape. The reference keeps its
own source span. Files read without the option, such as type nodes from
the checker and the AST conformance tests, keep TypeScript's exact tree.
Fixes#1625
Co-authored-by: ejc3 <1694850+ejc3@users.noreply.github.com>