Skip to content

AOT: WebAssembly in the optimizing tier, arm64 branch islands, fixes and new names - #1025

Merged
Jarred-Sumner merged 10 commits into
mainfrom
claude/aot-wasm-optimizing-tier-and-fixes
Nov 10, 2026
Merged

Jarred-Sumner merged 10 commits into
mainfrom
claude/aot-wasm-optimizing-tier-and-fixes

Conversation

@Jarred-Sumner

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

Copy link
Copy Markdown
Collaborator

The JavaScriptCore side of the next 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#48436. This follows #1021.

Merge order

This merges first. Then Bun's pull request sets its pin to the merged commit and runs CI once more.

What's in it

1,149 files, +23,756 −22,908 against main, in ten commits.

Area Files + −
aot/tests 539 3,043 4,926
aot/walk: the compiler's main pass 148 8,993 8,642
aot/runtime: modules, mocks, error messages 76 4,926 3,463
aot/image: the image, WebAssembly in it 38 1,561 979
aot/machine: register allocation and encoding 38 625 1,138
The rest of aot/ 257 3,379 3,514
Outside aot/ 53 1229 246

Outside aot/

Nothing in heap/, WTF or bmalloc, and nothing outside Source/JavaScriptCore. 7 of the 53 files change only comments, and 16 only follow renamed AOT identifiers. The others:

File + − Change
assembler/ARM64Assembler.h 108 0 Branch islands on arm64. In code longer than half the reach of b, the assembler plans pools of islands, and a far branch goes from pool to pool
assembler/LinkBuffer.cpp, .h, AssemblerPolicy.h 76 2 Plans and links the islands; a branch that cannot be encoded is reported, so that the build can name the function. On arm64 the JIT pays one null test per link and two flag tests per link record
wasm/WasmOMGIRGenerator.cpp 244 39 The optimizing tier can compile into the image. A branch to a br_table whose local holds a known constant goes straight to the selected case, and a state machine's first state is tested before its table; plain Bun's optimizing JIT gets both
wasm/WasmStreamingParser.cpp, .h 79 10 The digest that finds a module's code in the image skips data and custom payloads, and is computed through three hooks. A section's payload is read where it lies
wasm/js/WebAssemblyModuleConstructor.cpp 47 23 new WebAssembly.Module(bytes) parses the bytes in place, without a copy, where no code of the program can run in between; plain Bun too
wasm/WasmCodeInImage.cpp, .h, WasmIPIntPlan.cpp, .h, WasmModule.cpp, .h 80 7 The image is asked before the parse, so no function body is stored when its code is in the image
wasm/js/JSWebAssemblyInstance.cpp 11 0 Two run-time counters: image code used, or interpreted
runtime/ReflectObject.cpp, .h, ObjectConstructor.cpp, JSObject.cpp 70 5 Object.getOwnPropertyDescriptor(), its Reflect form and Object.getOwnPropertyDescriptors() can report a locked property as read-only, and defining that descriptor again is accepted. In plain Bun the three functions inline getOwnPropertyDescriptor() and test one bit of the structure
runtime/JSArrayBuffer.cpp, .h, wasm/js/JSWebAssemblyMemory.cpp, .h 21 8 Each byte of a WebAssembly.Memory is reported to the collector as allocated once, not again for each new buffer. Plain Bun too
jit/AssemblyHelpers.cpp 3 4 On x64, the stack check of a WebAssembly function compares with memory. Plain Bun too
b3/B3LowerToAir.cpp 25 2 For WebAssembly in the image: an instruction that reads fewer bytes than a load which may trap is not selected
assembler/X86Assembler.h 8 8 Byte-sized subtract, and, or, xor to memory take the prefix that the low byte registers need. Plain Bun too. Hot JavaScript used the same encodings on x64: Atomics.sub, and, or and xor on an Int8Array or Uint8Array with an unused result stored a wrong byte.
assembler/MacroAssemblerARM64.h 2 2 Without LSE atomics, a compare-exchange keeps its expected value for a second try. Plain Bun too, on such processors
assembler/testmasm.cpp 319 0 Tests of both
runtime/StackFrame.cpp 1 1 Drops two arguments that were always null and false
runtime/FunctionExecutable.cpp 3 3 Renames a fuzzing environment variable to BUN_FUZZILLI_HIDE_FUNCTION_SOURCE

Most of the added lines in assembler/, wasm/ and these four files are not behind ENABLE(AOT).

Changes

Builds

  • On arm64, two kinds of very large functions aborted the build: one whose code outgrew the reach of a branch because of spill slots, and one whose code is larger than 128 MB.

Executables

  • Three fixes to require() in mixed ES and CommonJS graphs: module.parent and id after a file requires itself and throws, and a JSON file that a cycle both imports and requires.
  • A small program stopped at run time (exit 134) on a check of the compiler's own that was wrong.
  • Buffer.concat's descriptor says writable: false, so that minizlib 3.1.0, which tar 7 and npm 11 carry, does not try to replace it.
  • The build stopped on delete under an unknown key beside a Map that holds the same property.
  • A field of a linked object that was deleted or redefined in an outer loop was read with its earlier value in the inner loop.
  • A read of a field off an object that had lost another field by delete, behind a typeof test, gave undefined. Right on Bun's main before AOT: the next base bun#48120.

bun test --aot

  • About twenty fixes to module mocks: imports in flight, factories that wait or fail, failed loads, mocked CommonJS files in packages, and microtask timing.
  • A later mock over a file that threw in a preload failed with the first error.
  • A package that imports a mocked CommonJS file whose original a refused require() had loaded got the mock.
  • Module instances, which gave each load of a module its own exported variables, were in the first commits and are out again. After a second load, an object kept from the first one could read another load, and some answers depended on how a name was read. A module that is loaded again keeps one set of variables, as on main.

WebAssembly

  • Functions in the image are compiled by the optimizing tier, with the baseline tier as the fallback.
  • On x64, a load at the last bytes of a memory, masked to fewer bits, returned a value where it should trap.
  • On x64, byte-sized atomic subtract, and, or, xor whose result is unused stored a wrong byte, in executables and in the optimizing JIT. Four encodings lacked a prefix.
  • arm64 without LSE atomics: a compare-exchange that has to fail could store when its store-exclusive was lost.
  • Creating a module whose code is in the image costs less: esbuild.wasm takes about 3,000 page faults instead of 9,400, and peaks at 68 MB instead of 92 MB.
  • esbuild-wasm compiled ahead of time, long job: 39.9 G instructions before the jump threading, 28.2 G after.
  • WebAssembly written into the source as base64 or hex is compiled at build time whichever function decodes it.

Speed and size

  • A call is hoisted out of a loop only if it is guaranteed to execute. Otherwise the first iteration that reaches it makes the call, and the result is carried.
  • Object.assign(), Object.create() with written descriptors, new F(...array), stores to function objects, and Buffer.from("text") with constant strings take fewer instructions.
  • Dead registers and dead stack words are no longer cleared. Three mechanisms are deleted.
  • --trim keeps less: an access on a built-in object under a symbol key no longer counts as a use of every member.

Checks and messages

  • A run-time check that finds the compiler wrong prints a four-line report with file, line, function and what to do.
  • Three new or corrected rules in the verifier and the register allocation checker, and a new check on built-ins that declare a fresh result. They run in builds with assertions.
  • --explain loses 20 causes that were never produced.

Names

  • About 2,800 more AOT identifiers get idiomatic English names: 1,253 that the schema files declare, and about 1,540 elsewhere in aot/. Wire::schemaHash changes, so this engine and Bun's side go together. No logic changes with the names.

The commit message describes each change, with the programs and the numbers.

Review

Review found three faults in the first commits. eb1fb5de fixes them: on arm64, jump tables out of reach in very large WebAssembly functions; a build inside a compiled process that found no WebAssembly function bodies; a re-export read through a cache. The last one went out with module instances. c6e34c07 makes an arm64 branch out of reach a build error. Of 81b5811c, review found property caches that a program with several realms could keep too long; 61d90cd8 fixes that.

Known issues

oven-sh/bun#48436 has the table of what is worse than main.

Tests

Nothing was run on this tree before the push. It is a copy of the development tree as it stood, and this pull request's CI is its first full run.

…im keeps less, mocks, new names

1,124 files, +21,751 -22,362: Source/JavaScriptCore/aot 1,084 files +21,029 -22,150 .
Source/JavaScriptCore/runtime 18 files +96 -96 . Source/JavaScriptCore/wasm 11 files +413 -73 .
Source/JavaScriptCore/b3 4 files +16 -16 . Source/JavaScriptCore/interpreter 3 files +17 -17 .
Source/JavaScriptCore/assembler 3 files +172 -2 . Source/JavaScriptCore/llint 1 file +8 -8.

This brings aot/ up to a snapshot of the development tree. 40 files change outside aot/, none in
heap/, WTF or bmalloc. 8 change only comments and 16 only follow renamed AOT identifiers.
runtime/StackFrame.cpp drops two arguments of one call, and runtime/FunctionExecutable.cpp renames a
fuzzing environment variable to `BUN_FUZZILLI_HIDE_FUNCTION_SOURCE`. The other 14 hold real changes,
and most of those lines are not behind `ENABLE(AOT)`: three files in assembler/ (+172 -2) for the
branch islands on arm64, and eleven in wasm/ (+413 -73) for WebAssembly. Both are described below.

"The earlier main" below is Bun's main before oven-sh/bun#48120 and #1021 were merged.
Today's main has most of the faults that are fixed here.

Builds

- On arm64, a function with 20,000 reads, most of them behind `if (neverTaken) a = ...`, aborted the
  build in the encoder. x64 and the earlier main build it. A phi that was evicted after the head of
  its block got a spill slot of its own, and the code outgrew the reach of a branch. Now such a phi
  takes the slot of a source whose live range ended before the head
  (`Allocator::findSpillOfDeadSource()`). The function at 8,000 reads: 17,282,140 B before,
  5,087,296 B now (aot/machine).

- On arm64, one function that carries 46,000 numbers around a loop aborted the build with `Stopped
  while compiling big in encode`. x64 and the earlier main build it. Its code is larger than 128 MB,
  which is out of the reach of `b`. Now, in code longer than half the reach, the assembler plans
  pools of branch islands, and a far branch goes from pool to pool. The JIT pays one null test per
  link (assembler/ARM64Assembler.h, AssemblerPolicy.h, LinkBuffer.cpp, outside aot/;
  aot/image/AOTRelocation.cpp).

Executables

- `piece.cjs` requires itself while it evaluates, its first evaluation throws, and
  `import("./piece.cjs")` evaluates it again. Under `bun run` the second module object has `id` "."
  and `parent` null. Compiled, it had the file's path and `undefined`. Same on the earlier main. Now
  the return of a `require()` whose target is still evaluating decides nothing (aot/runtime).

- `piece.mjs` requires itself through `createRequire()` and then throws, and it was imported, not
  required. The next CommonJS file that the loader brings was taken for the main module: `id` "."
  and `parent` null, where `bun run` prints the file's path and `undefined`. Right on the earlier
  main. A `require()` made through `createRequire()` never decided that there is no main module. Now
  it does (aot/runtime).

- A CommonJS file and an ES module import each other, and the module also imports a JSON file. The
  CommonJS file's `require()` of the JSON file returned the ES namespace (`{ __esModule, default
  }`); `bun run` returns the value. Same on the earlier main. Now `require()` asks whether the
  loader's registry entry for the file is still being fetched in a synchronous load, which is what
  plain Bun asks. The import gets an object of its own, as under `bun run` (aot/runtime).

- A small program built, and its executable stopped at run time (exit 134) with a report that a
  field does not hold the type that the compiler has proven of it. Right on the earlier main. The
  check was wrong, not the code. A versioned loop that leaves an iteration in the middle puts back
  what its stores overwrote, and that store was held to the types of other receivers. It is no
  longer checked; the loop is still versioned (aot/walk/AOTWalk.cpp).

- No behavior changes: `transferSynchronousLoad()` follows the chain of open queues instead of the
  queue that an `EagerLoad` names (aot/runtime).

`bun test --aot`

- An ES module that a module mock names, or that imports one, keeps its exported variables in a
  module instance: an environment that compiled code allocates for each run of the body. A body that
  runs again, as under `--rerun-each`, gets a new instance, so closures of the earlier run keep
  their variables. Executables have no instances. A test file's read of such an import goes through
  the property caches, which cache a variable that lies in a module instance like any other exported
  variable (aot/runtime/AOTPropertyCachesAnswers.cpp, aot/stubs/AOTStubsPropertyReadHandlers.cpp).
  The IR schema changes (about 30 files in aot/). The other half is in Bun's src/aot/lower and
  src/aot/modules.

- A test file leaves `import("./part.mjs")` pending and mocks the file one microtask later. The next
  test file's own mock was ignored, and its `import()` got the real file. Right on the earlier main.
  The runner now waits at the end of a test file for a fetch that a mock call found in flight, as
  `bun test` does (aot/runtime). The other half is in Bun's src/jsc/bindings/BunPlugin.cpp.

- Two files are mocked with factories that wait, `require()` of their importer gives up, one file is
  mocked again, and the other factory settles. The later factory was called; `bun test` does not
  call it. The earlier main fails loudly there. The walk that resumes such a load now skips a file
  whose recorded factory call is still pending (aot/runtime). The other half is in Bun's
  BunCompiledModules.cpp.

- A load waits on an early factory, a later mock is registered over the file, and the original of
  another mocked file imports it. The pending import got the early mock. Right on the earlier main.
  Now each deferred fetch waits for the disk reads that were started before it. Of 120 test runs
  written for this, 63 match `bun test` (56 before). Two that matched no longer do; they differ on
  the earlier main too (aot/runtime). The other half is in Bun's src/jsc/RuntimeTranspilerStore.rs.

- `app.mjs` imports `kiln.mjs`, which awaits and then throws, and `store.mjs`, which imports a file
  under a mock that takes its original. Under `bun test` the body of `store.mjs` runs before
  `import("./app.mjs")` rejects. Compiled, it never ran. Right on the earlier main. Now the importer
  goes on with its other requests, and fails where its own body would have run (aot/runtime).

- A module awaits at its top level and then throws, and a mock is registered over it while its body
  waits. A later `import()` returned the mock; `bun test` rejects with the body's error. Right on
  the earlier main. The error is now kept where the loader rejects the failed import, until a mock
  call, an unmock or the end of the test file clears it (aot/runtime).

- In the same setting, the mock is removed or replaced a few microtasks after the second `import()`.
  That import got the real module; `bun test` gives it the mock. The earlier main fails loudly
  there. An `import()` that has taken its first step now keeps the mock that was active, and is
  bound to it one microtask after the factory call, as under `bun test`. Of 85 variants by
  microtask, 84 match `bun test` (60 before).

- A module's body waits at a top-level await, `vi.doMock()` without a factory is registered over it,
  and it is imported again. Every value was right, but the second `import()` settled up to 8
  microtasks late, or ahead of the first. Now it settles in the same microtask as under `bun test`,
  after the first. The other half is in Bun's BunPlugin.cpp.

- A mock's factory failed, an importer of the mocked module failed to load, and an `import()` of the
  mocked module itself failed again. The next mock or unmock then let the importer load; `bun test`
  goes on answering with its first error. Compiled runs now keep the failure in that order of events
  too. The other half is in Bun's BunPlugin.cpp.

- A project's own ES module throws at its first load. The test fixes the cause, registers
  `vi.doMock()` over the module and loads it again. `bun test` runs the body a second time. A
  compiled run rejected with the first error, threw `Code generation from strings disallowed`, or
  loaded the original from source. Now the body runs again, with a new module instance. The other
  half is in Bun's BunPlugin.cpp.

- A test mocks `tint.mjs` with a factory that is never called, calls
  `vi.importActual("./tint.mjs")`, removes the mock and imports the file. The two results were
  different namespace objects for one evaluation. Right on the earlier main. Removing such a mock
  now puts the original's namespace object back (aot/runtime).

- A mock factory awaits `import("./user.mjs")`, which imports the mocked file, and then throws. `bun
  test` evaluates `user.mjs` again at the next import. A compiled run does not, and said nothing.
  Same on the earlier main. The end of the run now names `user.mjs` among the files that did not run
  again (aot/runtime). The call is in Bun's BunPlugin.cpp.

- The opposite fault: a package's CommonJS file requires a mocked ES module of the same package,
  which bypasses the mock. Every file ran once, as under `bun test`, but the run ended with `2
  compiled files didn't run again`. That notice is gone.

- A test file imports a JSON file that the run may take out of `require.cache`, beside a CommonJS
  file that requires it. `require()` returned the value; `bun test` returns the namespace. Same on
  the earlier main. The file now counts as imported while its importer is being loaded
  (aot/runtime).

- Five fixes for a mocked CommonJS file in a package. A package's own imports bypass `vi.doMock()`,
  so `bun test` reads the real `other=5` behind `export * from "./more.cjs"`. (1) `more.cjs` and its
  re-exporter are mocked: `other=undefined`. (2) `more.cjs` alone is mocked and requires back into a
  cycle of `export *`: `other=undefined`; the earlier main prints 50 under the mock and 5 after it.
  (3) All three files of the cycle are mocked and the CommonJS star is listed first: `other=50`, the
  mock's. (4) A name that `more.cjs` sets after its `require()` into the cycle was listed; `bun
  test` does not list it. The earlier main fails loudly in (1), (3) and (4). (5) The factory was
  called as soon as an importer that bypasses the mock was loaded; `bun test` calls it only when
  somebody outside node_modules asks. Now `more.cjs` is evaluated past its pending mock, and its
  exports are captured at the cyclic `require()` (aot/runtime).

WebAssembly

- WebAssembly functions in the image are compiled by the optimizing tier (OMG), with the baseline
  tier (BBQ) as the fallback. Functions of a module with GC types, with vectors or with exception
  handlers fall back by design. A module with a memory has two flavors of each function. The one for
  a fast memory is optimized; the one that checks bounds is compiled by the baseline tier, because a
  program runs only one of them. A module without a memory keeps one optimized copy. Statistics and
  counters for tiers and flavors are pinned exactly in every stored WebAssembly program
  (wasm/WasmOMGIRGenerator.cpp, outside aot/; aot/image/AOTWasmModules.cpp, AOTImageBuilder.cpp).

- To find a module's code in the image, the run time hashed every byte of the module. Now it skips
  the payloads of data and custom sections, which the code does not depend on. Of the seven modules
  that one program compiles, 5.0 MB in all, 0.7 MB is still hashed. Two run-time counters,
  `WasmInstancesUsingImageCode` and `WasmInstancesInterpreted`, say whether an instance fell back to
  the interpreter (wasm/WasmStreamingParser.cpp, WasmCodeInImage.cpp, outside aot/).

- In Bun that digest is computed by BoringSSL's SHA-1 instead of `WTF::SHA1`, through three hooks.
  It is the same 20 bytes. Medians of 20 runs on two builds that differ only in the hooks: `new
  WebAssembly.Module(esbuild.wasm)` in an `--aot` executable 62.0 | 31.5 ms; `bun run` of the same
  script 149.6 | 148.9 ms. The other half is in Bun's src/jsc/bindings/BunAOTRuntime.cpp.

- `new WebAssembly.Module(bytes)` does less when the code is in the image. The image is asked before
  the parse, so no function body is stored. A section's payload is read where it lies. And the bytes
  are parsed in place, without a copy, where no code of the program can run between the
  constructor's entry and the parse. The last two hold for plain Bun too. esbuild.wasm, first
  creation in a fresh process: 9,425 to 9,451 page faults before, 2,980 to 3,006 now; peak 92 to 93
  MB before, 68 MB now (five files in wasm/, outside aot/).

- A state machine written as a loop around a `br_table`, as Go's compiler writes every function,
  went back through the table at every jump. Where the branching block has stored a constant in the
  table's local, the branch now goes to the case that the table would select. esbuild-wasm compiled
  ahead of time, long job: 39.9 G instructions before, 28.2 G now. Plain Bun's optimizing JIT gets
  the same change (wasm/WasmOMGIRGenerator.cpp, outside aot/).

- The map file (`BUN_JSC_aotMapFilePath`) has rows for WebAssembly modules and functions
  (aot/image/AOTImageSymbols.cpp).

- WebAssembly written into the source as base64 was compiled at build time if the program decoded it
  with `atob()`, `Uint8Array.fromBase64()` or a `data:` URL. With `Buffer.from(text, "base64")` it
  was interpreted: 6,300 ms against 170 ms in one program. The build did not scan a literal that is
  passed to a native function. Now it scans every string whose text is in the image, of any length,
  and also decodes base64url, hex and base64 with line breaks (aot/image/AOTImageBuilder.cpp,
  AOTWasmModules.cpp).

Speed and size of generated code

- `for (..) { if (list[i] === stop) break; if (list[i] === q.toUpperCase()) n++; }`, where the first
  iteration leaves. `bun run` and the earlier main never call `toUpperCase()`; compiled code called
  it once in the preheader. With a `q` of 2 ** 30 letters: 59,960 M instructions before, 99 M now,
  99 M on the earlier main. Hoisted `Map` and `Set` lookups had the same fault. Now a call is
  hoisted only if it is guaranteed to execute: it dominates every exit, and nothing before it in the
  loop may throw or leave for the generic version. Any other such call is made by the first
  iteration that gets to it, and its result is carried around the loop in one more header parameter.
  Instructions per call of 64 iterations, with a `break` that is never taken before the call: 4,414
  before, 4,613 now, 7,994 on the earlier main (aot/walk/AOTWalkLoopInvariants.cpp).

- `Object.assign()` onto an ordinary object went through the engine's `objectAssignFast()`, which
  looks up one structure transition per property. With three or more arguments, or a function object
  as the target, the call left compiled code. Now it uses an assignment plan, as object spread does:
  the final structure is cached per target structure and source shape. Instructions per call, before
  | now (plain Bun with JIT): `Object.assign(Object.create(proto), instance)` 1,852 | 980 (1,662);
  `Object.assign(function, two fields)` 3,356 | 715 (2,063) (aot/object/AOTObjectAssign.cpp,
  AOTAssignmentPlans.cpp).

- A store to a function object whose prototype is a compiled object is made directly
  (`Closure::canPutDirectly()`). `Closure::isBuiltinFunction()` reads a flag before it scans the
  table of run-time functions, and the build stops with `FunctionOutsideRuntimeModule` if a listed
  function lacks the flag. With the item above, a benchmark that makes Effect schemas goes from
  212,893 to 113,937 instructions per group (aot/object/AOTClosure.cpp,
  aot/image/AOTProgramTableCheck.cpp).

- `Buffer.from("text"[, "encoding"])`, `Uint8Array.fromBase64("text")` and
  `Uint8Array.fromHex("text")` with constant strings are encoded during the build. The bytes go into
  the image's read-only constants, the string is not created, and one operation allocates and copies
  at run time. A call that throws, or whose callee is not proven, is left as written. Instructions
  per call, `--aot` | `bun run`: utf8 302 | 517, hex 303 | 1,564, base64 302 | 1,819
  (aot/builtins/AOTByteLiterals.cpp). The other half is in Bun's src/jsc/bindings/BunAOTCompile.cpp.

- `new F(...array)` and `super(...array)` built a second array and passed that; `f(...array)`
  already passes the array itself. Now all three do. In Rollup 4.68.2 bundling 100,078 lines, the
  copies were 5.3% of all bytes allocated.

- `Object.create(prototype, { key: { value: .. } })` allocated the map and each descriptor and then
  made a host call. With both levels written out, it becomes `Object.create(prototype)` and one
  definition per key. A small program of that form took 5,134 instructions per iteration compiled,
  against 3,706 in plain Bun.

- Dead registers and dead stack words are no longer cleared. Three mechanisms are deleted, and
  nothing replaces them: the operation `ReleaseHint` with everything
  that only fed it; the clearing of a closure or object in its maker's frame after the call that
  borrowed it; and the clearing of words of a saved frame that are dead at a suspension. Words that
  the collector decodes are still cleared. The TypeScript compiler benchmark on x64, before | after
  the first deletion: code 15,481,608 | 15,465,964 B, build 28.900 | 28.742 G instructions. Thirteen
  stored programs now print KEPT where `bun run` prints collected. They test only when an object is
  collected, and are deleted, with two more of that kind. With the hints gone, `x = step(x);` 32,000
  times in one function cost 60% more build in two linear searches. Both are lookups by key now; 1%
  is left on x64 and 6% on arm64. The other half is in Bun's src/aot/ir/ssa.rs.

`--trim`

- `console.log(globalThis[Symbol.for("x")])` built with `--trim` was 73.8 MB, against 25.9 MB for
  hello world: 231 of 267 features were kept. The package signal-exit begins so, and `bun compile
  --trim` removed nothing from Rollup's CLI. Every computed access on a built-in object counted as a
  use of any member. Now a key that is proven to be one symbol names one member. A built-in object
  that a closure captures is followed, like one that is stored in a literal (210 features kept
  before, 5 now). A read, a store, an `in` test or a method call on a built-in that arrives that way
  no longer lets the whole object go, where the table of built-ins can say what is used (aot/facts).

Build warnings and `--explain`

- `Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose")` in a dependency printed `TS100014: this
  assignment throws if it runs`. Bun has that member, so `??=` never assigns. The warning is left
  out where a `??=`, `||=` or `&&=` on a constant member never stores. `Number.EPSILON &&= 1` still
  warns and still throws (aot/facts/AOTFactsOfProgram.cpp).

- `--explain` printed `unknown-object: An object from untyped code is used as this type here` and
  `why (loose-type)` for every property access that is not one load, also where both are wrong. 20
  of the 24 causes were never produced, and the reason was a fixed function of the cause.
  `UnprovenCause` keeps 4 members and `IllTypedCause` 5. Three fields of the records that told the
  reader nothing go too. The wire schema changes. The other half is in Bun's src/aot/report.

Checks inside the compiler

- In builds with assertions, and under `testing=CheckResultFreshnessAtRunTime` in any build, a call
  to a native built-in whose signature declares a fresh result is followed by a check. The program
  stops with a message that names the built-in if the result is the receiver, is the first argument,
  was returned by an earlier such call since the last collection, or survived a collection that
  ended before the call. Release builds do not change (aot/builtins/AOTBuiltinCallEmitter.cpp,
  aot/runtime/AOTExceptionOperations.cpp).

- The register allocation checker marks a register whose 32-bit sum was sign-extended on the failing
  edge of a branch on overflow. A `ZExt32` whose upper half is read, and that emits no code in a
  marked register, stops the build with `UpperHalfNotClear`. The stored test runs on x86_64 only
  (aot/machine/AOTMachineAllocationChecker.cpp).

- A follow-up to the build stop on a `switch` in a loop. If a caller took the state out of a pending
  block's record and did not return it, the next arrival was stored as if it were the first. Now
  such a record knows nothing. No generated code changes: two large programs compile to the same
  image byte for byte (aot/walk).

- A run-time check that finds the compiler wrong printed one line that began with `AOT:` and a
  function's number. Every such report now has four lines, starting with `bun: internal AOT error:
  <check> failed`. It names the file, line, column and function as a stack trace does, the types
  expected and found, the workaround (`--no-aot`) and where to report it. No report prints a
  run-time value. No check, exit code or signal changes (aot/runtime/AOTRuntimeCheckFailure.cpp; 79
  files in aot/).

- Two rules of the verifier were too strict. They run only under `--aot-check=Validate` or
  `VerifyEachStage`, in `testaot` and in builds with assertions. `input.charCodeAt(offset) !==
  (current & flags.JUMP_TABLE)` stopped such a build with `TypeOutOfDate`; the operand check now
  looks through `NumberOrNaN`. A loop that fills one array up to the saved length of another was
  rejected; bounds evidence that was read from another array is no longer judged by writes to this
  one (aot/walk/AOTCodeVerifier.cpp, AOTWalk.cpp).

- A new rule in the same builds: a pointer read by `GetArrayStorage` is rejected if an operation
  that may move the array's storage lies between the read and the access
  (aot/walk/AOTCodeVerifier.cpp).

Dead code removed

- `TraceFrame::hasCalleeInFrame` was never set. It goes, with the parameters `callee` and
  `hasCalleeInFrame` of `stackTraceName()` and `calculatedDisplayName()` (aot/runtime; one line in
  runtime/StackFrame.cpp, outside aot/).

- Two statistics that nothing counts, one internal error that nothing reports, one flag that nothing
  sets (`mayPrecedeItsStore`), one enumerator that nothing produces
  (`ArrayLiteralStorage::ProfiledForRoom`) and three forwarding wrappers in aot/walk. The images of
  two large programs differ in the 8 stamp bytes only.

- 50 internal errors and 3 user diagnostics that only the schema spelled, options that nothing set
  or read, forwarders and copies in aot/walk, and members of two enums of `--explain=allocations`
  that the engine never produces.

- The testing switch `SkipExpectedTypeRollback` had no test and was no failing control of any check.

Renames. None of them changes logic.

- 1,253 names that the schema files declare, in three batches: build statistics, run-time counters,
  testing switches, fault injections, operations, internal errors, module flags, and the 38
  removable features. `TestingLie` is now `FaultInjection`; `Function::text` is `sourceRange`. Tests
  spell these names, so most of the changed files are tests. 22 internal-error messages move to the
  new words. `Wire::schemaHash` changes, so the engine and Bun go together.

- 1,379 names elsewhere in aot/: 357 in the module run time (aot/runtime), 648 in two batches for
  aot/walk alone, 374 in the other folders. Each noun that they coin has one defining comment where
  it is declared.

- 76 names: "face" becomes "facade", the synthetic ES module that wraps a CommonJS module so that
  `import` can load it.

- 63 names and 24 comments in shared engine files, 20 of them outside aot/: export resolution after
  a mock was removed, elided constructor frames in stack traces.

- About 20 names in aot/runtime and aot/tests, and three failure messages of the code verifier
  (aot/walk/AOTCodeVerifier.cpp).

- Three C++ files are renamed: aot/support/AOTHostFunctionSources.h,
  aot/image/AOTFunctionSources.cpp and aot/runtime/AOTQuotedStringCache.h. The comments of 53 files
  under aot/tests are rewritten in plain English; no line of a test changes.

Docs

- aot/README.md is cut to the pipeline, the folders, how to build and test, and the rules.
  aot/tests/README.md is cut to how to run and write a test, and says less about the run-time
  checks.

Files outside aot/, under Source/JavaScriptCore: assembler/ARM64Assembler.h,
assembler/AssemblerPolicy.h, assembler/LinkBuffer.cpp, b3/B3CompilationReport.h,
b3/air/AirCheckSpillSlots.cpp, b3/air/AirCheckSpillSlots.h, b3/air/AirReleaseDeadValues.cpp,
interpreter/Interpreter.cpp, interpreter/StackVisitor.cpp, interpreter/StackVisitor.h,
llint/LLIntSlowPaths.cpp, runtime/AbstractModuleRecord.cpp, runtime/AbstractModuleRecord.h,
runtime/CallData.cpp, runtime/CyclicModuleRecord.cpp, runtime/ErrorInstance.cpp,
runtime/Exception.cpp, runtime/FunctionExecutable.cpp, runtime/FunctionRareData.h,
runtime/InternalFunction.cpp, runtime/JSGlobalObject.h, runtime/JSMicrotask.cpp,
runtime/JSONObject.cpp, runtime/JSStringInlines.h, runtime/ObjectConstructor.cpp,
runtime/ObjectConstructorInlines.h, runtime/ProxyObject.cpp, runtime/RegExp.cpp,
runtime/StackFrame.cpp, wasm/WasmCodeInImage.cpp, wasm/WasmCodeInImage.h, wasm/WasmIPIntPlan.cpp,
wasm/WasmIPIntPlan.h, wasm/WasmModule.cpp, wasm/WasmModule.h, wasm/WasmOMGIRGenerator.cpp,
wasm/WasmStreamingParser.cpp, wasm/WasmStreamingParser.h, wasm/js/JSWebAssemblyInstance.cpp,
wasm/js/WebAssemblyModuleConstructor.cpp.

Nothing was run on this tree. It is a copy of the development tree as it stood, plus two later fixes
and two `#include` lines.

Built here with Bun's side of the same copy: release, Linux x64, no LTO, not hardened, 0 errors. The
tree that was built lacked one of the two later fixes (8 lines in aot/facts/AOTLinkCalls.cpp) and
the two `#include` lines (aot/runtime/AOTStaleAnswers.cpp, AOTRuntimeCheckFailure.cpp). Not built
here: arm64, musl, Windows, macOS, ASAN, the hardened build, LTO.

@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 the related module-namespace read paths in the TryGetSuperById / Proxy stubs (Source/JavaScriptCore/aot/stubs/AOTStubsPropertyMethodCalls.cpp) for the same stale-instance problem — the Variable-slot path reloads the module instance from the namespace cell at read time, so it is not affected. Also checked the Object.assign direct-write path in AOTObjectAssign.cpp (guarded by the ordinary-object check) and the unused reason argument of WASM_DECLINE_FOR_IMAGE_IF in WasmOMGIRGenerator.cpp (cosmetic only, all declines record the same failure code).

Extended reasoning...

The change spans about 1100 files (roughly 21k insertions / 21.6k deletions), almost entirely under Source/JavaScriptCore/aot plus smaller edits to the wasm plans, OMG generator, and FunctionExecutable; it touches no auth, crypto, or injection surface. Six confirmed findings are posted inline (ARM64 wasm jump-table range, wasm module skipped in nested builds, stale namespace field reads, a renamed fuzzing env var, lifetime of frame-allocated object cells, and a null bufferStructureProvider call), so human review is already signalled; this note only records the adjacent paths that were examined and found unaffected.

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

static const bool hidesText = getenv("BUN_FUZZILLI_HIDES_FUNCTION_TEXT");
if (hidesText && !isBuiltinFunction()) {
// Prints what a program that was built without function source prints.
static const bool shouldHideSource = getenv("BUN_FUZZILLI_HIDE_FUNCTION_SOURCE");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) Conditional, fuzzing-only: any Fuzzilli harness that still exports the old variable BUN_FUZZILLI_HIDES_FUNCTION_TEXT silently loses the function-source hiding after this merge. The getenv name was renamed to BUN_FUZZILLI_HIDE_FUNCTION_SOURCE at FunctionExecutable.cpp:209 and the old name has no remaining reader in this checkout, while the setter lives outside it (the embedder's fuzz scripts). Fix: keep accepting the old name alongside the new one (getenv both), or confirm every harness that sets it was updated in the same change; nothing in this repository depends on the old spelling.

Why this was flagged

The trigger is a FUZZILLI build whose harness sets the environment variable BUN_FUZZILLI_HIDES_FUNCTION_TEXT, which was the only spelling the base branch read at FunctionExecutable.cpp:209 (base line 210: getenv("BUN_FUZZILLI_HIDES_FUNCTION_TEXT")). After the change the code reads getenv("BUN_FUZZILLI_HIDE_FUNCTION_SOURCE") instead, so shouldHideSource stays false and Function.prototype.toString returns the real source text instead of the elided form. A repo-wide grep for the old name returns no hits, so the setter cannot be enumerated from this checkout; it is in the embedder's fuzzing scripts. The consequence over the base is that differential fuzzing compares programs built without source against ones printing full source, producing false mismatches; it affects nobody outside fuzzing, so this is low severity and conditional on the harness not being updated.

Verification: Triggers in an ENABLE(FUZZILLI) build whose harness exports BUN_FUZZILLI_HIDES_FUNCTION_TEXT. The reader is now getenv("BUN_FUZZILLI_HIDE_FUNCTION_SOURCE") (Source/JavaScriptCore/runtime/FunctionExecutable.cpp:209); no other reader exists, so the old name has no fallback. With the old name set, shouldHideSource is false and toStringSlow returns the real source text instead of the elided form.

@@ -153,15 +152,6 @@ void AllocationEmitter::generateNewObject(const ValueContext& value)
return;
}
CellPointer cell = allocateWithFields(value, allocation, value->fields(), value->valuesOperands(), value->storage());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) Compiled functions that pass a frame-allocated object to a direct call keep every cell that object referenced alive until the caller's frame is popped, where the base cleared them after the call. generateNewObject at AOTAllocationEmitter.cpp:154 no longer records noteWordsThatCellLentHolds for objects borrowed by a call, so no WordsClearedBehindCalls zeroing is emitted. The stale words sit on the machine stack and ConservativeRoots marks them on every collection. Fix: after a CallDirect that borrows a frame object, zero the object's cell-holding slots (or the whole frame cell) once the callee returns, for every frame-storage allocation site, not just NewObject. [also at: Source/JavaScriptCore/aot/codegen/AOTHintEmitter.cpp:160 - Frame-allocated closures and objects keep dead capture pointers in their stack words after their lifetime ends, so the collector retains those captured objects until the slot is reused, which the base branch avoided by zeroing. emitLifetimeEnd at AOTHintEmitter.cpp:160 no longer calls clearWhatCellLentHolds, and handler heads no longer zero either.]

Why this was flagged

Trigger: any compiled caller whose body stays on the stack for a long time (a request handler loop, a long synchronous batch) and that creates a frame-allocated options or argument object holding cells (collectSlotsThatMayHoldCells in the removed code at AOTAllocationEmitter.cpp:156-163) and lends it to a direct call. On the base, callThatBorrowsObject recorded the call and noteWordsThatCellLentHolds produced zeroing of those slots behind the call, so the cells became collectable as soon as the callee returned. After this diff the slots keep their stale cell pointers until the stack slot is reused, and ConservativeRoots::add (ConservativeRoots.cpp:271/292) marks any word that passes isLiveCell, so a dead cell reachable from a lent frame object stays reachable, with everything it references. Remedy: keep the zero-after-call for frame cells lent to direct calls, or mark their slots dead so the frame map excludes them and the allocator reuses them.

Verification: Trigger: any compiled function that allocates an object in its frame and lends it to a CallDirect, then keeps running before returning. The diff removes from generateNewObject (AOTAllocationEmitter.cpp, deleted lines 156-163) the noteWordsThatCellLentHolds sequence. No replacement exists. Cells referenced by the lent object stay conservatively reachable after the call until the frame returns.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Preview build of 584729d: autobuild-preview-pr-1025-584729de

…pies, mock fixes, names

94 files, +926 -503: Source/JavaScriptCore/aot 88 files +789 -472 . Source/JavaScriptCore/runtime 4
files +69 -4 . Source/JavaScriptCore/wasm 2 files +68 -27.

On 8826534. Six files change outside aot/, all with real changes, none in heap/, WTF or bmalloc:
wasm/WasmOMGIRGenerator.cpp (+67 -27), wasm/WasmStreamingParser.cpp (one comment),
runtime/JSObject.cpp (+14), ObjectConstructor.cpp (+11 -4), ReflectObject.cpp (+18) and
ReflectObject.h (+26).

Builds without `ENABLE(AOT)`

- 8826534 did not compile with `ENABLE(AOT)` off. `emitCallToThrowStub()` in
  wasm/WasmOMGIRGenerator.cpp used `AOT::SymbolSpace` outside the guard. It is guarded now. In the
  same file, `WASM_DECLINE_FOR_IMAGE_IF()` loses a parameter that it never used. A comment in
  wasm/WasmStreamingParser.cpp says that `useEagerWasmModuleHashing()` no longer names a module by
  the hash of its whole file. No generated code changes (both files are outside aot/).

Builds

- `bun build --compile --aot` stopped with `internal compiler error ... an operand is not of the
  kind that its operation takes` on valid TypeScript: one function runs `delete (pair as any)[key]`,
  and another reads a `Map` that holds `pair.x`. A deletion under an unknown key sent the mark for
  an empty slot to every place that stores under unknown names reach, and not to the fields alone.
  Reads took it from there as if it were a value. Seven edges in Link now pass values only. Two
  large programs compile to the same image byte for byte; Link costs one of them 0.15% more
  instructions (aot/facts/AOTLinkFlow.cpp, AOTLinkFlow.h).

Executables

- `Object.getOwnPropertyDescriptor(Buffer, "concat")`, its `Reflect` form and
  `Object.getOwnPropertyDescriptors(Buffer)` say `writable: false` in a compiled executable.
  minizlib 3.1.0, which tar 7 and npm 11 carry, replaces `Buffer.concat` only if the descriptor says
  that it may. The descriptor said writable, the assignment threw, and a compiled npm 11 failed on
  every tarball. `Buffer.concat` stays locked, and every other descriptor is as it was. The mark
  `IsReportedAsReadOnly` in the table of built-ins is on this one entry. Different from plain Bun on
  purpose: a property defined from that descriptor is read-only. minizlib 2.1.2 assigns without
  asking and still throws (aot/builtins/AOTBuiltinTable.h, aot/runtime/AOTBuiltinCells.cpp; outside
  aot/: runtime/JSObject.cpp, ObjectConstructor.cpp, ReflectObject.cpp, ReflectObject.h, where
  reflection asks only for a structure that has locked properties). In plain Bun the three functions
  now inline `getOwnPropertyDescriptor()` and test one bit of the structure. The other half is in
  Bun's src/codegen/builtins/host/buffer.builtins.ts.

- Eleven errors that a compiled program throws at its user were hard to read, for example `it hands
  out only the exports that the build saw somebody read from it`. Each now says what happened, why,
  and what to do: `the build kept only the exports that it saw your code read`. Classes, codes and
  conditions are unchanged (aot/runtime/AOTErrorMessages.cpp).

`bun test --aot`

- A `require()` of a mocked module was refused because the async factory of another mock, below the
  module's original, had not settled. After that the outer mock was lost without a word. `import()`
  and `require()` answered with the original, the outer factory was never called, the wrong value
  was still there in the next test file, and test runs that fail under `bun test` passed with exit
  code 0. The error also named `dep.js` where `bun test` names `dep.js?actual`. Compiled runs now
  keep the mock pending, name the original's key, and load the compiled original in the background.
  `original()` and `importActual()` get that original or its failure. Still different: in seven of
  204 generated sequences an `import()` that waits for an outer factory which then fails answers
  `undefined`; the run exits 1 with the right error (aot/runtime/AOTModuleEvaluation.cpp,
  AOTTestRunFactories.cpp, AOTTestRunOriginals.cpp, AOTModuleHost.h). The other half is in Bun's
  src/jsc/bindings/BunPlugin.cpp.

- One more place for the mocked CommonJS file in a package. `more.cjs` alone is mocked with
  `vi.doMock()` and requires back into a cycle of `export *`. Such a graph is loaded by the engine's
  own loader. There the factory was still called, `second.mjs` ran before `more.cjs`, and values
  were lost after the mock's removal. `bun test` runs `more.cjs` first and never calls the factory.
  Same on the earlier main. The loader's path now evaluates the file past its pending mock too
  (aot/runtime/AOTModuleEvaluation.cpp, AOTTestRunOriginals.cpp).

WebAssembly

- A state machine whose transitions all name their next state as a constant runs its `br_table`
  once, on the way in. Where no branch goes to the loop's header, the header now tests for the first
  state before the table. esbuild-wasm compiled ahead of time, long job: about 0.8 G fewer
  instructions (3%). This reaches plain Bun's optimizing JIT too (wasm/WasmOMGIRGenerator.cpp,
  outside aot/; the statistic `WasmFirstStateTests` in aot/image/AOTWasmModules.cpp).

- WebAssembly compiled into the image switches on three existing B3 and Air policies:
  `narrowsIntegers`, `extendsInstructionSelection` and `mergesIdenticalBlocks`. esbuild-wasm, long
  job: about 2.1 G fewer instructions (8%); optimized code 16,562,450 B before, 14,935,586 B now.
  Plain Bun's JIT is not touched (aot/image/AOTWasmModules.cpp, three lines).

Speed and size of generated code

- `Object.create(prototype, { [key]: { value: .. } })` with one property is expanded also where the
  key is known only at run time, such as a symbol in a captured variable. A small program of that
  form: 2,773 | 751 instructions and 269 | 126 bytes per iteration; plain Bun takes 1,498 and 218
  (aot/walk/AOTWalkWrittenDescriptors.cpp, AOTWalk.cpp).

- `constructor() { super(...arguments) }` with a speculated parent still copied its arguments into a
  second array. Now the call takes the source array. In Rollup 4.68.2 the copies were 3.6% of
  allocation samples. Two more copies of that kind go: in a chain of such constructors the direct
  call passes the caller's array on, and `new C(a, b)` with a callee that is not known at build time
  reads the parent's parameters out of the frame (aot/walk/AOTWalkCalls.cpp, AOTWalk.cpp,
  aot/facts/AOTFacts.cpp, aot/plan/AOTPlan.cpp).

Checks inside the compiler

- In a build with assertions, the report of a failed run-time check had no place for six operations
  that are declared not to collect. They now pass `AOT_OPERATION_FRAME_RECORD()`. A release build is
  unchanged (aot/runtime/AOTExceptionOperations.cpp).

- The statistic `DependencyFilesNotVerified` is new, for `bun check --aot` in Bun
  (aot/ir/schema/statistics.def).

Renames. None of them changes logic.

- 66 names, most of them older than this pull request: 41 in aot/runtime, 19 in aot/walk, facts,
  machine and object, and 6 of the reports of failed checks. Two identical helpers in
  aot/walk/AOTWalkNarrowingOfGuesses.cpp become one. None of the files is outside aot/.

Files outside aot/, under Source/JavaScriptCore: runtime/JSObject.cpp,
runtime/ObjectConstructor.cpp, runtime/ReflectObject.cpp, runtime/ReflectObject.h,
wasm/WasmOMGIRGenerator.cpp, wasm/WasmStreamingParser.cpp.

Nothing was run on this tree. It is a copy of the development tree as it stood, less two changes.

The copy that this tree is made from was built whole with its Bun: release, Linux x64, no LTO, 0
errors. With `ENABLE(AOT)` off, a syntax pass over all 168 unified engine sources outside aot/ on
the development tree with the guard gave 0 errors; with the guard taken out it gives exactly the two
errors of the failed build. This tree itself was not built before the push, nor arm64, musl,
Windows, macOS, ASAN or LTO.
ReflectObject.h has an inline function that reads the VM of a JSGlobalObject, and only
the forward declaration was in sight. The build on Windows failed, where ReflectObject.cpp
is the first file of its unified source. One line.

@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 new issues

No new issues were found in this update; 6 findings from earlier reviews are still open above.

Still open from earlier reviews (6):

If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.

…rted once, module mock fixes

38 files, +439 -179: Source/JavaScriptCore/aot 30 files +394 -149 . Source/JavaScriptCore/wasm 5
files +36 -20 . Source/JavaScriptCore/runtime 2 files +6 -6 . Source/JavaScriptCore/jit 1 file +3
-4.

On ed06b79. Eight files change outside aot/, all with real changes but one, none in heap/, WTF or
bmalloc: jit/AssemblyHelpers.cpp (+3 -4), runtime/JSArrayBuffer.cpp (+4 -4) and JSArrayBuffer.h (+2
-2), wasm/js/JSWebAssemblyMemory.cpp (+12 -2) and JSWebAssemblyMemory.h (+3), wasm/WasmIPIntPlan.cpp
(+6 -5) and WasmIPIntPlan.h (+4 -2), and wasm/WasmOMGIRGenerator.cpp (+11 -11, renames). The stack
check and the memory change reach plain Bun.

WebAssembly

- On arm64, the build aborted (exit 134) on a WebAssembly module with a function whose optimized
  code runs more than 1 MB past a `br_table`, or past the use of a floating-point constant. The jump
  tables and constants follow the function's code, and were addressed with `adr`, which reaches 1
  MB. Now they are addressed with `adr` and `add`, which reaches 16 MB. A function with a table more
  than 16 MB from its use is compiled by the baseline tier, as for any other refusal. No x64 code
  changes; arm64 pays one more instruction where such an address is taken
  (aot/image/AOTWasmModules.cpp).

- A process that runs compiled code, and whose own image holds a WebAssembly module, calls
  `Bun.build({ compile: { aot: true } })` on a program that imports the same module. The build
  failed with `TS100058: the compiler can't compile function 0 of the WebAssembly module`, one line
  for each function. It happened in a test under `bun test --aot` and in an executable. The parser
  asks the process's image before it parses, and skips the function bodies when the image has their
  code. The builder went the same way and got no bodies. Now it makes its plan with
  `UsesCodeInImage::No`. Plain Bun's path is unchanged: a default argument, and one condition
  computed once (wasm/WasmIPIntPlan.cpp, WasmIPIntPlan.h, outside aot/;
  aot/image/AOTWasmModules.cpp).

- Each new `memory.buffer` was reported to the collector as a fresh allocation of the whole memory.
  A growth detaches the buffer, so a program that takes it again after each growth, as Go's
  wasm_exec.js does, requested a collection every time. Now `JSWebAssemblyMemory` records how many
  of its bytes have been reported, and a new buffer reports only the rest. So every byte is reported
  as allocated once over the life of the memory object, by a buffer or by a growth, whichever comes
  first. The first buffer reports the initial size, as before. No schedule, threshold or growth
  factor changes, and nothing in heap/ changes. This reaches plain Bun. 300 memories of 100 pages
  under `bun run`, each grown four times with a buffer taken and written after each growth, before |
  now: 322 | 102 collections with fast memories, peak 34 | 33 MB; 295 | 137 with bounds checks, peak
  85 | 78 MB. With a ring of 8 buffers and bounds checks: 78 | 18 collections, peak 257 | 289 MB.
  Without growth the numbers are about as before (runtime/JSArrayBuffer.cpp, JSArrayBuffer.h,
  wasm/js/JSWebAssemblyMemory.cpp, JSWebAssemblyMemory.h, outside aot/).

- On x64, the stack check at the start of a WebAssembly function compares with memory: `lea r11,
  [rbp - size]` and `cmp r11, [instance + limit]` in place of a load, an add and a compare. It is
  the same test, one instruction shorter. arm64 and RISC-V have no compare with memory and are left
  alone. Plain Bun's JIT emits it too. esbuild-wasm's long job: 26.04 to 26.11 | 25.99 to 26.00 G
  instructions; optimized code 16,545,458 | 16,529,074 B (jit/AssemblyHelpers.cpp, outside aot/).

Executables

- `tools.made = createRequire(__filename); tools.made("./a.cjs")`, where `a.cjs` defines `exports`
  of its `module` as a getter. Since the `module` object that the host's `require()` makes became
  the module's own, the getter ran twice. Under `bun run` it runs once. Right on main. The engine
  read `exports` at the end of the evaluation, and the host threw that value away.
  `AOT::requireModule()` now takes `ReadsExports`, and the host passes `No` where it reads `exports`
  itself (aot/runtime/AOTModuleHost.h, AOTModules.cpp, AOTModules.h, AOTModuleEvaluation.cpp). The
  other half is in Bun's src/jsc/bindings/BunCompiledModules.cpp.

- `operationAOTCopyByteLiteral()` asserts that a provider of `Buffer`'s structure is registered. Bun
  registers it before it publishes the image, and compiled code runs only from a published image
  (aot/runtime/AOTTypedArrayOperations.cpp).

`bun test --aot`

- A module that re-exports from another module stays linked to the load that it was linked to. When
  `bun test` loads the other module again (`--rerun-each`, or a failed module that a mock names), an
  uncached read of the re-exporting module's namespace read the new instance, while a cached read
  went on reading the old one. So the answer depended on the cache and on the collector. Plain `bun
  test` reads the old instance. `Modules::retainLinks()` now records, before an instance is
  released, the instance and the namespace object that each loaded re-exporting module stays linked
  to. Reads of re-exported fields and namespaces, and the property caches, ask that table first
  (aot/runtime/AOTModules.cpp, AOTModules.h, AOTPropertyCachesAnswers.cpp, AOTRuntimeRecords.h).

- `vi.doMock(reed, async factory)`, and `require(pond)`, which imports `reed` and lies on an import
  cycle with `heron`, gives up. Under `bun test` the load that was left goes on, and when the
  factory settles it evaluates `heron` and `pond`. In a compiled run the bodies never ran unless
  somebody loaded them again. A body whose timer throws fails the test under `bun test`; the
  compiled run passed with exit code 0. Where a second `require()` below the first one gave up too,
  the bodies ran in another order. Main and the earlier main are wrong there too. A load that was
  left now evaluates roots on a cycle, in the order that the loader would
  (aot/runtime/AOTModuleEvaluation.cpp, AOTModules.h).

- An importer that has loaded before is loaded again under a mock whose factory fails. Its next
  `import()` asked the factory again; `bun test` answers with the first error. The importer now
  keeps the error of its load, also where the mocked module is a CommonJS file that it reaches
  through its facade, and `require()` answers from it. Two of the differences that were listed for
  ES modules go with it (aot/runtime/AOTTestRunFactories.cpp, AOTModuleEvaluation.cpp).

Speed and size of generated code

- `Object.create(null, { key: { value } })` with one or two written descriptors allocated six inline
  slots (64 bytes). It now has two (32 bytes). An object that gets a third property later allocates
  out-of-line storage, as any object does at its seventh. In Rollup 4.68.2 such objects are 9.3% of
  allocation samples (aot/runtime/AOTInstance.h, aot/builtins/AOTObjectBuiltinEmitter.cpp,
  AOTObjectBuiltinOperations.cpp, aot/walk/AOTWalkWrittenDescriptors.cpp).

Renames. None of them changes logic.

- 28 names, some of them new on this pull request: 13 in the compiler, most of them about spread and rest
  arrays, 8 in the module run time, 4 in the checks for mocks that are bypassed, and 3 in
  wasm/WasmOMGIRGenerator.cpp, outside aot/ (for example `stateMachineDispatch()`).

Files outside aot/, under Source/JavaScriptCore: jit/AssemblyHelpers.cpp, runtime/JSArrayBuffer.cpp,
runtime/JSArrayBuffer.h, wasm/WasmIPIntPlan.cpp, wasm/WasmIPIntPlan.h, wasm/WasmOMGIRGenerator.cpp,
wasm/js/JSWebAssemblyMemory.cpp, wasm/js/JSWebAssemblyMemory.h.

Nothing was run on this tree. It is a copy of the development tree as it stood, less two changes
whose build cost grew quadratically.

This tree was not built before the push. Each change was built when it was applied to the
development tree. Not built here: a build with `ENABLE(AOT)` off, arm64, musl, Windows, macOS, ASAN,
LTO.

@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.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

…rted, a verifier rule, counters

27 files, +272 -83: Source/JavaScriptCore/aot 25 files +259 -83 . Source/JavaScriptCore/assembler 2
files +13 -0.

On eb1fb5d. Two files change outside aot/: assembler/LinkBuffer.cpp (+9) and LinkBuffer.h (+4).
None in heap/, WTF or bmalloc.

- Builds, arm64: a branch that no island can carry to its target is a build error that names the
  function, not an abort in the JIT's allocator. Plain Bun gets two tests of a flag per link record
  on arm64; no code that the JIT generates changes, and x64 compiles none of it
  (assembler/LinkBuffer.cpp, LinkBuffer.h, outside aot/; aot/image/AOTRelocation.cpp).
- Revert: bun test --aot: the fix of 8826534 that let a project's module run again after it threw
  at its first load. With it, a module that imports its own namespace ran again at the `vi.doMock()`
  call that names it; right on main. Such a second load again rejects with the first error, or runs
  from source and says so (aot/runtime; the other half is in Bun's src/jsc/bindings/BunPlugin.cpp).
- bun test --aot: a second `vi.doMock()` over a module whose importer was loaded by `require()`
  called its factory at the call, and a factory that throws ended the test. Now it waits for the
  next load, as under `bun test` (aot/runtime/AOTTestRunMocksLetGo.cpp).
- Speed: a class that extends another and writes no constructor no longer allocates a rest array in
  its generic entry (aot/facts/AOTFacts.cpp, aot/walk/AOTWalk.cpp, AOTWalkCalls.cpp).
- From review of this pull request: the base that the offset of a cached variable refers to is
  computed in one place, for reads by `super` too. A slot that names another module's instance is
  never packed, and a test pins that, so the case was not reachable
  (aot/stubs/AOTStubsPropertyProbes.cpp, AOTStubsPropertyProbes.h, AOTStubsPropertyReadHandlers.cpp,
  AOTStubsPropertyMethodCalls.cpp; aot/tests/AOTRuntimeRecordTests.cpp).
- Checks: the verifier's rule on the start of a counter follows only edges that are reached. It
  rejected sound loops under `--aot-check=Validate`. No generated code changes
  (aot/walk/AOTCodeVerifier.cpp, AOTSumOverRecords.cpp, AOTSumOverRecords.h,
  AOTWalkLoopsBuiltTwice.cpp; three tests in aot/tests/walk/positions-inside).
- Statistics: `ParameterGuardsSkipped`, `ParameterGuardsEntered` and `FreshResultsChecked` are new.
  No generated code changes (aot/walk/AOTWalkCalls.cpp, aot/builtins/AOTBuiltinCallEmitter.cpp,
  aot/ir/schema/statistics.def).

Files outside aot/, under Source/JavaScriptCore: assembler/LinkBuffer.cpp, assembler/LinkBuffer.h.

It is a copy of the development tree as it stood.

Not built and not tested here: CI's run of this pull request is its first.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
…ore edges, test names

On a360dc8. 5,201 files, +14,676 -11,501: docs 8 files +86 -67 . scripts 1 file +1 -1 . src 17
files +311 -86 . test 5,175 files +14,278 -11,347. Pins the preview build of oven-sh/WebKit#1025 at
eb1fb5de, which is not merged. [skip size check], as in 607519a.

- WebAssembly, plain Bun too: each byte of a `WebAssembly.Memory` is reported to the collector once,
  not again for each new `buffer` (engine; test/js/bun/gc/wasm-memory-buffer-after-grow.test.ts,
  wasm-memory-dropped.test.ts).
- WebAssembly, arm64: jump tables and constants out of reach in a large function no longer abort the
  build (engine; test/aot/wasm-large-function.test.ts).
- WebAssembly: `Bun.build()` in a process that runs compiled code no longer fails with TS100058 on a
  module of its own image (engine; test/aot/wasm-nested-build.test.ts).
- Executables: a getter on a CommonJS module's `exports`, read through a kept `createRequire()`
  result, runs once (src/jsc/bindings/BunCompiledModules.cpp and the engine; 52 test files).
- Executables: `Object.create(null, { .. })` allocates a smaller object (engine).
- bun check --aot, builds: type errors are reported again where tsc has no type for an import:
  source under the condition `"aot"`, and `int32` of `"bun"` without `@types/bun`
  (src/aot/compile/lower_stage.rs, src/aot/load/runtime_types.rs, src/sema/resolve.rs,
  src/sema/driver/lib.rs).
- Build warnings: TS100064 is printed again where an entry point is not code, and for dependencies
  (src/aot/load/host.rs, src/aot/compile/load_stage.rs, src/aot/diagnostics/engine_records.rs).
- Build warnings: `// bun-ignore` is no longer called stale in code that the executable leaves out
  or in dead code; JSX lines, all line ends, semicolons and block comments work
  (src/aot/diagnostics, src/sema/parser/lexer.rs). Still wrong: a build that stops at a type error
  calls a comment stale if it silences a warning of the engine.
- bun test --aot: a re-export stays linked to the load that it was linked to (engine; 85 test
  files).
- bun test --aot: after `require()` gave up on a module of an import cycle, the cycle's bodies run,
  in the order of `bun test` (engine; 65 test files).
- bun test --aot: an importer that is loaded again under a mock whose factory fails gets the first
  error, also where the mocked module is CommonJS (engine; 80 test files).
- Lint: one argument that clippy refused goes by reference.
- Docs: statements that a360dc8 had cut come back in 24 places of docs/compiler; three sentences on
  package options and warnings.
- Names, no logic: 2,409 test files move to names of at most five words; one function and one helper
  are renamed.
- Tests only: 60 stored programs about built-in names that reach a call through other values; a
  WebAssembly stack overflow; a generator of loops over number fields
  (test/aot/fuzz/fuzzilli/write-random-field-loop-sweep.ts).

Known issues where this commit, with the engine it pins, is worse than main (5):

- `bun test`, without `--aot`: A test file whose source contains the word `Actual` and a constant
  that is a sum of 100,000 strings makes plain `bun test` crash. On main it passes. Contrived.
  (loud)

- `bun test`, with and without `--aot`: A mock factory that asks `vi.importActual` for another file,
  under a name that begins with written text and goes on with something computed, as in `"./other" +
  x.length`, makes the mocked file itself run first. On main it does not run. (silent)

- The build: A package with `"sideEffects": false` whose index re-exports one CommonJS file both
  with `export *` and by name, imported both statically and with `import()`, stops the build with an
  internal compiler error. main builds it. (loud)

- `bun test --aot`: A module that imports its own namespace and threw the first time it ran is run
  again at the `vi.doMock()` call that names it, and the namespace it kept then reads the mock. On
  main the body runs once and it reads the module. Contrived. (silent)

- The build: The new warning TS100087, about a path looked up at run time, is also printed in two
  cases where the executable is right: the computed text names a built-in module, or the file it
  needs was added and another code file of the project still stays out. (a false warning)

Not built and not tested here as it stands: CI's run of this pull request is its first. The
formatters would change nothing in it.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
…nore in builds that stop

On fd88d2c. 39 files, +478 -208: docs 2 files +2 -2 . src 6 files +184 -206 . test 31 files +292
-0. The pin stays at eb1fb5de of oven-sh/WebKit#1025. [skip size check], as in 607519a.

- bun test and bun run, plain Bun too: a sum of 100,000 strings in a file whose source says `Actual`
  overflowed the stack (exit 139). a360dc8 brought that in; main is right. Which module
  `importActual()` or `requireActual()` names in a mock factory is now read from how its argument
  begins, in a loop: a string, the head of a template, or a `const` or enum member that is
  initialized with a string. Anything else means any module. The evaluator of sums, templates and
  numbers goes (src/js_parser/lower/hoist_test_mocks.rs,
  src/sema/import_sites/requested_originals.rs; docs/test/mocks.mdx;
  test/js/bun/test/mock/mock-module.test.ts; 30 new test files).
- bun test, with and without --aot: `vi.importActual("./other" + x.length)` in a factory no longer
  makes the mocked file itself run first. The same change. Of 226 generated forms of the argument,
  164 differed from main before it and 94 differ with it, 9 of them newly, on a build of the
  development tree; see the first known issue.
- Build warnings: a build that stops at an error no longer calls a `// bun-ignore` comment stale,
  and a comment over an error says that an error can't be silenced (src/aot/diagnostics,
  src/aot/compile.rs; docs/compiler/troubleshooting.mdx; 4 more cases).

Known issues where this commit, with the engine it pins, is worse than main (4):

- `bun test`, with and without `--aot`: A mock factory that asks `vi.importActual` for another file
  makes the mocked file itself run first where the name begins as the mocked file is written and
  goes on, or does not begin with a string. On main it does not run. Contrived. (silent)

- The build: A package with `"sideEffects": false` whose index re-exports one CommonJS file both
  with `export *` and by name, imported both statically and with `import()`, stops the build with an
  internal compiler error. main builds it. (loud)

- `bun test --aot`: A module that imports its own namespace and threw the first time it ran is run
  again at the `vi.doMock()` call that names it, and the namespace it kept then reads the mock. On
  main the body runs once and it reads the module. Contrived. (silent)

- The build: The new warning TS100087, about a path looked up at run time, is also printed in two
  cases where the executable is right: the computed text names a built-in module, or the file it
  needs was added and another code file of the project still stays out. (a false warning)

Not built and not tested here: CI's run of this pull request is its first. The formatters would
change nothing in it.

@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.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

…test files, detached loads

21 files, +591 -29: Source/JavaScriptCore/aot 21 files +591 -29.

On c6e34c0. Nothing changes outside aot/.

- `--trim`: a name known only at run time, read off the global object, keeps nothing.
  `globalThis[name]` and a global object that went out of sight counted as a use of everything that
  it leads to. `Bun[name]` and a name that the program spells count as before
  (aot/facts/AOTFactsOfProgram.cpp, AOTLinkTables.h).
- bun test --aot: the load that a refused `require()` left is evaluated in the microtask of `bun
  test`, and no longer five or more jobs early. A load that is due runs before its mock changes. The
  earlier main is wrong there in another way (aot/runtime/AOTModuleEvaluation.cpp,
  AOTTestRunFactories.cpp, AOTTestRunMocksLetGo.cpp, AOTModuleHost.h, AOTModules.h).
- bun test --aot: a module that is loaded again no longer reads the old instance of a module that it
  re-exports from, when nobody had made its namespace object. A fault of eb1fb5d
  (aot/runtime/AOTModules.cpp).
- bun test --aot --isolate: a new realm, and each collection, clears the property caches only of
  realms that have run since their last clear, not of every earlier one
  (aot/runtime/AOTInstance.cpp, AOTPropertyCaches.cpp, AOTPropertyCachesWords.h, AOTHeapHooks.cpp,
  AOTHeapCacheRegistry.h, aot/stubs/AOTStubsCallAdapters.cpp).
- bun test --aot: linking asks the image's tables whether an imported name exists, unless a mock is
  reachable through re-exports. It resolved the name through every `export *` target, for each
  importer and each test file (aot/runtime/AOTModuleLinking.cpp, AOTModuleTable.cpp,
  AOTModuleTable.h, AOTModules.h, AOTInstance.cpp, AOTVMState.h).
- bun test --aot: the report that a file did not run again is built once for each file, not at each
  load (aot/runtime/AOTTestRunMocksLetGo.cpp, AOTVMState.h).
- Checks: the check that read-only members of built-ins are what the table says tests for an
  exception after each lookup. A build with ASAN and exception checks stopped there
  (aot/builtins/AOTBuiltinTableValidation.cpp).
- Statistics: five counts of calls of built-ins by the row of the table that they reach. No
  generated code changes (aot/walk/AOTWalkBuiltins.cpp, aot/ir/schema/statistics.def).

"The earlier main" is Bun's main before oven-sh/bun#48120 was merged.

It is a copy of the development tree as it stood.

Not built and not tested here: CI's run of this pull request is its first.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
…ds named by helpers

On bc23277. 599 files, +5,034 -1,651: docs 3 files +3 -2 . scripts 1 file +1 -1 . src 84 files
+2,151 -1,253 . test 511 files +2,879 -395. Pins the preview build of oven-sh/WebKit#1025 at
c6e34c07, which is not merged. [skip size check], as in 607519a.

- Module mocks, with and without --aot: whether a mock factory requests the original is decided by
  main's rules again. Plain Bun searches the factory's printed source, and the compiler predicts
  that source. The syntax rule of a360dc8 is out: nothing of it is left in the parser, the printer,
  the AST or the transpiler cache, whose version is main's again. It ran the mocked file first where
  main does not, and did not load the original first in some scripts under `bun run` where main does
  (src/js_parser, src/js_printer, src/ast, src/jsc, src/runtime/jsc_hooks.rs; src/aot/lower,
  src/sema; docs/test/mocks.mdx; test/js/bun/test/mock/mock-module.test.ts).
- `mordant`: the walk from an expression to its statement is shared, and a local is renamed
  (src/sema/bind/mod.rs, src/sema/import_sites, src/aot/known_helpers,
  src/aot/lower/scope/enter.rs).
- bun compile: from review of this pull request: `bun compile serve` beside serve.ts and a package
  whose "bin" is named serve compiled the package at the second call and overwrote the program. A
  source file of that name in the working directory is the entry point in every build, in the
  resolver's order of extensions, and a build of a package's executable says so
  (src/runtime/cli/compile_command, src/runtime/cli/script_or_command.rs, src/bundler/options.rs;
  docs/compiler/aot.mdx; test/cli/compile/compile.test.ts).
- Builds: from review of this pull request: the search for code that the executable leaves out
  followed links to folders, and a project with several links to an ancestor stalled the build. It
  follows none, and runs only if a warning depends on it (src/aot/load/host.rs,
  src/aot/compile/load_stage.rs, src/aot/diagnostics; 7 more cases in
  test/aot/bun-ignore-comments.test.ts).
- --trim: a build on a template that cannot hold the whole program stopped because the plan behind
  its `(N MB trimmed)` figure failed. It goes on and prints the size alone (src/trim,
  src/runtime/cli/compile_command; test/bundler/compile-trim-template.test.ts).
- Executables, Windows: files below a module above the root are found by `path.join()`; the root
  directory was compared in the wrong path format (src/aot/compile/bind_stage.rs;
  test/aot/embedded-assets.test.ts; not run on Windows).
- Builds: in a package with `"sideEffects": false`, tree shaking dropped an import statement whose
  names nobody reads, and the names that the link looks up for it stayed. The build stopped
  (`InvalidModule`), or the executable stopped at its start. The statements on the path to such a
  name are kept (src/aot/modules, src/aot/compile; 165 test files).
- bun test --aot: a file that a mock may load again and whose import of another such file nobody
  reads, in a package with `"sideEffects": false`, stopped the build (`InvalidModule`). Only module
  instances that are read are linked (src/aot/modules, src/aot/compile; 45 test files).
- Executables: a load whose name is partly unknown, as in `require(path.join(folder, "good.json"))`,
  embeds the files that its known alternatives name (src/sema/import_sites,
  src/sema/program/code_imports.rs, src/aot/load/contents/load_names.rs;
  docs/compiler/compatibility.mdx).
- Builds: many loads that call one helper, as in `require("./" + pick("a"))`, no longer cost the
  square of their number, and each names its own file alone (src/sema/import_sites/alternatives.rs,
  parameters.rs; 102 test files with the line above).
- Executables: `require(computed("data.json"), { type: "text" })` with a computed name threw
  although the executable holds the file. It answers the text where every alternative of the name is
  known and the attributes are written as one `type` (src/aot/lower/module/loads.rs,
  src/sema/hir/module_syntax.rs; 40 test files).
- Builds: whether a function expression mentions its own name is recorded once, and no longer
  searched for in every expression of its file (src/sema/bind/runtime).
- Hardening: `--aot-harden=proof-checks` also checks calls that were hoisted out of loops and the
  freshness of built-ins' results (src/runtime/cli/compile_options.rs; 6 test files).
- Builds, arm64: a branch that no island can carry to its target is a build error that names the
  function (engine).
- Revert: bun test --aot: the fix of a360dc8 that let a project's module run again after it threw
  at its first load. With it, a module that imports its own namespace ran again at the `vi.doMock()`
  call that names it; right on main. Such a second load again rejects with the first error, or runs
  from source and says so (src/jsc/bindings/BunPlugin.cpp and the engine; its 21 test files go).
- bun test --aot: a second `vi.doMock()` over a module whose importer was loaded by `require()`
  waits for the next load and no longer calls its factory at the call. Same on the earlier main
  (engine; 13 test files).
- Speed: a class that writes no constructor no longer allocates a rest array in its generic entry
  (engine; 1 test file).
- Checks: the verifier no longer rejects sound loops over typed arrays under `--aot-check=Validate`,
  and three statistics are new (engine; 5 test files).
- Tests only, red in CI: the size bound of test/bundler/compile-trim-runtime.test.ts fits macOS, the
  union of a build-scaling test fits the limit of types, and a program on when an argument is
  collected is out.
- Tests only: ten stored test runs read re-exports through cached slots
  (test/aot/parallel-test-runs/reexports-read-through-cached-slots).
- Tests only: 204 cases hold a namespace object while its module is loaded again, and fail if an
  answer depends on a cache or on a collection (test/aot/module-identity-held-1.test.ts to -4; the
  known list matches the revert). `BUN_FUZZILLI_STORES_ONE_IN` sets how many programs
  test/aot/fuzz/fuzzilli/counters-as-coverage.py stores.

"The earlier main" is Bun's main before #48120 was merged.

Known issues where this commit, with the engine it pins, is worse than main (6):

- `bun test --aot` with `--rerun-each`: In a run that contains a mock, two test files that import
  each other run again, and one re-exports from the other: read through its own namespace, a
  re-exported name has the value of the first run. On main it has that of the last. (silent)

- The build: With two or more entry points the warning TS100064 about a computed `require()` is
  missing in six cases in which the executable then cannot find the file: in `node_modules`, behind
  links that lead out of the project, or through a link to an entry point. main prints it. (silent)

- `bun test --aot`: Where a module is loaded a second time, with `--rerun-each` or after a package
  failed and was mocked, a namespace object kept from the first load, or what is re-exported through
  it, can be another object, read another load or throw a `ReferenceError`. In each shape main has
  right what is wrong here; with `--rerun-each` main is wrong in other columns. (silent)

- Executables: Two `--asset` folders outside the project that share a base name are one folder in the
  executable; listing it shows the files of the first folder alone. main lists both. (silent)

- Executables: Two `--asset` folders outside the project that share a base name and both hold a file
  of one name: main stops the build; here it succeeds, and a read by the shared name gives the first
  file without a warning. (silent)

- The build: The new warning TS100087, about a path looked up at run time, is also printed in two
  cases where the executable is right: the computed text names a built-in module, or the file it
  needs was added and another code file of the project still stays out. (a false warning)

Not built and not tested here: CI's run of this pull request is its first. The formatters would
change nothing in it.

@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.

The last 3 reviews of this pull request each found new blocking issues. Where they share a root cause, one fix may close them together.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

…rs under mocks

83 files, +513 -878: Source/JavaScriptCore/aot 61 files +477 -838 . Source/JavaScriptCore/runtime 11
files +22 -23 . Source/JavaScriptCore/wasm 6 files +8 -10 . Source/JavaScriptCore/interpreter 3
files +3 -3 . Source/JavaScriptCore/assembler 2 files +3 -4.

On 81b5811. 22 files change outside aot/, +36 -40: comments alone, made shorter. None in heap/, WTF
or bmalloc.

- Revert: bun test --aot: the module instances of 8826534 and later commits. After a second load of
  a module, objects kept from one load could read another load, in cases that are right on main, and
  reads of such exports were slower. What returns is as on main: a module that is loaded again keeps
  one set of variables, so under `--rerun-each` functions and namespace objects of an earlier run
  read the latest run's. The IR schema changes back, so the engine and Bun go together
  (aot/ir/schema/program-records.def and 33 files in aot/facts, image, ir, plan, runtime, stubs,
  tests and walk).
- Realms, from review of 81b5811: in a program with several realms, a realm that becomes the only
  one again counts as one whose code may have run, so its property caches are cleared like any
  other's (aot/runtime/AOTInstance.cpp, AOTPropertyCaches.cpp, AOTVMState.h,
  aot/tests/AOTPropertyLookupTableTests.cpp).
- bun test --aot: a name that modules behind a chain of `export *` ask for, beside mocks, is
  resolved once for the whole chain (aot/runtime/AOTModuleLinking.cpp, AOTModuleTable.cpp,
  AOTModuleTable.h).
- bun test --aot: `require()` gives up on a pending mock factory, the factory rejects, and the file
  is required again. The importer ran over a mock that was not there, and a run that fails under
  `bun test` passed. The second `require()` now joins the failing load. Same on main
  (aot/runtime/AOTModuleEvaluation.cpp, AOTModuleLinking.cpp, AOTModules.h, AOTTestRunOriginals.cpp;
  the other half is in Bun's src/jsc/bindings/BunPlugin.cpp).
- Build memory: what the compiler caches for a body ends with the body's unit, and a large chunk of
  a thread's arena with the unit that needed it (aot/driver/AOTCompileStage.cpp,
  aot/ir/AOTBodyIndex.h, AOTBodyLiveness.cpp, aot/machine/AOTMachineArena.cpp, AOTMachineArena.h).
- Names and comments, no logic: 38 identifiers in aot/, among them `staticallyUsedBuiltins` and the
  functions of aot/runtime that release an earlier load; shorter comments in files outside aot/.

It is a copy of the development tree as it stood, less two speed changes of the last minutes and one
change to the notices at the end of a test run.

Not built and not tested here: CI's run of this pull request is its first.

@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 reviewed the latest push (61d90cd) and found no new bugs; given the size of this change (1124 files across the AOT compiler, runtime, stubs and wasm), a human look is still worthwhile.

What was reviewed:

  • The per-instance cache-clearing path: VMState::didChangeInstances at Source/JavaScriptCore/aot/runtime/AOTInstance.cpp:548 now marks the sole remaining instance as having run, which covers the retired-realm case raised on AOTStubsCallAdapters.cpp:150.
  • The per-load module instance machinery (other-module environments in Variable slots, links to released instances) is gone from the tree, so the earlier namespace-read and retainLinks findings no longer have code to apply to.
  • Not done by this review: no build or test run; the commit message itself notes CI is the first build of this version.
Extended reasoning...

The diff spans 1124 files (+22.6k/-22.1k) in Source/JavaScriptCore/aot plus wasm, runtime, interpreter and assembler, implementing an AOT compiler and runtime: code generation, register allocation, image layout, property caches, module loading and WebAssembly integration. It touches no auth, injection or data-exposure surface, but it does touch JIT-style code emission and GC-visible caches, where mistakes become memory-safety issues. The latest commit reverts the per-load module instance design and fixes the hasRunSinceClear flag for a realm that becomes the only instance, both of which were raised in earlier reviews; this run's hunt ran dry with no new findings. Two optional earlier nits remain open. The change's scale and the fact that it has not been built or tested before CI rule out approval.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
…ssets and mocks as on main

On f1a38bc. 273 files, +3,124 -1,617: bench 1 file +2 -2 . docs 5 files +20 -22 . scripts 1 file +1
-1 . src 95 files +1,347 -1,298 . test 171 files +1,754 -294. Pins the preview build of
oven-sh/WebKit#1025 at 61d90cd8, which is not merged. [skip size check], as in 607519a.

- Revert: bun test --aot: the module instances of a360dc8 and later commits, with their half in the
  engine. After a second load of a module, objects kept from one load could read another load, in
  cases that are right on main, and reads of such exports were slower. What returns is as on main: a
  module that is loaded again keeps one set of variables (src/aot/lower, src/aot/link,
  src/aot/modules, src/aot/ir/keys.rs, src/aot/compile; eleven stored runs are marked todo,
  test/aot/module-identity.known.txt lists 24 cases more).
- Revert: build warnings: TS100087 for computed paths, and the rule that stopped TS100064 once no
  code of the project was left out, with the search behind both. A file that is in the executable by
  one path is not found by another, so builds were quiet whose executables throw; main warns. A
  computed import path is always warned of again. `// bun-ignore` and TS100099 stay
  (src/aot/load/host.rs, src/aot/compile/load_stage.rs, src/aot/diagnostics,
  src/aot/diagnostic_codes.rs; docs/compiler/troubleshooting.mdx, compatibility.mdx).
- `--trim`: a name known only at run time, read off the global object, keeps nothing (engine).
  Reading `Bun.sql`, `Bun.SQL` or `Bun.postgres` where its native code was removed returns a
  function that throws `ERR_FEATURE_REMOVED` when it is used. Plain Bun: a read of the three asks
  first whether the feature was removed, which it never is there (src/jsc/bindings/BunObject.cpp,
  RemovedFeature.cpp, RemovableFeatures.h; docs/compiler/size.mdx; 2 test files).
- Executables, `--asset`: two outside folders with one base name list the files of both by that
  name, as on the earlier main, and the build warns once for a file name that both hold and says
  which file that path reads. The short name of an outside asset answers as on the earlier main
  again: a file with a slash after it is not found, nor a path with a backslash off Windows, and
  `Bun.embeddedFiles` and a listing of the root show the short name. Not run on Windows
  (src/standalone_graph, src/resolver/compiled_program.rs, src/runtime/cli/compile_command/build.rs;
  docs/compiler/executables.mdx; test/aot/embedded-assets.test.ts).
- bun compile: the executable is never written over an entry point, such as an own script named
  serve under `bun compile serve`; the build stops. A link to an entry point at the outfile is
  replaced. `bun build --compile` does not change (src/runtime/cli/build_command.rs,
  src/runtime/cli/compile_command; test/cli/compile/compile.test.ts).
- bun test --aot: `require()` gives up on a pending mock factory, the factory rejects, and the file
  is required again. The importer ran over a mock that was not there, and a run that fails under
  `bun test` passed. Same on main (src/jsc/bindings/BunPlugin.cpp and the engine; 36 test files).
- bun test --aot: a factory call that came to a fetch that another call had left pending, and then
  rejects, no longer ends the load; `bun test` goes on with the third mock. A silent regression of
  a360dc8 (src/jsc/bindings/BunPlugin.cpp; 6 test files).
- bun test --aot: the load that a refused `require()` left is evaluated in the microtask of `bun
  test`, and before `vi.resetModules()` takes modules out if it is due. The earlier main is wrong
  there in another way. Plain `bun test` returns before the new call
  (src/jsc/bindings/BunCompiledModules.cpp and the engine; 28 test files).
- bun test --aot --isolate: the property caches of a realm are cleared only if its code may have run
  (engine).
- bun test --aot: names behind `export *` chains beside mocks are resolved in the image's tables,
  once for a chain, and the report of a file that did not run again is built once (engine;
  test/aot/star-exports-cost-the-same-beside-mocks.test.ts).
- Builds of test runs: a file outside the run is bound and not folded where its imports are all
  statements or strings (src/aot/test_runs/files_of_run.rs, src/sema/file_analysis,
  src/sema/import_sites).
- Build memory: bodies are kept packed between their lowering and the engine
  (src/aot/emit/external_bodies.rs, src/aot/link, src/aot/ir/mod.rs).
- Docs: `proof-checks` tests what the compiler believes about values, not every compiler mistake
  (docs/compiler/aot.mdx).
- Tests only: 38 test files of stored runs on re-exports after a second load; three stored programs
  store their output; one program on when an object is collected goes; the executables of
  test/cli/compile/compile.test.ts are copies of a Bun without debug information; the check on names
  compared as text gets an entry (test/aot/compiler/names-compared-as-text.ts).
- Tests only, fuzzers: programs of 20 sweeps and of the mock nets decide a branch before they print,
  classes share fields without declaring them, and
  test/aot/fuzz/fuzzilli/write-random-module-graph-sweep.ts gets six groups.
- Names, comments and format, no logic: 33 identifiers, most of them of the mock code
  (src/jsc/bindings), shorter comments in 18 files, and four files formatted.

"The earlier main" is Bun's main before #48120 was merged.

Known issues where this commit, with the engine it pins, is worse than main (5):

- `bun test --aot` with `--rerun-each`: In the second pass, a mock factory that takes the original
  of a file that threw in a preload gets the error again, and the test fails. On main it passes.
  Contrived. (loud)

- `bun test --aot` with `--rerun-each`: In the second pass, a test that mocks and unmocks files of a
  package with a cycle of `export *` and a CommonJS file fails. On main it passes, with wrong
  values. Contrived. (loud)

- `--asset`: A folder from outside the project whose name holds a backslash is not found by its
  short name (not on Windows). On main it is. Contrived. (loud)

- `--asset`: A file in a folder from outside the project whose name holds a backslash is listed but
  cannot be read by any path (not on Windows). Contrived. (loud)

- `bun test --aot`: A second `require()` of a module whose async mock factory is settling throws for
  one job longer than on main. Contrived. (loud)

Not built and not tested here: CI's run of this pull request is its first. The formatters would
change nothing in it. Nothing of the --asset changes was run on Windows.
… a mock that is in place

4 files, +6 -3: Source/JavaScriptCore/aot 4 files +6 -3.

On 61d90cd. Nothing changes outside aot/.

- Executables: a read of a field off an object that had lost another field by `delete`, behind a
  `typeof` test, gave `undefined`. Right on the earlier main (aot/ir/AOTTypeNarrowing.cpp,
  AOTTypeNarrowing.h, aot/walk/AOTWalkNarrowingOfGuesses.cpp).
- bun test --aot: a second `require()` of a module whose async mock factory is settling no longer
  throws for one job longer than on main, where a mock is already in place. A fault of 61d90cd
  (aot/runtime/AOTTestRunMocksLetGo.cpp).

"The earlier main" is Bun's main before oven-sh/bun#48120 was merged.

The tree of 61d90cd with these two changes and nothing else.

Not built and not tested here: CI's run of this pull request is its first.

@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.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

…e the const it extends

5 files, +20 -2: Source/JavaScriptCore/aot 5 files +20 -2.

On a4eabe3. Nothing changes outside aot/.

- Executables: a field of a linked object that was deleted or redefined in an outer loop was read
  with its earlier value in the inner loop (aot/ir/AOTEffectsDeclared.h, AOTEffectsOfOperations.cpp,
  aot/ir/schema/prepared-operations.def, aot/codegen/AOTCodeGenerator.cpp).
- Builds: a module imported inside a `try` that declares a derived class with a method above the
  `const` it extends stopped the build with an internal compiler error. Right on main
  (aot/image/AOTClassRecords.cpp).

The tree of a4eabe3 with these two changes and nothing else.

Not built and not tested here: CI's run of this pull request is its first.

@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.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
…ked objects and classes

On fd28490. 146 files, +3,842 -62: scripts 1 file +1 -1 . src 4 files +132 -34 . test 141 files
+3,709 -27. Pins the preview build of oven-sh/WebKit#1025 at fffb0222, which is not merged. The pin,
tests and how `--asset` paths are looked up change. [skip size check], as in 607519a.

- Executables: a field of a linked object that was deleted or redefined in an outer loop was read
  with its earlier value in the inner loop. Fixed in the engine (8 stored programs in
  test/aot/parallel/links-marked-between-loops).
- Executables: a read of a field off an object that had lost another field by `delete`, behind a
  `typeof` test, gave `undefined`. Right on the earlier main. Fixed in the engine (111 stored
  programs in test/aot/parallel/reads-behind-failed-shape-tests).
- Builds: a module imported inside a `try` that declares a derived class with a method above the
  `const` it extends stopped the build with an internal compiler error. Right on main. Fixed in the
  engine (10 test files in test/aot/parallel/classes-in-dead-zones).
- bun test --aot: a second `require()` of a module whose async mock factory is settling no longer
  throws for one job longer than on main. Fixed in the engine (two stored runs in
  test/aot/parallel-test-runs/require-after-rejected-factory).
- Executables, `--asset`: the short name of an asset from outside the project is also found under an
  untidy spelling, as in `./note.txt` or `//note.txt` below the root
  (src/standalone_graph/compiled_program.rs). test/aot/embedded-assets.test.ts asks plain Bun which
  spellings name the asset's own file and expects the same of both names, and a failure shows only
  the rows that differ. Not run on Windows.
- Executables, `--asset`: off Windows a backslash stays part of a file's name, so a folder from
  outside the project whose name holds one is found by its short name, and its files are read. A
  module specifier is still parted at it (src/resolver/compiled_program.rs, src/standalone_graph,
  src/runtime/cli/compile_command/build.rs; test/aot/embedded-assets.test.ts).
- --trim: one test expects that its executable lacks native addons, bun:ffi and SQLite, which the
  program does not use (test/bundler/trim-by-use/near/exports/features.json).
- Tests only: the bound on the bytes that a trimmed hello world maps is restated, 25,960,000 to
  25,990,000; it measured 25,966,728 (test/bundler/compile-aot-size.test.ts).

"The earlier main" is Bun's main before #48120 was merged.

Known issues where this commit, with the engine it pins, is worse than main (2):

- `bun test --aot` with `--rerun-each`: In the second pass, a mock factory that takes the original
  of a file that threw in a preload gets the error again, and the test fails. On main it passes.
  Contrived. (loud)

- `bun test --aot` with `--rerun-each`: In the second pass, a test that mocks and unmocks files of a
  package with a cycle of `export *` and a CommonJS file fails. On main it passes, with wrong
  values. Contrived. (loud)

Not built and not tested here: CI's run of this pull request is its first.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
… compile, a gap on Windows

On 75466cb. 11 files, +131 -13: src 4 files +85 -12 . test 7 files +46 -1. The pin stays at the
preview build of oven-sh/WebKit#1025 at fffb0222. [skip size check], as in 607519a.

- Executables: a program no longer aborts with an internal error when it changes the exports object
  that `require(path, { type: "text" })` returns for a file that was already loaded as code, for
  example by `Object.freeze()`. Such a `require()` now checks first whether the file was loaded as
  code, as it already did for data files (src/aot/modules/module_set.rs; two stored programs in
  test/aot/parallel/typed-requires-of-computed-names).
- `bun compile`: on a file system that reports no inode numbers, a second build no longer refuses to
  replace its own executable. Such files are told apart by their real paths (src/bundler/aot,
  src/runtime/cli/compile_command/build.rs).
- Executables, `--asset`: a folder from outside the root directory that holds no files no longer
  adds its name to the listing of the root (src/runtime/cli/compile_command/build.rs,
  test/aot/embedded-assets.test.ts).
- Tests only: on Windows, test/aot/embedded-assets.test.ts failed in CI on 75466cb, because an
  executable does not find an asset under five spellings that `bun run` finds: a trailing slash,
  separator or backslash, a climb out of a file (`a.txt/../a.txt`) and, from an ES module, a
  lower-case drive letter. The test now names that gap: there it expects that one of them at least
  still differs. Not run on Windows.

Known issue, on Windows alone: under those spellings `existsSync()` and `Bun.file().exists()` answer
`false` for an embedded file, without an error. Not compared with main.

Known issues where this commit, with the engine it pins, is worse than main (2):

- `bun test --aot` with `--rerun-each`: In the second pass, a mock factory that takes the original
  of a file that threw in a preload gets the error again, and the test fails. On main it passes.
  Contrived. (loud)

- `bun test --aot` with `--rerun-each`: In the second pass, a test that mocks and unmocks files of a
  package with a cycle of `export *` and a CommonJS file fails. On main it passes, with wrong
  values. Contrived. (loud)

Not built and not tested here as one tree: CI's run of this pull request is its first.
…s over loaded and failed files

On fffb022. 8 files, +382 -14: Source/JavaScriptCore/aot 4 files +28 -2 .
Source/JavaScriptCore/assembler 3 files +329 -10 . Source/JavaScriptCore/b3 1 file +25 -2.

- x64: byte-sized atomic subtract, and, or, xor in WebAssembly whose result is unused stored a wrong
  byte, in executables and in the optimizing JIT. Four encodings lacked a prefix
  (assembler/X86Assembler.h; a test of every register in assembler/testmasm.cpp).
- arm64 without LSE atomics: a compare-exchange that has to fail could store when its
  store-exclusive was lost. This is WebAssembly's baseline tier. And the relaxed forms, which
  nothing uses, passed their registers to the store-exclusive in the wrong order
  (assembler/MacroAssemblerARM64.h; a test with a second thread in assembler/testmasm.cpp).
- Executables on x64: a WebAssembly load at the last bytes of a memory, masked to fewer bits,
  returned a value where it should trap. Code in the image alone (b3/B3LowerToAir.cpp).
- `bun test --aot`: a later mock over a file that threw in a preload calls its factory at the next
  load, as in `bun test`. The factory was called at once, and the load failed with the first error
  (aot/runtime/AOTModuleHost.h, AOTModules.cpp, AOTModules.h).
- `bun test --aot`: a package that imports a mocked CommonJS file whose original a `require()` has
  loaded gets the original, as in `bun test`. It got the mock (aot/runtime/AOTTestRunOriginals.cpp).

The other tests are in Bun's half. Not built on this tree: the preview build is the first.

@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 completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
…red programs for WebAssembly

On 91af53d. 42 files, +1,321 -6: scripts 1 file +1 -1 . src 1 file +27 -5 . test 40 files +1,293
-0. Pins the preview build of oven-sh/WebKit#1025 at 584729de, which is not merged.
[skip size check], as in 607519a.

- x64: byte-sized atomic subtract, and, or, xor in WebAssembly whose result is unused stored a wrong
  byte, in executables and in the optimizing JIT. Fixed in the engine (a stored program in
  test/aot/parallel/webassembly/byte-atomics).
- arm64 without LSE atomics: a compare-exchange that has to fail could store when its
  store-exclusive was lost. Fixed in the engine.
- Executables on x64: a WebAssembly load at the last bytes of a memory, masked to fewer bits,
  returned a value where it should trap. Fixed in the engine (a stored program in
  test/aot/parallel/webassembly/trapping-loads-read-all-bytes).
- `bun test --aot`: a module that is mocked again after a `require()` loaded its importer kept its
  earlier mock, so a test that should fail passed (src/jsc/bindings/BunPlugin.cpp; two stored runs
  in test/aot/parallel-test-runs/detached-require-loads).
- `bun test --aot`: after a refused `require()` of a mocked CommonJS file, a package that imports
  the file gets the original, as in `bun test`. Fixed in the engine (a stored run in
  test/aot/parallel-test-runs/package-bypasses-pending-commonjs-mock).
- `bun test --aot`: a later mock over a file that threw in a preload calls its factory at the next
  load, as in `bun test`. The factory was called at once, and the load failed with the first error
  (src/jsc/bindings/BunPlugin.cpp and the engine; stored runs in
  test/aot/parallel-test-runs/mocks-over-evicted-failure).

Known issues where this commit, with the engine it pins, is worse than main (2):

- `bun test --aot` with `--rerun-each`: In the second pass, a test that mocks and unmocks files of a
  package with a cycle of `export *` and a CommonJS file fails. On main it passes, with wrong
  values. Contrived. (loud)

- `bun test --aot`: Mocking three files of a package twice in a loop makes the second import of
  their barrel throw. (loud)

Not compared with main: on Windows an embedded file is not found by `existsSync()` and
`Bun.file().exists()` under a trailing separator, over `a.txt/../a.txt` or, from an ES module, with
a lower-case drive letter. (silent)

Not built and not tested here: CI's run of this pull request is its first.
@Jarred-Sumner
Jarred-Sumner merged commit 873ab3a into main Nov 10, 2026
88 checks passed
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
On af86d9e. 1 file, +1 -1: scripts 1 file +1 -1. [skip size check], as in 607519a.

- oven-sh/WebKit#1025 is merged as 873ab3a426f858450b4bdba51e230f79a8feec85. `WEBKIT_VERSION` in
  scripts/build/deps/webkit.ts now names that commit instead of the pull request's preview build,
  autobuild-preview-pr-1025-584729de. The engine's sources are the same: the merged commit's tree is
  the tree of 584729de.

Nothing else changes.
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 10, 2026
…8436)

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#1025. This
follows #48120.

About 9,400 files, +53,000 -22,000. About 3,200 of the files only move. Most of the rest is tests.

[skip size check], as in 607519a.

If you don't use `--aot`

- The transpiler's visit pass skips an empty list that it used to drain for every scope.
  src/jsc/RuntimeTranspilerStore.rs counts the transpiler jobs that were scheduled and completed:
  two additions per job.

- x64: byte-sized atomic subtract, and, or, xor in WebAssembly whose result is unused stored a wrong
  byte in the optimizing JIT; four encodings lacked a prefix. Hot JavaScript used the same encodings
  on x64: `Atomics.sub`, `and`, `or` and `xor` on an `Int8Array` or `Uint8Array` with an unused
  result stored a wrong byte. Fixed in the engine.

- arm64 without LSE atomics: a compare-exchange that has to fail could store when its
  store-exclusive was lost. Fixed in the engine.

- From the engine: `new WebAssembly.Module(bytes)` parses the bytes in place where no code can run
  in between; the optimizing JIT threads jumps through a `br_table` and tests a state machine's
  first state before its table; `Object.getOwnPropertyDescriptor()` and its relatives test one bit
  of the structure; each byte of a `WebAssembly.Memory` is reported to the collector once, not again
  for each new `buffer`; on x64, the stack check of a WebAssembly function compares with memory.

`bun compile`

- `bun compile rollup` compiles the executable that an installed package provides under that name,
  not the package's library. A source file of that name in the working directory comes first. `bun
  compile` stops if the executable would overwrite an entry point; files are compared by inode
  number, or by their real path on a file system that reports none.

- An entry point without an extension is read as code if its first line is a `#!` line that names
  node or bun.

- The build prints three rows, `bundle`, `check` and `compile`, whose times add up to the whole
  build. Notes come below them, grouped. Better messages for `--trim`, `--trim-without`,
  `--aot-harden` and `--library --target`.

With `--aot`

The engine's changes are described in oven-sh/WebKit#1025. On this side:

- A real type error stops the build again in a project without `@types/bun`, and type errors are
  reported again where tsc has no type for an import.

- A barrel in a `"sideEffects": false` package stays where its namespace is used as a value, and an
  import statement that tree shaking dropped no longer takes away names that the link looks up.

- A `require()` path is followed through nested array patterns and rest elements. A load whose name
  is partly unknown embeds the files that its known alternatives name.

- An asset outside the build's root keeps its place relative to the modules, and its short name is
  found under every spelling that names its own file in `bun run`, except on Windows (see the known
  issues). A folder without files adds no name to the listing of the root.

- `Buffer.from("text")`, `Uint8Array.fromBase64("text")` and `Uint8Array.fromHex("text")` with
  constant strings are encoded during the build.

- `bun test --aot`: about twenty fixes to module mocks. The bodies of an import cycle run, in the
  order of `bun test`, after `require()` gave up on one of its modules. An importer that is loaded
  again under a mock whose factory fails gets the first error again.

- `Buffer.concat`'s descriptor says `writable: false`, so that tar 7 and npm 11 work.

- `// bun-ignore TS100064` silences a compiler warning at a line. New and wider build warnings about
  files and paths that an executable will not find: TS100098, TS100099.

Docs

- The pages under docs/compiler are cut to what a user can hit, and checked against a build. About
  twenty wrong claims are fixed. The flag lists under docs/snippets/cli are held against `--help` by
  a test.

Names

- Bun follows the engine's new idiomatic names, 1,253 of them in the wire schema. Tests spell those
  names. No logic changes with the names.

Known issues

- Executables: a CommonJS file that the program loads with `import()` and that a computed
  `require()` of the same program also names runs in sloppy mode.

- `bun test --aot` with `--rerun-each`: in the second pass, a refused `import()` behind an unrelated
  mock gives another error object.

- `bun test --aot` with `--rerun-each`: in the second pass, a test that mocks and unmocks files of a
  package with a cycle of `export *` and a CommonJS file fails. Before, it passed, with wrong
  values. Contrived.

- `bun test --aot` with `--rerun-each`: in the second pass, a CommonJS test file times out when a
  mock factory takes the original of a file that threw. Before, it passed.

- `bun test --aot`: mocking three files of a package twice in a loop makes the second import of
  their barrel throw.

- Executables on Windows: an embedded file is not found by `existsSync()` and `Bun.file().exists()`
  if its path ends in a separator, climbs out of a file (`a.txt/../a.txt`) or, from an ES module,
  has a lower-case drive letter. Under `bun run` it is found. Not compared with main.
robobun added a commit to oven-sh/bun that referenced this pull request Nov 11, 2026
…ounds of an AOT executable [skip size check]

The engine has main of the fork at oven-sh/WebKit#1025 and three more
commits: a block of the heap is made only once its records have room
under a limit on address space, a position in the source is found
without the table of remembered positions when no memory is left for
it, and a test of the first.

A trimmed hello world maps 26,351,648 bytes and an untrimmed one
68,847,648 (25,975,112 and 68,430,152 on main).
robobun added a commit that referenced this pull request Nov 11, 2026
…f the boxed callee to cage the memory base

The merge of main at #1025 (e50312b) gave the patchpoint of an
indirect call one register more than x86-64 has. Upstream switches to
the callee's instance inside the generator of the call, so the
patchpoint has the code pointer in a fixed register and the boxed
callee and the callee instance in two more. Code for an image added
the function's record as an input and a scratch register of its own,
for the base of the cage that it loads before the switch. With six
arguments in registers only three registers are free there, and Air
stopped with "FATAL: no register for %tmp64". Bun's
test/aot/parallel/webassembly/six-arguments-through-a-table failed so
on every x64 lane.

The scratch of code for an image is now the register of the boxed
callee. That value is stored into the callee's frame at the start of
the generator and is dead from there, as the callee instance is dead
behind its store where upstream reuses it. The function's record is
stored at the start too. Signaling mode keeps its scratch register:
there an input can lie in the register of the bounds-checking size.
robobun added a commit that referenced this pull request Nov 11, 2026
…arguments

A module without a memory whose function calls through its table with
six arguments. On x86-64 every register is taken where that call is
made. With the patchpoint as the merge of main at #1025 first had it,
the compiler stops there with "FATAL: no register", and this test
fails.
Jarred-Sumner added a commit that referenced this pull request Nov 11, 2026
…tack traces as in bun run (#1028)

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#48478. This follows
#1025.

565 files, +24,718 -4,414: aot/tests 90 files, +3,077 -724; the rest of aot/ 395 files, +18,764
-3,265; outside aot/ 80 files, +2,877 -425. In heap/ one condition and one comment, for compiled
images; nothing in WTF or bmalloc, and nothing outside Source/JavaScriptCore.

Executables

- Two tests of bounds in a row, such as `if (v < 3) { a = 5; continue; } if (v > 9) { b = 7;
  continue; }`, took the first's arm for both where both arms are short. Fixed.

- Stack traces and error messages are closer to `bun run`: positions of constructions, destructuring
  and `await`, names of methods under computed keys, paths relative to the folder of the build. An
  async function that awaits itself through `Promise.all` is in a trace once.

- Modules: `require()` of an ES module whose graph holds a file that cannot be loaded runs the
  CommonJS files in front of it. Errors reach every load of a graph. A file that is imported as text
  and as JSON no longer mixes up its forms. After an imported CommonJS file throws, the next one
  that an import loads is the main module, as under `bun run`.

- A collection of compiled code that has no helper threads could wait for helpers, so a program
  whose heap is exhausted, or that may not start threads, could hang. The collector's thread marks
  there itself; plain Bun is unchanged.

`bun test --aot`

- Mocks: a package module that failed at its first load, chains of mocks whose factories take their
  original, mocks of files that import each other in a cycle or that fail, `resetModules()` inside a
  running graph, mocks below originals, an import() after one whose graph failed to link.

- `--rerun-each`: in the second pass, an import() that is refused again behind an unrelated mock is
  rejected with the same error object as under `bun test`.

WebAssembly in the image

- Frames are shrink-wrapped, the bounds checking register is not saved, direct calls pass the first
  mutable i32 global in a register, functions of Go's compiler are entered behind the switch on
  their parameter, an access that a succeeded one covers needs no check, on x64 comparisons read
  memory. A trap takes no lock.

Plain Bun too

- On x64 a WebAssembly load whose low bytes alone are used returned a value at the end of the memory
  where it should trap, in the optimizing JIT. Fixed.

- In the optimizing JIT: `f32.demote_f64` of a converted 64-bit integer rounded once where it rounds
  twice, and a signaling NaN stayed signaling through `f32.demote_f64` of `f64.promote_f32`. Fixed.

- arm64 with DotProd: `i32x4.relaxed_dot_i8x16_i7x16_add_s(x, x, c)` in the optimizing JIT
  multiplied by the addend where the result took x's register. Fixed.

- The data segments of a WebAssembly module lie in one buffer, each behind a short header:
  esbuild.wasm has 98,450 of them.

- B3: a Phi that follows its own Upsilon in a block is folded; assertion builds poison stale
  Value::owner pointers (#986).

- Corrected assembler operations that nothing calls with such operands: equal registers, negative
  immediates and masks, pairs of floats at far offsets, blinded additions, shifts by 32 and more.
  Small corrections in the x64 assembler and in the register allocator.

Speed (instructions, by our own benchmark rows)

- Async code and generators: an awaited call of a compiled function continues it in place, 687 to
  202 a call; a pipeline of generators is joined, 81 to 35 an element.

- Sorting: `sort((a, b) => a - b)` from 65 numbers on goes by digits, 1,286 to 52 an element for
  20,000 integers; `sort(comparator)` of typed arrays is compiled.

- Strings: substrings, parseInt(), keys of a `Map` that are joined, one character of a string,
  split(), destructuring, TextEncoder and TextDecoder (3,811 to 1,465 a line).

- Loops: lists in fields, rows of rows, nested loops, counters of any kind, views under strides and
  masks, sums of unknown values, BigInts, remainders, method chains, throwing callees.

- Objects: comparisons of one layout, `instanceof`, `Object.hasOwn()` and `Object.keys()` of
  records, getters and setters of host and class objects, static fields, spread copies, constructor
  functions below native classes. Results of functions of node:path and node:fs have types.

Size and build

- Image tables are coded. Constants are compared and loaded in place, and element accesses under a
  constant index take fewer bytes.

- Builds that took quadratic time: chains of classes and interfaces, unions with many tests, barrels
  with many stars under mocks, nested array patterns.

- `--aot-harden=proof-checks` verifies each stage. A frame part is closed under dominance.

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

Known issues, right before this commit

- In `bun test --aot`, a test file that mocks, with its original, a module of its own running graph,
  beside another such mock in a helper, can end with "never finished loading".

- With `--aot-harden=proof-checks`, a method that is replaced by that of another class stops a
  build, a replaced generator method that is stepped by hand can stop one, and so can a test of a
  list's length against the length before a push() or pop().

As before

- `bun test --aot`: with `vi.doMock()`, a factory that imports its own file and `vi.importActual()`,
  and with a mock of a file that a package has imported before, the answer is wrong as before,
  without the notice that was given before.

A line of a stack trace names the source relative to the folder of the build, so it no longer
includes `import.meta.path`; that is by design.
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