Skip to content

AOT: objects and arrays in loops, vectors, subclasses, patterns in place, code from strings - #1040

Merged
Jarred-Sumner merged 11 commits into
mainfrom
claude/aot-objects-and-arrays-in-loops
Nov 12, 2026
Merged

Jarred-Sumner merged 11 commits into
mainfrom
claude/aot-objects-and-arrays-in-loops

Conversation

@Jarred-Sumner

@Jarred-Sumner Jarred-Sumner commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

The JavaScriptCore side of a round of work on Bun's ahead-of-time compiler (bun build --compile --aot and bun test --aot, both experimental). Bun's side is oven-sh/bun#48677, which pins this one's preview. This follows #1036.

Merge order

This merges first; then Bun's pull request pins the merged commit and runs CI once more.

What's in it

847 files, +74,933 −6,494 against main.

Area Files + −
aot/walk: the main pass 129 26,856 2,361
aot/facts: the link 26 8,447 721
aot/codegen, stubs, machine: code generation 220 17,855 1,513
aot/runtime, builtins, object 143 7,165 985
aot/tests 181 7,585 253
The rest of aot/ 101 3,589 348
Outside aot/ 47 3,436 313

Outside aot/

Only compiled programs take these paths; plain Bun runs a few checks more and gives the same answers. The row marked Plain Bun too changes an answer.

File + − Change
llint/LowLevelInterpreterAOT.asm, llint/LLIntSlowPaths.cpp and 9 more 2643 225 The interpreter of code from strings in executables
interpreter/Interpreter.cpp, interpreter/Interpreter.h and 1 more 23 0 Errors that code from strings throws and catches
runtime/ArrayPrototype.cpp 3 2 concat() into the result of a species constructor. Plain Bun too
runtime/JSArray.cpp 2 0 Notifies compiled code when the length of an array on a prototype chain becomes read-only
runtime/RegExpCachedResult.cpp, runtime/RegExpCachedResult.h and 3 more 56 13 The last match, where its input is a position in a string
runtime/StringPrototype.cpp, runtime/StringSplitCache.h and 1 more 9 10 Which literals of a compiled program are in the split cache
runtime/ObjectConstructor.cpp 22 4 Freezing, symbols and keys of compiled objects
runtime/JSArrayBufferView.cpp, runtime/JSArrayBufferView.h and 1 more 22 7 Cached addresses of typed arrays whose storage moves
runtime/JSMicrotask.cpp, runtime/JSPromise.cpp and 3 more 44 5 Chains of then() calls
runtime/JSONObject.cpp 30 13 JSON of compiled objects with index keys
runtime/DatePrototype.cpp, runtime/DatePrototype.h and 1 more 16 0 Entries for date arithmetic; the hash of a substring
yarr/YarrFlatProgram.h, yarr/YarrFlatProgramBuilder.cpp and 5 more 537 33 Compiled patterns: searches for two prefixes, captures
assembler/MacroAssemblerARM64.h, assembler/X86Assembler.h 23 0 Instructions and operands that stubs use
runtime/RegExp.cpp 6 1 Counts patterns created at run time that are searched by the character before them

If you don't use --aot

concat() keeps the elements of a species constructor's result where the argument has holes.

Changes

Builds that stop on main

Program On main
A loop over a typed array under y - (y & ~7), where y is 2 ** 32 or more Stops
A built-in constructor passed as a callback (list.map(Date)) Stops with --aot-harden=proof-checks
a[0] - 1 + a[2] * x in both arms of a branch, then a[2] = 7 As above
if (a[i] < 0) a[i] = x; else a[i] = x in a loop that then adds the next element and multiplies the stored one As above
The remainder of a product of BigInts, (a * b) % c, in two arms of a loop Can stop
arm64: more than 128 MB of compiled regular expressions Stops

Wrong on main: two accessors that a program defines on a prototype one after the other, behind the first instance: [t.s, t.g] between the two gives one answer twice.

Objects and classes

  • An object or array that each iteration of a loop allocates and that doesn't escape is carried through the loop as its fields, private fields included, and allocated only on the exits that need it.
  • int32 fields take four bytes. Short arrays, empty literals and some records take smaller cells.
  • A class that a function creates (a mixin, Class.create(), also in TypeScript) has code and a structure for each call in module code.
  • Subclasses of Array, typed arrays, Map and Set are allocated from templates. Loops over the first two inline their elements, getters and callbacks.
  • Static fields are read as variables, also through subclasses. Accessors from Object.defineProperty(), defaults on prototypes and assigned prototypes keep their slots.
  • A Proxy trap written next to the Proxy is called directly; without a trap, the target's slot is read. Reflect.set() runs in a stub.

Loops and numbers

  • Loops over typed arrays and arrays of numbers use 128-bit vectors: sums, fills, conversions, square roots.
  • An element stored by one iteration reaches the next in a register. Arrays that only some iterations read are checked before the loop too.
  • push(), pop(), shift() and splice() of arrays in fields, in variables and behind methods are inlined. An array filled by a loop reserves its capacity.
  • A loop over arrays of unknown kinds gets a version for the kinds it meets, also for tables of int32s and arrays of arrays.
  • Module variables that hold typed arrays cache the address and length (code compiled from C or C++).
  • Remainders, products modulo n, shifts and carries stay integers. if (a % b) compares the remainder without allocating the number.
  • A name that no object of a loop has is answered inline after the first miss. Where shared memory may grow, the length of a typed array in a field is read before the loop.

Strings and regular expressions

  • A string that a loop consumes piece by piece is carried as a position in its base string.
  • A loop over split() or matchAll() takes one piece at a time, without an array or result objects.
  • A sticky pattern, or one held by a constant, a field or a private field, is matched in place, and only the groups that are read are created.
  • A regular expression created at run time is attempted only where the character before it and its leading lookaheads let a match begin.

Calls

  • Callbacks of array methods run in one loop also where the method is in a function that the loop calls. sort() computes keys once where the comparator only reads them.
  • A chain of then() calls keeps one object until something needs a promise of it.
  • Generators are stepped inside more consumers: delegated calls, and methods chosen by a key.
  • Recursive functions check arrays and numbers once, at their entry.

Code from strings

  • Strings that a program evaluates at run time (eval(), new Function(), node:vm) are interpreted in an executable. The interpreter now caches properties, globals and the names of a context, and calls getters and common built-ins directly.

Build and checks

  • The new forms cost build time. Fewer queries per call, literal, edge and register, and tables that are filled when they are first needed, pay for part of it.
  • More generated programs for fuzzing, and injected faults that the checks of a build must refuse.

Known issues

What differs from bun run and bun test is listed in Bun's pull request.

Tests

IR tests and native tests are in aot/tests; stored programs are in Bun's pull request. CI's run of this pull request is the first of this tree.

…ace, code from strings

On 7101dff. 830 files, +73,852 -6,221: the rest of aot/ 608 files, +62,980 -5,686; aot/tests 177
files, +7,694 -238; outside aot/ 45 files, +3,178 -297.

Objects and classes

- An object or array that each iteration of a loop allocates and that doesn't escape is carried
  through the loop as its fields, private fields included. int32 fields take four bytes, and short
  arrays, empty literals and some records take smaller cells.

- A class that a function creates has code and a structure for each call in module code. Subclasses
  of Array, typed arrays, Map and Set are allocated from templates. Static fields are read as
  variables; accessors from Object.defineProperty(), defaults on prototypes and assigned prototypes
  keep their slots.

- A Proxy trap written next to the Proxy is called directly, and Reflect.set() runs in a stub.

Loops and numbers

- Loops over typed arrays and arrays of numbers use 128-bit vectors. An element stored by one
  iteration reaches the next in a register. Arrays that only some iterations read are checked before
  the loop too.

- push(), pop(), shift() and splice() of arrays in fields, in variables and behind methods are
  inlined. Module variables that hold typed arrays cache the address and length.

- Remainders, products modulo n, shifts and carries stay integers.

Strings and regular expressions

- A string that a loop consumes is carried as a position in its base string. A loop over split() or
  matchAll() takes one piece at a time. A sticky pattern, or one held by a constant, a field or a
  private field, is matched in place.

Calls

- Callbacks of array methods run in one loop also where the method is in a function that the loop
  calls. A chain of then() calls keeps one object. Generators are stepped inside more consumers.
  Recursive functions check arrays and numbers once.

Code from strings

- The interpreter of strings that a program evaluates at run time (eval(), new Function(), node:vm)
  caches properties, globals and the names of a context, and calls getters and common built-ins
  directly.

Builds that stop on main

- A loop over a typed array under y - (y & ~7) with y of 2 ** 32 or more. arm64: more than 128 MB of
  compiled regular expressions. With `--aot-harden=proof-checks`: a built-in constructor passed as a
  callback; `a[0] - 1 + a[2] * x` in both arms of a branch, then `a[2] = 7`; a loop whose two arms
  store one parameter into an element. The remainder of a product of BigInts in two arms of a loop.

Plain Bun too

- concat() keeps the elements of a species constructor's result where the argument has holes.

`Wire::schemaHash` changes, so this engine and Bun's side go together.
…engths in loops

On 69e40c6. 31 files, +654 -88: the rest of aot/ 26 files, +396 -71; outside aot/ 4 files, +257
-16; aot/tests 1 file, +1 -1.

- AOTObjectKeys.cpp includes the header that defines propertyNameEnumerator(). It compiled only next
  to a file that includes it.

- A read of a name that no object of the loop has is answered inline after the first miss. A
  subclass that counts in a static field of its base class keeps the fast version of the loop.

- Where shared memory may grow, the length of a typed array in a field is read before the loop.

- `if (a % b)` compares the remainder without allocating the number. A counter whose value may
  exceed int32 steps as an integer.

- A generator that iterates over another generator steps it on the main path. A generator's step
  that finishes resumes through one shared stub.

- A regular expression created at run time is attempted only where the character before it and its
  leading lookaheads let a match begin.

- Nested loops that add elements of any type are visited as often as before this pull request.

- With `--aot-harden=proof-checks`, an element read under a string that spells an integer does not
  stop the build.
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Preview build of 6f7dec7: autobuild-preview-pr-1040-6f7dec74

… many edges

On 5a7ad89. 374 files, +5,889 -5,856: aot/tests 110 files, +3,548 -3,533; the rest of aot/ 240
files, +2,102 -2,085; outside aot/ 24 files, +239 -238.

- Names and comments that this pull request adds are put into plain English, and its tests of the
  intermediate representation get shorter file names. 319 files, 2,331 lines; nothing else in them
  changes.

- LLIntSlowPaths.cpp, AOTReactionChain.cpp and AOTPropertyCachesLeafOperations.cpp read a structure
  through WTF::opaque(), as the places beside them do.

- Six files include what they use: they compiled only next to files that include it.

- The link counts the names that a loop copies into a record once, after they are read, and the walk
  collects the edges of a body once for all of its loops. A loop with many `continue` took time
  quadratic in their number.

- `if (!map.has(key)) map.set(key, value)` followed by `map.get(key)` looks an existing key up once,
  as on main.

- A value that comes around a loop through a catch block keeps its type.

- Tests: expectations follow the code this pull request emits. On Linux arm64, where blocks are
  64 KB, the test of a string that grows in place makes enough additions.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beyond the inline findings, I also checked whether the splice fast path's removed-elements array (tryCreateArrayWithStorage with WrittenByCaller, Source/JavaScriptCore/aot/runtime/AOTArrayOperations.cpp:744-766) can be observed by a concurrent marker with uninitialised slots — the cell is published before the caller fills it, but nothing in the heap references it yet and there is no safepoint between allocation and the copy, matching the contract of JSC's tryCreateUninitializedRestricted, so it is not affected. The other candidate concerns (Array.from detach handling, flatMap callable check, shift start-move preconditions, sort key-array reuse, Buffer.byteLength divergence) were examined and ruled out as well. This is a very large change (834 files, ~74k lines) touching a new AOT compiler, runtime, and machine encoders, so a human review of the overall design is still worthwhile.

Extended reasoning...

The diff adds or rewrites 834 files (about 74k insertions) across the JavaScriptCore AOT compiler: builtin emitters, IR schema, machine encoders for ARM64 and x86_64, object model, and runtime operations including array, RegExp, and property-cache paths. It touches no auth or injection surface, but it is memory-safety-sensitive engine code (butterfly manipulation, GC fences, hand-written allocation). Three confirmed findings (a null dereference on the in-line lastIndex store, a quadratic shift fallback, and a signed-shift overflow in the RegExp bit-parallel emitter) are posted inline; the size and the nature of the code rule out approval.

Findings marked 🟡 are optional suggestions and need no follow-up push.

On f21acba. 9 files, +71 -4: aot/tests 5 files, +60 -0; the rest of aot/ 4 files, +11 -4.

- A store of `lastIndex` asks for an object before it reads the receiver's structure.

- shift() of a long array that has named properties moves its start, as on main. A queue took time
  quadratic in its length.

- AOTRegExpBitParallel.cpp shifts an unsigned one.

- `this.size` of a subclass of Map, read in a loop that sets and deletes, is checked by structure.

- Tests: four sources name 128-bit vectors in their switches.
…over 2 GiB

On 1cb4f72. 9 files, +56 -20: the rest of aot/ 8 files, +55 -20; aot/tests 1 file, +1 -0.

- A loop that copies elements under a counter that passes the greatest int32 keeps its counter:
  `for (; i < n; i++) target[at++] = source[i]` continued at another index. Such loops are copied in
  one operation only where the counter stays an int32.

- An element behind the mirrored length of a typed array over 2 GiB is read and stored by the array's
  own length.

- Object.defineProperties() converts a key that is no string where compiled code can't define it.

- Accessors that a program defines on a prototype one after the other, behind the first instance, are
  each read by their own definition. On main `[t.s, t.g]` between the two gives one answer twice.

- A module's variable that a loop carries and that was initialized before the loop is read as
  initialized where it comes around. Two programs walked a function again and printed a line.

- AOTCompactTable.cpp: a substring keeps the hash of its characters for fewer hashes; the others are
  computed at each lookup.

- Tests: one source names 128-bit vectors in its switch.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-reviewed after 33c603c and found no new bugs; the two issues I raised on the previous push are fixed there (the mirrored-view path now re-checks the index against the view's own 64-bit length before treating it as out of bounds, and the Object.defineProperties fallback converts the key with toPropertyKey and uses putDirectMayBeIndex). Given this is still an ~840-file, ~74k-line change to the AOT compiler and Yarr, a human look from a JSC reviewer is worthwhile as an additional step.

What was reviewed:

  • The fix commits 1cb4f72 and 33c603c against each earlier inline finding (lastIndex store now requires a present cell, long-array shift with named properties, unsigned mask shift, 2 GiB view length, non-string defineProperties keys).
  • Candidates examined and ruled out: the Array.from typed-array fast path when the map callback detaches the buffer (handwritten/ArrayConstructor.ts), re-entrant key sorts of small arrays in operationAOTSortKeyArray, and compiled then/catch handler captures under a nested microtask drain (AOTStubsReactionChains.cpp).
  • Not done: no build or test run; the AOT test sources added under aot/tests were read, not executed.
Extended reasoning...

The diff spans 840 files and about 74,600 insertions, almost entirely under Source/JavaScriptCore/aot (builtins, codegen, facts, image, machine, object, plan, runtime, stubs, walk) plus edits to Source/JavaScriptCore/yarr (YarrJIT, YarrSharedRoutines). It is JIT and runtime code that emits machine code and touches typed-array bounds, property definition, and RegExp matching, so memory-safety is the sensitive surface, not auth or injection. The latest commit 33c603c is small (9 files) and I verified it implements the two fixes requested in the prior review correctly, including loading JSArrayBufferView length at Int64 width consistent with the existing typedArrayElements helpers. Approval is withheld because of the size and complexity, because Source/JavaScriptCore is covered by a CODEOWNERS entry, and because the earlier inline threads were resolved by this bot's own session rather than by an independent reviewer.

…ions

On 33c603c. 17 files, +296 -141: the rest of aot/ 13 files, +220 -89; aot/tests 4 files, +76 -52.

- A program with more than half a megabyte of type records stopped the build, as on main; their
  numbers count units of 16 bytes or more then.

- Stores under constants in a loop, and their reads, cost time quadratic in their number. An element
  that nothing reads behind a store is not noted anew.

- Names that few objects of a class get late have no room in the others. Only a loop that stores them
  into every element of a list gives them room.

- A constructor that can return another object than its own is not laid as a prototype.

- The consistency of unshared records is checked once in builds without assertions too.

- An operation that must not allocate could: it lists a structure's properties without building the
  property table. subarray() checks for an exception behind the question for the species. A slot that
  was not there is inserted as it is.

- Two assertions know vectors of 16 bytes. One folding test names its operands in order.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
…t follow [skip size check]

99 files, +1,469 -1,082: test 65 files, +1,092 -716; src 31 files, +349 -358; scripts 3 files, +28
-8. Pins the preview build of oven-sh/WebKit#1040 at 1a7e70d8.

- Wrong on main: a function that calls itself last behind `!`, `satisfies` or a JSDoc cast, beside
  such a call without one, lost what the first stored. The loop has the variables of the calls that
  jump, and only these jump.

- Wrong on main: inside `with (..)`, a test of a name (`typeof x`, `!x`, `if (x)`) was decided by the
  variable outside. What the build folds asks whether an object may hold the name.

- The functions of a literal are read once for all their `this`, so a build's work grows with them.

- `Object.assign()` of literals is compiled as on main: the first commit's stores by name go.

- A constant of a bundle that `__export()` names stays in a scope, so the build no longer stops. The
  text of a function has no parenthesis of an operand that is left out; a statement without a
  semicolon had one on main too.

- Classes that extend each other in a ring no longer hang the build. The class of a worker and a
  method are found through chains of any length.

- A damaged list of package names in an executable ends the program with the message of a damaged
  one. A folder that macOS clones is noted file by file.

- Where the front end looks for `undefined` beside a namespace, it asks the binder. The other new
  places that compare names as text are listed in test/aot/compiler/names-compared-as-text.ts, with
  their reasons.

- Lints: bundles of stored programs name their modules by paths. Four lines of the front end share a
  method or have other names. scripts/verify-baseline-static lists five more functions of the
  engine, which ask the processor first.

- Tests: twenty files of expected compiler output, and others, follow what the first commit changed
  (constants, enums as data, narrowed values, names of the global object that nothing stores). In
  test/aot/perf, rows whose twins got faster go or have another bound, and two of them are gaps. The
  stored program what-a-suspended-function-holds.mjs goes: what it printed depended on the time of a
  collection.

- New stored programs: what is above, and what the engine's fifth and sixth commits fix.
…ed again

On 1a7e70d. 46 files, +1,446 -561: the rest of aot/ 45 files, +1,444 -560; aot/tests 1 file, +2 -1.

- Some forms of programs cost the build more than linear time: lists made at the head of a loop,
  classes asked for in one loop, branches and loops in a row, parameters compared with characters,
  classes that each extend the last or store to `this`, names that a pattern takes or that a
  constructor stores, objects handed to a function with a loop. What a body, a family, a set of
  shapes or a state holds is listed once, and a question that can find nothing is not asked.

- Elements that a loop carries from one turn to the next: where a `continue` goes round in front of
  the read, the value was wrong. Elements under constants are no longer carried.

- Names that objects get late have room in the cell only where every path of the program fills them:
  in each object that a constructor or its maker hands on, or in each element of a list.

- In a build without function source, what `String(f)` answers is not taken for the source.

- A method whose class may be evaluated again is not read off the table of closures: each evaluation
  makes another class object. Release builds answered right.

- NewArrayOfHoles, NewArrayWithHoles and TypedArrayOfPlainArray stand in no family of operations, so
  `--trim` leaves out as much as on main where a program uses one of their neighbors.

- Which copy of the stub that calls a value is used follows the order of the calls of a unit. It
  followed the place in the file, so the same code differed by where it stands.

- The build of a loop around one that is written out, with stores that are undone and a way out,
  stopped: the key of such a store comes from a name that all its paths know.

- A turn of a loop that appends to a list and leaves by its test undoes the stores in front of the
  append too.

- A realm that outlives the instance whose tables it reads. The table of only referrers is made
  under a lock of its own.
…m as on main

On 8782a6a. 12 files, +38 -971: the rest of aot/ 9 files, +38 -746; aot/tests 3 files, +0 -225.

- `f(this || x)` or `f(this ?? x)` in a constructor, in front of stores into `this`, shows the object
  with the names it has by then: what `f` read of it was the value stored later, or a crash.

- A cell has room for names that objects get late where a function fills its parameter with all of
  them, as on main. The rules of this pull request for elements and fields that a function reads go,
  with their three tests: objects that never get the names had room for them.

- What a large walk has answered is released before its machine code is made. The check of unshared
  records in builds with assertions is the process's alone again, as on main.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

On 949adee. 1 file, +4 -0: the rest of aot/ 1 file, +4 -0.

- Where a helper makes a prototype by `Link.prototype = base.prototype; heir.prototype = new Link()`,
  and the program writes that prototype's parent anywhere else too, the methods of `base` are kept.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
…ze check]

65 files, +2,109 -106: test 60 files, +2,093 -100; src 4 files, +15 -5; scripts 1 file, +1 -1. Pins
the preview build of oven-sh/WebKit#1040 at 8c0d09b7.

- The helpers that step the matches of `matchAll()` come where a text names it, and no longer count
  as called by its native code: a program that lets `String.prototype` go kept thousands of members
  for them.

- Tests of captured variables and of a full address range use values that are not constants, and
  objects that have no room for later names. Rows of test/aot/runtime-use-prototypes.test.ts ask for
  names read from the prototype of a record.

- The row of test/aot/build-scaling on as many names as classes is judged by its instructions, which
  still grow; its counts and its memory no longer do. A stored program on few objects with other
  names and a test of elements under constants go with the rules they were for.

- The row of test/aot/plain-bun.test.ts on `sort()` goes: it failed or not by the moment at which
  the JIT compiles.

- The programs of test/aot/from-source run in 48 test files instead of 32, each with fewer of them.

- New stored programs: elements that a loop carries past a `continue`, stores in front of an append,
  stores of a loop that is written out, narrow empty slots, and parents that a helper writes.
… units

On 8c0d09b. 18 files, +120 -128: the rest of aot/ 18 files, +120 -128.

- A word of a slot is decoded before it is tested, as on main.

- A loop that pushes onto another array in each turn (`rows[i % n].push(x)`,
  `node.children.push(x)`, `map.get(k).push(x)`) reserves no room for its remaining turns: 150
  elements took 16.8 KB and take 1.3 KB. An array that is read anew in each turn has room reserved
  while it holds what the turns have pushed.

- What the walk and the sweep of a large unit have learned, and the records of its abandoned blocks,
  are released before its machine code is made.
On 2f9f2cc. 2 files, +4 -1: the rest of aot/ 2 files, +4 -1.

- AOTCode.h includes wtf/PageBlock.h, whose pageSize() it calls: the files of testaot did not
  compile.

- Whether a field is inherited is read off the field, not asked of all classes above it: a build's
  work grows with classes that extend one another in a row.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

@Jarred-Sumner
Jarred-Sumner merged commit 6fc709c into main Nov 12, 2026
88 checks passed
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
…s [skip size check]

95 files, +511 -108: test 82 files, +391 -70; src 12 files, +119 -37; scripts 1 file, +1 -1. Pins
the preview build of oven-sh/WebKit#1040 at 6f7dec74.

- A read of an embedded file's open descriptor (`node:fs`, `Bun.file()`) no longer falls into the
  moment at which another thread's first write of that file moves the descriptor to the disk: it
  could mix old and new bytes. What a thread of the pool has written is seen by the next call of
  `node:fs`.

- In plain Bun too these reads ask one word of memory whether the descriptor is recorded; outside an
  executable it is zero, and they read as before.

- Two stored programs ask for the room of arrays that a loop pushes onto by turns. A test of the
  engine goes with what it was for.

- A stored program on a data file that is required ahead of its import holds its output: what `bun
  run` prints there hangs on its threads.

- `require("url")` is an object where a build follows strings that a package evaluates. One question
  for a regular file serves the compiler and the bundler.

- The programs of a-few-of-every-sweep run in eight test files instead of four, those of
  test/aot/from-source in 64 instead of 48, and a program on readable streams makes its calls in two
  turns instead of three: builds with AddressSanitizer took too long.

- A file that holds a webpack or browserify bundle beside a function of its own with a direct
  `eval()` no longer stops the build: a request in the bundle is the request of the module that the
  build has noted around it.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
…ed loosely [skip size check]

11 files, +200 -19: test 6 files, +140 -14; src 4 files, +59 -4; scripts 1 file, +1 -1. Pins
oven-sh/WebKit#1040 as merged, 6fc709c298409fe433a60f6aff328a45a8974532.

- test/cli/hot/hot.test.ts writes texts of one length, so a load never reads the rest of a longer
  one; test/cli/run/no-orphans.test.ts waits for what a parent does a moment later. Both failed at
  times.

- A build followed `==` and `!=` of a variable of the environment as it follows `===`: a file that a
  package chooses by such a test of a number, a boolean or null could be missing, and the read
  failed with ENOENT. Values of unlike kinds go both ways now; `null` and `undefined` are equal.

- A loop of test/aot/embedded-assets.test.ts ends with an error behind 30 seconds.

- The build of a JavaScript file of 4 MiB or more, in which a variable holds objects of more than
  1,001 unrelated classes, did not end. Where a part of a file meets that limit, the file waits for
  the last round and is compiled whole.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
…ies, mocks in import cycles (#48677)

Bun's side of a round of work on the ahead-of-time compiler (`bun build --compile --aot` and `bun
test --aot`, both experimental). The JavaScriptCore side is merged: oven-sh/WebKit#1040. This
follows #48617.

2,084 files, +88,328 -2,222: test 1,890 files, +71,847 -1,437; src 189 files, +16,434 -768; scripts
3 files, +28 -8; docs 2 files, +19 -9.

[skip size check], as in 607519a.

Tests

- CI compiles a stored program with `--aot`, runs it and compares it with `bun run`; a stored test
  run likewise, with `bun test --aot` and `bun test`.

If you don't use `--aot`

- `concat()` keeps the elements of a species constructor's result where the argument has holes.

- Reads of `node:fs` and `Bun.file()` ask one word of memory, which is zero outside an executable,
  and read as before.

Wrong on main, fixed

- A function that calls itself last behind `!`, `satisfies` or a JSDoc cast, beside such a call
  without one, lost what the first stored.

- Inside `with (..)`, a test of a name (`typeof x`, `!x`, `if (x)`) was decided by the variable
  outside.

Executables and builds

- A mixin or a class factory (`Class.create()`, also in TypeScript) is copied for each call in
  module code, so each class has its own code. Constructors that are kept in variables, fields or
  namespaces are classes too. TypeScript enums are data.

- The modules inside the output of webpack and Browserify are compiled as files, with their
  requests. Names that go through the helpers of Babel, esbuild, Rollup and swc are read directly.

- What a package joins from its own files and hands to `new Function()` or `eval()` is compiled, and
  so are strings that such code evaluates in turn. If the string is another one at run time, that
  one is interpreted.

- A WebAssembly file that glue code names beside itself is compiled.

- Stores into a path's variables are followed in order, so a build finds reads that it passed over.
  Some files that the program only writes are no longer warned about (TS100098).

- A server whose route is the `Bun.file()` of an embedded file threw at its start; it serves the
  file.

- A data file that is imported under two types and then required by a path made at run time has the
  form that `bun run` gives it in more programs.

- Names of packages and paths of data files are read when the program first needs them.

`bun test --aot`

- Partial mocks in import cycles: the files of the cycle run again with the mock, as in `bun test`.
  An `import()` behind an awaited import waits for its own source.

- After `vi.resetModules()`, a package that is kept keeps the exports of a built-in module that a
  later file mocks, and the factory of a hoisted mock over a package is called when something asks
  for it.

- Fewer notices where a run is as in `bun test`.

Known issues

- #48617 lists what main has. Of it, the two builds that stop (two arms that store one
  parameter into an element; the remainder of a product of BigInts) are fixed here, a direct `eval`
  in strict code of a string that strict code refuses throws, accessors that are defined one after
  the other each answer by their own definition, the notice about `import defer` of a mocked
  CommonJS file is printed again, and fewer files that the program only writes are warned about
  (TS100098). Not on main:

- Executables, silent: Where a method of a constructor function gives many names to a few of its
  objects, all of them take the larger size (at most 128 bytes an object).

- Executables away from their sources, silent: A route of `Bun.serve()` that is a `Bun.file()` of a
  file embedded by `--asset` or an import keeps the build's bytes when the program writes or removes
  that file later by a `__dirname` path, and answers a `Range` request with the whole file (status
  200).

- Executables, an error: Where the text that `eval()` is given depends on a variable that is changed
  only in the default of a parameter of a function with an empty body, the program ends with an
  error (exit 134).

- Executables, an error: A file of a package is not embedded where the package reads it by a
  parameter whose default is a function that writes files, such as `(write = Bun.write) =>
  write(path.join(__dirname, "one.txt"))`, and the caller passes one that reads: `ENOENT`.

- The build, an error: Some programs that read and write several elements of a typed array held by a
  file's variable stop the build with an error (one of 400 drawn programs).

- `--aot-harden=proof-checks`, an error: A product stored into an element and read back from it,
  where one of the lists has an accessor, a hole or a read-only element, can end the process. By
  default the answer is right.
robobun added a commit that referenced this pull request Nov 12, 2026
main has one more AOT landing (#1040). No conflicts. Its new code has no call of an import that is made again, no
job of the loader and no synchronous load: nothing more takes the async context.

6fc709c is the commit that Bun's main pins (oven-sh/bun#48677).
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