Skip to content

Typed code generation faster than Node - #17

Draft
Qard wants to merge 65 commits into
mainfrom
perf/typed-codegen
Draft

Qard wants to merge 65 commits into
mainfrom
perf/typed-codegen

Conversation

@Qard

@Qard Qard commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Stream: make typed TypeScript compiled by Tint faster than Node 26.13.1 in every case.

Phase 1 (done): diagnosis (report)

  • tools/typed-bench/: 12 typed kernels (PR Worker runtime performance and typed shared memory #15's five plus typed arrays, string equality and building, Map/Set, closures, arrays, escaping allocation) built with the general fallback disabled; a separate classes image, and a typed basicClasses image (classes without inheritance).
  • bench.ts prepare | smoke | measure | v8-script: rotated paired rounds against Node under LLDB, with candidate images for A/B runs.

Phase 2 (in progress) (progress report)

  1. Decimal string→number fast path: compiler 4.2× → 1.0× (0.95× on Linux).
  2. Integers formatted as one string: strings and stringBuild 10–14% faster.
  3. Typed-array bounds proved against the array's own length; integer elements: numeric 4.6× → 1.1×, typedArrays 2.7× → 1.5×.
  4. FJCVTZS on Apple targets; constants written straight into their home register: small gain.
  5. Inlining allowance for reference callees 128 → 384: allocation −12%.
  6. Allocation: numeric temporaries stay in registers across record allocation, saved only on the slow path: escape 2.61× → 1.99× (0.76 of its previous time). Frozen v7: outputs identical, cycles −0.7% median, −2.6% min.

Typed classes (design, phase C1)

  • Steps 1–2: module classes (and classes directly in non-generic module-level functions) lower natively instead of falling back: one closure per member, generated definition, construction, static-initialization and [[Call]] entries, class-scope binding initialized before static fields. Native instanceof for typed classes; typeof C is "function". Fixtures in tools/native-typed-classes.test.ts are checked against Node.
  • Step 3: own fields have no initialization state (checker-proven, including constructor calls of the class's own methods analyzed in place), class types dispatch on the class layout only, receivers convert once, and inherited method calls devirtualize (closed records) to receiver-passing twins that inline. basicClasses: 76.8 ms → 35.4 ms steady (Node 21.1 ms).
  • Also typed now:
    • temporal-dead-zone reads throw ReferenceError inline;
    • delete of fields that admit undefined, via presence bytes;
    • fields read before their first assignment, with exact undefined reads (primitive fields; contract TypeError at written types);
    • accessors (get/set, also static), devirtualized and inlined like methods;
    • class instances for interfaces with methods: method signatures pass the object as receiver (chosen by measurement: frozen v7 neutral, typed kernel images byte-identical).
  • TypeScript diagnostics as tsc reports them: TS2790/TS2704 (delete), TS2565 (constructor read before assignment) and TS2729 (initializer read before initialization) fail the build; tools/source-validation.test.ts compares with tsc 6.0.3.
  • Class values reaching general code (dynamic objects, thrown values, general and realm calls, exported unknown results) send the module to the general path until step 4's record views exist; values only typed code reads stay typed.
  • Parser: implements, extends Base<T>, overload and index signatures and optional methods in classes used to fail every build; they now parse and erase like TypeScript's emit.
  • x86-64: frame slots of one type with disjoint live ranges share an offset (as on AArch64). This fixes the Linux x86-64 stage 2 stack overflow; the checker's expression walker frame went from 38 KB to 1.9 KB.
  • x86-64 labels: local labels resolve per function, which fixed the Linux x86-64 stage 2 managed-heap exhaustion.
  • Next: C2 (extends) and kernel parity; step 4's runtime part builds on PR Propose general runtime re-architecture from Octane diagnostics #12 after it merges.

Typed-array kinds (notes)

  • Kind table and header: typed-array markers are (kind index << 3) | width class (the original kinds keep 2–5, every built-in marker stays below 32). Collectors, extent decoding, relocation and fixups classify any typed array as pointer-free elements with a header extent through one predicate (nativeTypedArrayMarker); the heap-debugger kind table and DWARF buffer types come from the same table.
  • Native kinds: Int8Array, Uint8ClampedArray, Int16Array, Int32Array and Float32Array are typed now (checker, IR, lowering, AArch64 and x86-64), with ECMAScript conversions: ToInt8/16/32, ToUint8Clamp (round half to even), Float32 rounding and overflow. Typed instanceof and the realm's per-kind prototypes keep each kind's identity. BigInt64Array, BigUint64Array and Float16Array remain realm objects.
  • Evidence: tools/native-typed-array-kinds.test.ts (Node-compared; arm64 under LLDB, x86-64 under qemu) and per-kind Test262 TypedArrayConstructors selections, 158/158 (TZ=UTC).
  • Kernels: new typedArrayKinds kernel at 1.14× Node's time; the existing typedArrays kernel is at 1.41× (parity work pending, as for the other kernels).

Overlaps:

Typed-only gaps recorded in docs/unified-pipeline.md: classes with extends and the remaining C1 items, the BigInt and Float16 array kinds, reduce, parseInt/parseFloat, narrowing from a for condition into its update clause, String() of primitive unions, and top-level expression statements.

🤖 Generated with Claude Code

Twelve typed kernels (PR #15's five Worker kernels unchanged, plus typed
arrays, string equality and building, Map/Set, closures, arrays and
escaping allocation) built as one image with the general fallback
disabled, and a class kernel in a separate image that may fall back
because typed classes do not lower natively yet. bench.ts prepares the
native image and the stripped Node script, smoke-runs both, and measures
rotated paired rounds against Node 26.13.1 under LLDB, with optional
candidate images for A/B runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Qard
Qard marked this pull request as draft November 22, 2026 21:31
Qard and others added 21 commits November 23, 2026 05:55
Fifteen rotated paired rounds on macOS arm64 and Linux arm64 (dev):
Tint loses every typed kernel at steady state, from parity
(stringEquality) to 4.5x (numeric), and the class kernel, which falls
back to general semantics, is 98-100x. Per-kernel pprofessor profiles,
op-cost attribution and V8's optimized code locate the causes and rank
the fixes. bench.ts gains a v8-script mode for the V8 dumps; the gap
table gains the typed-only gaps the suite had to avoid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Number(text) built two 150-word bignums for every decimal string and
rounded their ratio; parseInt and prefixed literals did the same for
every integer. Strings with at most 15 significant digits and a decimal
exponent within 22 now convert with one correctly rounded multiply or
divide (Clinger's fast path), and integer digit runs that stay below
2^53 accumulate exactly in binary64; everything else keeps the exact
bignum path. The typed compiler kernel spent 68% of its samples here.

Node unit tests cover both sides of each bound and 4,000 random
decimals; a native typed fixture checks Number() against V8-parsed
literals across the same bounds. parseInt and parseFloat do not link in
typed code yet (recorded in the gap table).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
decimalInteger prepended a one-unit string per digit, allocating and
copying at every step, with % and floor in doubles. Integers below 10^8
now produce all their digits with one fixed-arity String.fromCharCode
(a single string-from-code-units allocation); larger safe integers split
once at 10^8, correcting the rounded quotient with the exact remainder,
and join two such strings. The typed strings and stringBuild kernels
spent a quarter of their samples in number-to-string conversion.

The native number-text fixture now also checks String() and template
literals against Node across the split, the safe-integer limit and the
shortest-decimal path; Node unit tests add the split boundaries and
2,000 random safe integers. Also records item 1's A/B: the typed
compiler kernel went from 4.19x to 1.02x Node (candidate/base 0.243).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fifteen rotated rounds against the item-1 image: strings 2.04x to 1.88x
Node (candidate/base 0.90), stringBuild 3.19x to 2.70x (0.86); other
kernels neutral. Host load 3-10 during the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bounds pass proved typed-array accesses only for arrays created in
the function with a constant length, so a stencil over a parameter
(i < a.length - 1 reading a[i - 1], a[i], a[i + 1]) kept every access
checked and NaN-boxed its result for ?? 0. The relational string-index
facts now cover typed arrays too and carry a constant margin: Len(L, S,
c) when a slot holds a length minus c (also through copies), Less(I, S,
c) when I + c is below it, from both edges of <, <=, > and >= with the
index (plus a constant) on either side. Less facts are closed downward
so block entries still meet by intersection. An access at I + d (d up to
the margin) or I - d is below the length; the interval facts still prove
it an integer at least 0. Typed-array lengths never change in typed code
(realm views cannot reach the raw typed-array ABI).

Codegen keeps integer elements of word arrays as int64 when every use
takes integers (zero-extending loads, as inline code units do) and
stores int64 values into word arrays from their register instead of
staging them through the frame.

The numeric kernel's stencil step drops from 91 to 33 instructions
(V8: 28); the byte loop of typedArrays is integer end to end. Unit tests
cover margins, both operand orders, inclusive bounds, negative indexes
and reassignment; a native fixture checks the same against Node,
including out-of-bounds fallbacks and ToUint8/16/32 store wraparound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fifteen rotated rounds against the integer-formatting image: numeric
4.05x to 1.00x Node (candidate/base 0.24), typedArrays 2.46x to 1.50x
(0.59); stringBuild read 1.09x base (load 8-10; its code path did not
change), other kernels neutral.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ToInt32/ToUint32 of a double of unknown range (|, &, ^, ~, shifts,
Math.imul and integer typed-array stores) was a seven-instruction int64
round trip with a branch to the to-uint32 helper for fractional, huge
or non-finite inputs. Host ABIs now declare FEAT_JSCVT as a target
property (javascriptConversion: baseline, like sha256Instructions);
Darwin arm64 does, as every Apple silicon core implements it, and those
conversions become one FJCVTZS. Linux targets keep the round trip until
a HWCAP-dispatched form exists.

Integer and float-bit constants are also materialized straight into
their GP home instead of through x9 and a move.

The ISA golden adds FJCVTZS (checked against llvm-mc); a native fixture
checks the operators and integer stores across fractions, -0, NaN,
infinities and magnitudes around 2^31, 2^32, 2^53, 2^63 and 2^64 against
Node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fifteen rotated rounds against the typed-array bounds image under load
8-11: candidate/base medians calls 0.96, typedArrays 0.97, closures
0.96, stringBuild 0.92, the rest 0.97-1.02 (all IQRs span 1). Kept for
fewer instructions and no helper path; the gain is small next to the
host noise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A caller could absorb only 128 units of CFG callees with traced
reference slots, so a loop over a few number lists inlined two reads
(cost 54 each) and called the rest. The per-caller budget is now 384.
Typed benchmark, 16 rotated rounds under load 7-10 (with a resize fast
path that alone measured neutral and was dropped): allocation 2.99x to
2.64x Node (candidate/base 0.875), typedArrays 0.968, closures 0.971,
arrays 0.975, the rest within noise; the image size is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sixteen rotated rounds (Node, the FJCVTZS image, a resize fast path, and
the resize fast path with a 384-unit reference allowance), load 7-10.
The resize fast path alone measured neutral (dropped); the allowance
version moved allocation to 0.875x its base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per-fix A/B results, the frozen v7 check (outputs byte-identical,
instructions -4.6%, no cycle regression, compiler image +5% from the
inlining allowance), and one consolidated rotation of the baseline image
against the current head on macOS arm64 and Linux arm64: compiler 4.2x
to 1.02x (0.95x on Linux), numeric 4.6x to 1.1x, typedArrays 2.7x to
1.5x, strings, stringBuild, allocation and closures 7-14% faster; the
rest unchanged. The remaining causes are re-ranked: dense number-list
and reference-list push fast paths, the allocation contract, a string
append builder, record layout facts, Map/Set probes and integer
induction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A record constructor's inline allocation calls the allocator only on its
slow path, but numeric temporaries crossing it (the fields being stored,
values used after it) were denied FP temporary registers and went
through the frame: in a loop that builds a record from the previous one
(total = add(total, delta)) the spill and reload sat on the loop-carried
chain. Functions whose record constructors have numeric fields now
reserve a 128-byte frame area; record-new preserves d16..d31 for numeric
temporaries (references still end at it), and its slow path saves and
restores the function's FP temporaries around the allocator call. Field
words already in a register home are stored from it (no FP-to-GP
transfer).

A native fixture collects every few hundred records (4 MiB heap) while
temporaries are live across constructors, as fields, after them, as
optional numbers and beside moved references; dropping the restores
makes it fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/design-typed-classes.md: fixed instance layouts with prefix
inheritance, prototype records with shared method closures, guarded
direct calls for exact classes and vtable-like slots for hierarchies,
construction allocating new.target's layout up front, annotated fields
as contracts and unannotated ones open, record views and PR #12's shape
metadata for untyped code, and four phases with explicit failures for
what each does not cover.

The allocation-temporaries A/B (15 rounds, load 3-5): escape 2.61x to
1.99x Node (candidate/base 0.761), other kernels neutral. The gap table
gains for-update narrowing and links the class row to the design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three interleaved rounds against the previous branch build at load
about 4: cycles min 317.1G to 309.0G, median 317.3G to 314.9G, wall
66.0 s to 63.9 s (min), instructions -0.07%; outputs byte-identical;
image +0.5 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A module-level constant read into the mutable per-caller allowance hit
"invalid binding operation" in native module-instance preparation, so
the native bootstrap failed on both Linux CI jobs. The value stays a
literal at its use, with the comment moved there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Prototype validity cells guard every direct method call (receiver
prototype, own shadow, cell), and derived prototypes hold only their own
members, so prototype mutation from typed or untyped code (assignment,
defineProperty, delete, setPrototypeOf) can never be assumed away.
Expandos stay ordinary own properties of the record view; method-named
writes go to own-shadow slots; open and optional fields carry presence
and can be deleted; annotated required fields are non-configurable
contracts (the one deliberate deviation). Observable construction order,
new.target, instanceof via Symbol.hasInstance or OrdinaryHasInstance,
[[IsClassConstructor]], toString and strict class bodies are specified,
with a fixture for each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Module instances move top-level statements into an initializer function,
so typed classes first need scoped contract resolution in the checker
("local classes require scoped contract resolution"), then class
statements in closure lowering, member access and guarded calls, record
views of instances and prototypes, and the fixtures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The configurability of annotated required class fields is a semantics
question for the user; the design now confines it to one policy function
in the class-view layer that no other C1 work depends on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Module instances now evaluate each class statement in their initializer,
where its contract resolves, instead of falling back to general
semantics. The checker resolves contracts for classes declared directly in
the body of a non-generic module-level function; nested classes, classes in
generic functions and shadowing body classes stay unsupported local classes.

Closure lowering creates one closure per member at the class statement,
then calls generated definition, construction and [[Call]] entries
(closure/lowering/class-statements.ts). The class-scope binding is
initialized before static fields run and the statement binding after them;
static methods live in the constructor-state record and static fields
initialize in source order through a generated static entry. Calling a
class without `new` throws V8's TypeError.

- `readonly` instance fields and prototype methods are writable storage:
  `readonly` is TypeScript-only and untyped code may write them.
- An assignment to an unset own field of a class instance defines it, so
  constructor bodies may assign a field more than once.
- `x instanceof C` for a typed class tests C's instance layout and compares
  the operand's prototype pointer with C.prototype (OrdinaryHasInstance);
  typed constructors have no realm view yet, so no Symbol.hasInstance check.
- `typeof` of a callable or constructible object type is "function".

Native fixtures (tools/native-typed-classes.test.ts) check field
initialization order, constructor bodies, statics and their order against
the class bindings, method identity, own overrides and prototype mutation
from typed code, instanceof, typeof, exceptions from initializers and
constructor bodies, and collection under a small heap, against Node.
Record views for untyped code (step 4) and guarded direct calls (step 3)
follow; new typed-only gaps are listed in docs/unified-pipeline.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Typed class code now compiles to plain field accesses and inlinable
method calls:

- Own data fields of class instances are `deferred` record fields: the
  construction entry leaves them zero-filled with no initialization state,
  since the checker proves each is assigned before it is read. The IR
  verifier accepts omitting a deferred field at construction.
- Values of a class instance or prototype type dispatch only on the class
  layouts, also for structurally identical types interned separately, so
  record facts prove the layout after the first check. Object literals typed
  as a class instance fail explicitly.
- Methods convert their receiver once on entry, without trapping, into an
  optional reference that `this` reads.
- A method call reads an inherited method into a slot only prototype reads
  write, and calls through it; an own override takes the ordinary call.
  Closure devirtualization now handles calls with receivers: under closed
  records it calls a twin taking the receiver (and environment) as trailing
  parameters, and the inliner accepts general-value operations, so small
  methods inline.

The typed benchmark gains a `basicClasses` suite (classes without
inheritance): 76.8 ms -> 35.4 ms steady on macOS arm64 (Node 26.13.1:
21.1 ms). Frozen v7 is unchanged within noise with identical output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `delete` of a required property fails the build with TS2790, and of a
  readonly property with TS2704, as the pinned TypeScript reports them
  under strict checking (user decision). Tint's checker reports the same
  codes and spans definitively, so native builds without the hosted
  validator fail like tsc. Optional and open operands stay valid and take
  the general path until typed deletes lower.
- Class fields keep their `readonly` and `?` modifiers in the syntax tree.
  `x?: T` fields admit undefined and need no constructor assignment.
- Object literals typed as a class instance construct plain records again;
  accesses through the class type dispatch on the class layout first and
  on the plain layout only when such a literal exists.
- Fixtures: class-typed literals on the typed path, and field reads before
  assignment (a method called from the constructor, a base constructor
  dispatching to an override) observing undefined on the general path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blacksmith-sh blacksmith-sh Bot mentioned this pull request Nov 23, 2026
15 tasks done
Qard and others added 5 commits November 23, 2026 13:19
A typed read or write of a `let` (or class) binding before its
declaration ran trapped the process; it now throws a catchable
ReferenceError with V8's message, "Cannot access 'x' before
initialization", naming the source binding.

- Native errors gain a ReferenceError brand (error-new, error-is) in the
  IR, aarch64 and x86-64; `instanceof Error` covers it.
- Realm programs project it through a fourth generated error view
  (`getReferenceErrorView`), realm `instanceof` classifies it with the
  realm's ReferenceError prototype, and typed `instanceof Error` tests
  include it.
- Typed builds always ask the linker for source binding names; lowering
  gives locals their source name for messages (and callable views their
  `name`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Instance fields no longer carry initialization state (C1 step 3), so the
hand-built class record fixture writes the field directly and its test
checks plain record access; the hosted class-records verifier expects a
deferred field and plain (uninitialized-state-free) access choices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The temporal-dead-zone ReferenceError is built and thrown inline in one
block per binding and handler context instead of through an out-of-line
helper call: a call disqualifies leaf registers in every function with a
checked cell (the helper version ran the frozen v7 workload with 0.6%
more instructions). Inline: frozen v7 output identical, cycles neutral
(medians 318.9 vs 319.7 billion), instructions +0.46%; the compiler image
grows 3.3% (53.3 -> 55.1 MB) for the shared throw blocks.

docs/design-typed-classes.md records the step 4 plan: publish views at
erasure points, general method storage, the prototype validity cell as the
direct-call guard (landing with the views), contracts and the delete policy
through views, and instanceof with views.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Classes whose constructors (or field initializers) call their own methods
no longer fall back: the initialization checker analyzes each `this.m()`
call during construction in place. The method may read fields assigned
before the call, and the fields it definitely assigns count as assigned
after it (loops, switch, try and labels are handled conservatively). The
analysis applies while no code writes through a `prototype`, so the calls
reach the defined methods; recursion and own overrides escape as before.
Classes that may genuinely read a field before assignment still fall back
(interim, recorded in the design).

docs/design-typed-classes.md now plans step 4 on PR #12's object model:
record-backed fast views whose fixed-layout shapes address the instance
record, prototype views with method callable views, the compiler-side
seam, and the runtime interface needed from #12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IR values are local to their block (the verifier requires it) and x86-64
stack maps include a value's home only while it is live within its block,
so every block now reuses one area of value homes, sized by its largest
block, instead of giving each value of the function its own home. Frames
shrink accordingly. The temporal-dead-zone throw blocks added three or four
values each to functions with checked cells; with function-wide homes that
deepened frames enough for the native x86-64 compiler to fail stage 2
(the gate passed with those blocks reverted to traps).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qard and others added 22 commits November 23, 2026 22:14
The typed path held only Uint8, Uint16, Uint32 and Float64 arrays
natively; the other numeric kinds were realm objects whose constructors
fell back to the general path. They are now native kinds throughout:
checker types, IR scalar types (appended codec, signature and general-test
codes), lowering and both backends. Element writes convert as ECMAScript
requires: the integer kinds store ToInt32's low bits, Uint8ClampedArray
stores ToUint8Clamp (AArch64 FCVTNU then a clamp; x86-64 CVTSD2SI after
range checks; int64 values clamp directly) and Float32Array rounds to
nearest, ties to even. Reads sign-extend or widen. Typed instanceof and
the realm's per-kind prototypes distinguish every kind.

The hand-written four-kind lists become shared helpers (IR
nativeTypedArray/typedArrayLayout/typedArrayScale/typedArrayMarker,
checker nativeTypedArrayKind), and the word-fact, zero-sign and word-kind
analyses no longer treat Float32 elements as integers. On AArch64 the
fused `??` reads and checked writes use register-indexed loads and stores.
BigInt64Array, BigUint64Array and Float16Array remain realm objects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A class extending a non-generic typed class by name now gets a contract:
its instance type lists the base's properties first (so a derived layout
can extend the base's as a prefix), overrides replace the members they
override in place and must relate to them (methods bivariantly, without
receivers, as method syntax relates), and a class without a constructor
constructs through its base's signature. Generic bases, inherited statics
and accessors, mismatched member kinds and unproven overrides take the
general path. The closure checker still sends derived classes to the
general path until their lowering lands (C2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
extendRecordLayout keeps a base layout unchanged (fields, presence and
state bytes) and places further fields, with their own tags, after it:
the layout a derived class instance needs so base-class code reads it at
the base's offsets (C2 step 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A derived class's instance layout keeps its base's layout unchanged
(names, shadow slots, presence bytes and the hidden prototype pointer)
and appends its own fields. Its prototype record holds its own methods,
absent shadow slots for inherited method names and a hidden link to the
base prototype, registered as a prototype contract, so inherited reads
fall through recursively. A base type's shape choices list every class of
its family, and the class definition stores the base prototype in the
link. Redeclared base fields keep their type. Derived classes still take
the general path until construction and super expressions land (C2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The nested conditional stored straight into the optional classification
byte array lowered to IR that stores a Uint8Array value into a
reference slot once the marker predicate is inlined; the x86-64 emitter
verifies the runtime's IR and rejected it (Linux x86-64 stage 1). The
classification is computed into a local first. The lowering defect
itself is recorded as a follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The IR names typed-array layouts through @tint/abi/typed-array, which,
like the C model, has no dependencies; the boundary tests now allow it
and list the new ABI entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TypedArray.prototype.fill compiled to a loop of checked element writes
(about 1.3 ns per word on a Uint32Array bitmap). It now lowers to one
array-fill instruction over the clamped [from, to) range: the value is
converted once to the element encoding (the conversion is pure),
replicated to a 64-bit pattern, and stored by a fill helper, 64 bytes per
iteration with 32/16/8/4/2/1-byte tails on AArch64 and 8 bytes per step
with 4/2/1-byte tails on x86-64. Each chunk starts at a multiple of the
element size, so the pattern stays in phase for every width.

The kinds fixture covers fills of every kind over relative, clamped,
NaN, infinite and fractional bounds, empty ranges, all tail sizes, the
conversions, -0 and the returned receiver; typedArrayFill joins the typed
benchmark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
boundCountedLoops kept a loop's counter a double unless the loop indexed
with it, so outer driver loops (`for (round = 0; round < scale; round++)`)
left `round` a double and every inner use converted it (scvtf, fadd,
fjcvtzs). Any counter now qualifies; the size limit still bounds the cold
copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
provenRecordFacts opened every record field (externalFields) as soon as
any function had a receiver, so one class method disabled layout proofs
across the whole module. Non-entry receivers are already merged as
unknown values and come from module code; only an entry function's
receiver, like its parameters, can bring a record whose fields were
written outside the module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
record-has always tested the object for null and compared its descriptor
before reading the presence byte, even where whole-module record flow
proves the object is always that layout and never null. A proven object
now reads only its presence byte (or is present, for fields without one).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The descriptor dataflow that proves record terminators across joins now
also reports each record-has whose object it proves to be the record's
layout (facts come from constructors, successful checks and verified
reads, so the object is never null); AArch64 then reads only the presence
byte. In basicClasses this removes 4 of the 16 record-has guards, the
repeated ones after an iteration's first check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The construction entry held its receiver in a local general slot, which
the inliner refuses (only parameters may be general), so no `new C(...)`
was ever inlined. The receiver is now wrapped where each field
initializer or body call passes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inliner refused record-cell terminators, function-environment reads
and error construction, so class methods that read their class binding
(and its TDZ ReferenceError path) never inlined: Vector.add in
basicClasses stayed a call. A record cell's environment object is an
explicit operand (unlike a frame cell), and a function value's
environment, string literals and new errors are position-independent,
so they now clone with the callee.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed typed-array elements load with LDRSB/LDRSH/LDRSW (added to the
ISA, encodings checked against clang) instead of a load and SBFM; an
int64 product by 2^k or 2^k + 1 (k <= 4) is one shifted ADD instead of
MADD; `x | 0` and `x ^ 0` fold their zero and move the word; and a
clamped store keeps its byte in a register instead of staging it in the
frame (it is computed inline, without a helper).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fused map/filter loops read their callback's captured values through
`function-environment (load closureSlot)`, so the closures (and a never
called filter closure) were allocated every round. When every write of a
slot stores `function-new f env`, environment reads now load `env` from
a mirroring slot; a closure slot left unread loses its loads and stores,
and an unused function-new is removable. In the closures kernel both
per-round closure allocations go; the captured environment record stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Catalog the new optimization module and use a Uint32Array (slot + 1) for
the mirror table; compiler sources have no Int32Array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocks were emitted in IR order, and inlining and record lowering append
continuations at the end, so a proven record access or a jump often
ended in a taken branch (three per iteration in escape's loop). Blocks
now follow a chained layout: a jump's target or a record access's
consequent comes right after it when it has no other predecessor. The
block-entry register forwarding and the seeded-entry check use the same
order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qard and others added 4 commits November 24, 2026 09:22
LICM keeps a checked read in its loop when an unchecked access's object
comes from the same slot, but a direct read can rest on the check through
slot copies: once resultCell inlined into resultNumber (after record-cell
inlining), hoisting `fn.cell`'s check out of the loop left the inlined
`fn.results` read, reached through a copy of `fn`, without a proof. The
verifier rejected the typed module and the trusted FFI module fell back to
general code (macOS gate: native-ffi dynamic calls).

A round that leaves any verified read unproven is now redone without
moving checked reads (its remarks wait for the kept round). The proof
comparison counted-loops already made is shared as recordReadsKept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A LICM round redone without moving checked reads (because a moved check
left a direct read unproven) is a fallback, so it must be visible: pass
statistics gain an optional `fallbacks` count (in the JSON and as a
"fallbacks N" marker in the table), LICM reports each redone round, and a
remark names the function and round.

Before the root fix that follows: 0 on frozen v7 and the typed suites,
7 in the FFI dynamic fixture's program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LICM keeps a checked read in its loop when an unchecked access may rest
on it, judged by the access object's slot. The verifier's proof also
traces that slot back through stores of copied slots (through reference
unwraps and wraps), so the dependence set now closes over copies: a slot
counts when any slot an unchecked access reads (transitively) copies it.
The redo backstop becomes a fallback that should not fire.

Fallbacks (redone LICM rounds) before -> after: FFI dynamic fixture
7 -> 0; frozen v7 0 -> 0; typed and basicClasses suites 0 -> 0 (images
unchanged). The flow-insensitive closure keeps 11 more checks in loops on
frozen v7 (LICM hoists 2553 -> 2542); none of them had broken a proof.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AArch64 image startup created the callback pthread key only when the
program had callback thunks. Every may-callback C call publishes the
thread's callback state under that key (callbackState reads it through
callbackKey()), with or without a callback in the program, so a program
whose only may-callback calls take no callback ran with an uncreated key:
pthread_setspecific failed and the call threw "callback state
registration failed". The key is now created when the program has thunks
or any module imports tint:callback-key, as x86-64 startup already does.

On main the zlib codecs only worked because unused allocator closures in
the program kept a callback thunk alive; removing dead closures (PR #17)
exposed the bug as a RangeError from deflateSync.

tools/native-ffi.test.ts: a may-callback call (abs as MayCallback<i32>)
in a program without callbacks; it exits 70 without this change and 42
with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant