Commit Graph
6750 Commits
Author SHA1 Message Date
Chris Tate a00d56e518 Fix the int32 array CI failures 2026-10-23 02:26:57 -05:00
Chris Tate 358d2df536 Keep package results that pass their argument through out of the declaration boundary
A package function declared to return its own type parameter, which also
types one of its parameters (<T extends object>(obj: T) => T), hands back
the argument or something standing in for it, and the package may track
that object's identity. Effect's Equal.byReference returns a proxy it
keeps in a WeakSet. The declaration-typed boundary cast such a result to
the argument's type and built a separate native record, so
Equal.equals(a, b) on two by-reference objects compared them by value and
printed true where Node prints false. The result's type comes from the
caller's argument, not from data the package declares, so the projection
no longer casts these calls.

The package re-export coverage test now expects three dynamic statements:
since the boundary, readRows's declared number result keeps its type, so
count - 1 in 7004-package-declared-type-reexports is native arithmetic.
2026-10-23 02:23:33 -05:00
Chris Tate 94c00200ff Create untyped class instances' property-bag entries without the class tables (#1961) 2026-10-23 02:18:39 -05:00
Chris Tate b7d187f889 Keep inline caches for bag helpers with class-table exits 2026-10-23 02:10:57 -05:00
Chris Tate 76e57eac7f Merge main 2026-10-23 02:00:06 -05:00
Chris Tateandblurname 2f88f35281 Freeze records that other references still hold
Object.freeze of a record that another reference may still hold stopped at
compile time with SC2020 ("possibly-aliased value"), and freezing a record
held in an untyped value threw SC2020 at run time. Node freezes the object
itself: every later write through any reference throws a TypeError in
strict mode code and leaves the object unchanged in sloppy-mode code.

- A record a program may freeze keeps a frozen bit in its reference count
  word. A shape is freezable when a typed Object.freeze names it, or, in a
  program that freezes untyped values, when a value of it can be held as a
  live untyped reference. Only those shapes change: their release ignores
  the bit, and every write to them, keyed writes and deletes included,
  checks it first.
- Object.freeze of a record held in an untyped value sets the bit and
  freezes the record's checked view, so Object.isFrozen, Object.isSealed
  and Object.isExtensible through that value answer for the frozen record.
  A typed Object.isFrozen of a record reads the bit.
- Programs that never freeze a record compile to the same IR and LLVM.

Corpus 7404 covers typed and untyped freezes, a recursive freeze through
unknown, keyed writes and deletes, optional-field deletes, Object.assign,
tuples, and frozen records that are released or collected as cycles, in
strict mode code. 7405 covers the same writes in sloppy-mode code. Both
match Node.

Refs #1374

Co-authored-by: blurname <50226652+blurname@users.noreply.github.com>
2026-10-23 01:56:34 -05:00
Chris Tate 2232c716a8 Compile instanceof against constructors held as values (#1909) 2026-10-23 01:56:13 -05:00
Chris Tate a71d15387d Exit the untyped class tables early for values that are not class capsules (#1962) 2026-10-23 01:55:52 -05:00
Chris Tate 6fba766e58 Merge main 2026-10-23 01:52:29 -05:00
Malte UblandClaude Opus 5.5 da546c05b3 Format the class-table exits
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 23:51:04 -07:00
Malte UblandClaude Opus 5.5 604f647e30 Update the normalization unit test for the hoisted receiver
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 23:50:59 -07:00
Malte UblandClaude Opus 5.5 756a93a8f2 Exit the untyped class tables early for values that are not class capsules
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 23:50:59 -07:00
Malte UblandClaude Opus 5.5 14a2769f58 Create untyped class instances' property-bag entries without the class tables
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 23:50:58 -07:00
Chris Tate f5cecccf5c Reflect the prototype of function-local classes without prototype members (#1958) 2026-10-23 01:46:06 -05:00
Chris Tate 1d68edc0f6 Give function-local class prototypes their own constructor
The prototype object of a function-local class, created once per evaluation
of the class, now starts with its own non-enumerable `constructor`, the
class value of that evaluation, as every class prototype does. Reflecting
the prototype of a function-local class without prototype members exposed
an object without it: `proto.constructor` answered the base class, and
`Object.hasOwn(proto, "constructor")` and its property descriptor did not
match Node.
2026-10-23 01:39:26 -05:00
Malte UblandClaude Opus 5.5 14ba361985 Call own accessors over an Error's name and message from typed code
zod 4 defines its error message with Object.defineProperty(inst, "message",
{ get, set }). The typed-ref commit of an Error subclass read the accessor
as a data value and threw "expected string". The commit and the slot sync
now leave the slot alone and mark the property absent; typed reads and
writes of name and message call the accessor when the program reflects on
an untyped or Error-shaped target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 23:34:56 -07:00
Chris Tate b6d6eb60ae Replace a scheduled _construct hook, and keep runtime option values in order
Node's constructNT reads _construct on the construction tick, so an
assignment after the constructor and before that tick replaces a scheduled
construct hook. The assignment was dropped, so the original hook ran. It
now lowers to stream.replaceConstruct, which swaps the hook while its tick
has not run and has no effect after it or on a stream without a hook.

Runtime decodeStrings and defaultEncoding values are read into locals
before the constructor evaluates the other option members, while Node
evaluates the members in order. A runtime value after a member whose value
has effects (a call or an assignment) now refuses instead of reading a
value that member could still change.
2026-10-23 01:34:19 -05:00
Chris Tate 2ebb89b0ef Store number arrays of proven int32s in 4-byte slots across direct calls
An int32 array candidate can now be a module global or a parameter, not
only a local. A number[] parameter qualifies when its function is reached
by direct calls alone (not as a value, a method or a constructor, and not
through a result-slot entry the backend calls in its place), it is never
written, and every call passes a candidate at its position; a local,
global or parameter may then be passed there as well. A global qualifies
when every function reads it only in candidate positions and every write
stores a fresh array. moduleInt32ArrayCandidates finds them by dropping,
pass after pass, the ones a function or call disqualifies.

The candidates one array can reach through calls form a group
(int32ArrayGroups): the int32 slot analysis keeps or drops a group as one,
since a store through any member writes the same array. A module with a
module namespace object keeps its globals in doubles, as member reads can
reach any global by name.
2026-10-23 01:24:41 -05:00
Chris Tate 7dfc96728d Merge main 2026-10-23 01:19:49 -05:00
Chris Tate 15e3d8f9aa Merge main 2026-10-23 01:13:27 -05:00
Chris Tate 80f0bfada2 Resolve a forward local class per instance in hoisted functions (#1959) 2026-10-23 01:07:52 -05:00
Chris Tate 291aad0f8b Merge main 2026-10-23 01:07:14 -05:00
Chris Tate 387419720e Support String.prototype.at on strings held in untyped values (#1948) 2026-10-23 01:03:32 -05:00
Chris Tate d942c27c2f Merge main 2026-10-23 01:01:03 -05:00
Chris Tate f3a903607d Merge main 2026-10-23 00:54:10 -05:00
Chris Tate 468e0592bd Enumerate each record in the key order its object literal wrote (#1943) 2026-10-23 00:51:23 -05:00
Chris Tate 0418911874 Build the native compiler again after the two-counter while loop pass (#1956) 2026-10-23 00:50:32 -05:00
Chris Tate 341868ea9e Build fresh literals a JavaScript callee may reshape as plain objects (#1951) 2026-10-23 00:46:30 -05:00
Chris Tate c50fb1275e Build the native compiler again after the two-counter while loop pass
The native compiler spreads only known record shapes, from values whose
type no longer includes undefined (SC1090). runPairedWhileLoopsAsFor
copied a counter's local read through a non-null assertion, and renamed
counters by spreading nodes narrowed to several kinds. It now tests the
local against undefined and renames one node kind at a time. The pass
rewrites the same loops to the same IR.
2026-10-23 00:46:09 -05:00
Chris Tate e8d1c2f47b Keep arrays stored through a typed global view native (#1952) 2026-10-23 00:45:28 -05:00
Malte UblandClaude Opus 5.5 2f882e1e1e Reflect the prototype of function-local classes without prototype members
Object.getPrototypeOf on an instance of a function-local class refused
unless its prototype members were installed at run time. A class that
declares no prototype methods or accessors (zod 4's
class Definition extends Parent {}) has nothing to install, so its shared
prototype view is returned, as is a bare Local.prototype value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 22:44:07 -07:00
Malte UblandClaude Opus 5.5 20d0a6c7eb Resolve a forward local class per instance in hoisted functions
A JavaScript package function lowered once per argument-type tuple
collects its local class per instance. A function hoisted above the class
statement in a later instance resolved the class an earlier instance
collected (zod 4's $constructor: "expected class constructor"). It now
takes the forward-class TDZ box unless the collected class is this
instance's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 22:44:07 -07:00
Chris Tate 5c5d0f5a0f Merge main 2026-10-23 00:42:41 -05:00
Chris Tate 638750751f Merge main 2026-10-23 00:38:51 -05:00
Chris Tate 108df00b29 Keep wrapped array literals native in typed global views
A fresh array literal wrapped in parentheses or `satisfies` on the right
side of a write to a member of a typed view of the global object
(`g.cache ??= ([])`, `g.cache ||= [] satisfies number[]`) is now built as
the declared native array too, so typed reads return the same array.
globalViewSlot walks up through those wrappers to the write's right operand
and answers it, and the slot type comes from that operand's contextual type.
2026-10-23 00:37:49 -05:00
Chris Tate 6e71385a1a Type user code from npm package declarations at a checked, identity-preserving boundary (#1942) 2026-10-23 00:33:02 -05:00
Chris Tate cba3fa6a05 Keep projected files valid for bare async arrows and unbraced bodies, and adopt tuple elements
- A bare arrow parameter after `async` (`async x => ...`) gets parentheses
  with its projected type, as `x => ...` does. Without them the rewritten
  file failed its check and lost its projection (SC6102).
- A cast that starts an unbraced loop or `if` body gets no `;` guard. Only
  a statement in a statement list can continue the previous line, and in
  a body the `;` became the body, which moved the statement after the
  loop.
- Adoption walks a tuple's elements through the live element capsules of
  the tuple's view, so references package code holds to them see the
  native values.
- scr_runtime.h declares scr_dyn_decl_adopt (in scr_dyn.h), which the
  backend emits, so llvm-runtime-abi.test.ts finds its prototype.
- npm.test.ts gives zod3-adoption and zod3-boundary the long per-case
  timeout of the other zod 3 cases; their sanitized builds compile zod's
  types module too.
2026-10-23 00:25:59 -05:00
Chris Tate 2edbe9186a Declare flock on macOS in the native compiler host (#1955) 2026-10-23 00:14:08 -05:00
Chris Tate 257d4dc5cb Declare flock on macOS in the native compiler host
host.c defines _POSIX_C_SOURCE, under which Darwin's <sys/file.h> hides
flock and LOCK_EX/LOCK_UN, so the native compiler build failed on macOS
with an implicit declaration error. Define _DARWIN_C_SOURCE on Apple
targets before the system headers. Linux preprocessing is unchanged.
2026-10-23 00:11:30 -05:00
Chris Tate f8fdb3b3f5 Call observed class methods natively while their slot is unchanged (#1950) 2026-10-23 00:09:35 -05:00
Chris Tate 4a17b3f461 Keep the dynamic call for observed methods called with a spread argument 2026-10-23 00:05:57 -05:00
Chris Tate a9b551a091 Fold navigator member reads under optional chains (#1954) 2026-10-22 23:59:26 -05:00
Chris Tate 67cfa74d92 Dispatch checked-dynamic method calls on method ids (#1953) 2026-10-22 23:56:15 -05:00
Chris Tate 0314d9db3e Dispatch checked-dynamic method calls on method ids 2026-10-22 23:52:25 -05:00
Malte UblandClaude Opus 5.5 390ac6f326 Call observed class methods natively while their slot is unchanged
Any computed write with a key TypeScript cannot know (zod's
`curr[el] = ...` in ZodError.js, for one) puts every class method name
in the method census. Every typed call of such a method then went
through the observable prototype slot: a dynamic call with boxed
arguments, followed by a checked conversion of the result (for a
`Product[]` result, a deep walk of every element). Bundling untyped
JavaScript made unrelated typed code several times slower per call.

The prototype data now keeps each observed method's original value in a
global. A typed, non-virtual call of a TypeScript method still reads the
slot first, as before, and calls the method natively when the slot holds
that original value. A replacement, on the prototype or as an own
property, still takes the dynamic call. Virtual calls and methods
declared in unchecked JavaScript keep the dynamic call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 21:52:15 -07:00
Chris Tate f03b798ea5 Convert typed arrays to BigInt through their element text (#1934) 2026-10-22 23:31:39 -05:00
Malte UblandClaude Opus 5.5 37ea2c9ce7 Keep arrays stored through a typed global view native
A fresh array literal written to a checked-dynamic slot is built as a
dynamic array. On a member of a typed view of the global object
(`(globalThis as typeof globalThis & { cache?: number[] }).cache ??= []`)
the program reads it back through that declaration, and each typed read
extracted a new native copy. `cache().push(x)` was lost, and two reads
were never the same array. Node keeps one array.

When the literal is the right side of a write (`=`, `??=`, `||=`) to a
member of the global object, and the member is declared as a native
array, build the native array and store it boxed. Every typed read then
extracts that same array, and untyped reads see it through its live
capsule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 21:31:28 -07:00
Chris Tate d027786c80 Convert Buffers and DataViews to BigInt through their own text
BigInt of byte storage joined the elements with "," for every kind, so a
Buffer, whose text is its UTF-8 decoding, and a DataView, whose text is
"[object DataView]", converted as typed arrays. BigInt now parses the
value's ToString, which the runtime value decides, as String does. This also
covers a Buffer held in a Uint8Array slot.

Corpus 7403 adds Buffers, a DataView, and a Buffer in a typed array slot.

Refs #1647
2026-10-22 23:29:34 -05:00
Chris Tate 5159d2e966 Keep replaceable method results that have no dynamic form native (#1947) 2026-10-22 23:28:45 -05:00
Chris Tate c5f0dbbebf Run two-counter while loops on integer counters (#1946) 2026-10-22 23:28:18 -05:00