Skip to content

AOT: variables keep their stores where a loop ends with a TypeError; two fixes of builds - #1042

Merged
Jarred-Sumner merged 7 commits into
mainfrom
claude/aot-stores-before-type-errors
Nov 12, 2026
Merged

Jarred-Sumner merged 7 commits into
mainfrom
claude/aot-stores-before-type-errors

Conversation

@Jarred-Sumner

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

Copy link
Copy Markdown
Collaborator

Fixes in Bun's ahead-of-time compiler (bun build --compile --aot and bun test --aot, both experimental), found after #1040.

What's in it

29 files, +431 −105 against main, all of it under Source/JavaScriptCore/aot but for one line in runtime/JSObject.cpp that compiled programs alone run. Without --aot nothing changes.

Program On main File
x64: a for, while or for..of loop in a function changes a number in a variable of the file or of an enclosing function, and then ends with the engine's TypeError for a null or undefined element All of the loop's changes are lost codegen/AOTCastEmitter.cpp, codegen/AOTCodeGenerator.cpp
A loop with a continue cuts a text (s = s.slice(-11), substring(), a template) The text can come out uncut codegen/AOTCodeGenerator.cpp
A function asks data[Symbol.asyncIterator] and then walks a generator by for..of The generator of the caller can be unfinished afterwards walk/AOTWalkGeneratorsInLoops.cpp
A loop stores a property on an array to which it also pushes The property can lose its value codegen/AOTAccessEmitter.cpp, runtime/AOTPropertyCachesOperations.cpp
A function that calls itself with a large number added (a + 2147483647) behind a >> 0 or `a 0` The build can stop
Under --aot-harden=proof-checks, a function reads an object literal under a template key (({ a1: 1 })[`a${k}`]) The build stops walk/AOTCodeVerifier.cpp
A spread ({ ...q }) of what require() of an ES file gave in a try or behind a condition The executable ends with an abort plan/AOTSlotPlan.cpp
A method called in a loop gives a field a new list, and Object.assign() copied the object before The copy can show another list's elements facts/AOTLinkListsOfFields.cpp
A static field of a class is defined again by a native function, as stack by Error.captureStackTrace(), and a method of the class reads it The method can read the value from before object/AOTClassTable.cpp, object/AOTClosure.cpp, runtime/JSObject.cpp
A method of an array is held by a variable and called without a receiver in a loop The build stops walk/AOTWalkFusedChains.cpp
Several elements of a typed array held by a file's variable are read and written The build of some of these programs stops with an error (one of 400 drawn programs) walk/AOTWalkTypedElements.cpp
Neighboring functions that are called back or are traps of proxies, in a build on many threads One of two notes can be lost, so two builds of one program can differ facts/AOTLinkFlow.h, support/AOTThreads.h
A loop in a try passes a value of unknown type to String.fromCharCode(), and a later error is caught The catch can read that value cut to 16 bits walk/AOTWalkBuiltins.cpp
A build on many threads Can, rarely, stop, or differ from another facts/AOTLinkFlow.h, walk/AOTWalkGuesses.cpp

How it was run

By builds of the commit that each fix came with and of main beside it, x64 but where it says otherwise; the last line is of the last commit:

  • Loops that end with a TypeError: of 292 drawn programs 28 are wrong on main and none here, by default and with --aot-harden=proof-checks. Of 61,824 drawn forms 3,226 are wrong on main; of 77,280, those among them, none is wrong here, and none of 61,824 on arm64.
  • Typed arrays: the programs that stop the build on main answer as bun run does, and so do 300 drawn ones.
  • Two notes: found by the thread sanitizer. On arm64, one of 20 builds of a program with 2,000 functions that are called back differed on main. Here 48 builds gave one executable; main's did so too in that run, so it shows little.
  • The IR tests (2,783) and the native tests (2,168 on x64, 2,151 on arm64) pass.

Known issues

On main and here:

  • Where a program stores a method again and again on a prototype to which it also adds elements under integer keys, an older method can be called.
  • On x64, where a loop stores eight or more numbers 4 KB apart into one typed array, a number that it carries from the iteration before can be stored as it was in front of the loop.

Merge order

This merges first; then oven-sh/bun#48714 pins the merged commit.

…two fixes of builds

9 files, +35 -17, all under Source/JavaScriptCore/aot.

- On x64, where a loop changes a number in a variable of the file or of an enclosing function, and
  then ends with the engine's TypeError for a null or undefined element, the last changes were lost,
  and code that caught the error outside the function read an older number. The variable is now
  written before the error is thrown.

- The build of some programs that read and write several elements of a typed array held by a file's
  variable stopped with an error. Each way out of such a stretch now uses only the values of that
  way.

- With many threads, one of two notes about neighboring functions (that a function is called back,
  or is a trap of a proxy) could be lost, so two builds of one program could differ. The notes are
  now added atomically.

@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 this PR and didn't find any bugs. Because it changes the exception path emitted inside unrolled loops and the rebinding logic of the typed-array in-bounds walker, a human look would still be worthwhile.

What was reviewed:

  • Codegen: the mayThrowInPlace() gate — layOutTurns now bails from the fused x64 throw when loop-carried stores exist; the interleaved/vector layouts never set the flag, so they only fall back to the branch-to-throw path (slower, not wrong); emitFirstConditions keeps the in-place throw, which is sound since no store of the first turn has happened when a copied condition throws.
  • Link: the four BitVectors replaced by BytesSharedByThreads::add (relaxed load, then fetch_or); all writers and the single reader in WriterOfLink::writeFunction updated, no stale references remain.
  • Walk: forgetOtherPaths runs before the needed bindings at all three exit sites, so values in the forgotten range that an exit needs are rebound afterwards; not run here: the IR/testaot suites and the unified-sources name check (the new names are all class-scope).
Extended reasoning...

The commit touches nine files under Source/JavaScriptCore/aot (+35/-17): a new m_iterationMayThrowInPlace flag in CodeGenerator gating CastEmitter::throwAfterFailedTest, a thread-safe byte-set replacement for four per-function BitVectors in LinkFlow with a new BytesSharedByThreads::add, and a forgetOtherPaths lambda in tryOpenInBoundsPath that clears stale in-bounds-path bindings before each slow exit. It touches no auth, injection or data-exposure surface; it is compiler internals whose failure mode is wrong generated code or a failed build. The decision to defer rather than approve rests on the change being correctness-sensitive codegen and walker logic whose invariants (which values an exit's needed list covers, and which loop layouts carry sunk stores) cannot be fully settled by reading, and on /Source/JavaScriptCore being covered by a CODEOWNERS entry; no test was run in this review.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The changes update AOT loop throw eligibility, call-discovery flags, list-field analysis, closure writes, and slot planning. They also change walker binding handling, centralize cached value-use access, add locking for cached object expectations, and add an IR test.

Changes

In-place throw eligibility

Layer / File(s) Summary
Track in-place throw eligibility during loop layout
Source/JavaScriptCore/aot/codegen/AOTCodeGenerator.h, Source/JavaScriptCore/aot/codegen/AOTCodeGenerator.cpp, Source/JavaScriptCore/aot/codegen/AOTCastEmitter.cpp
CodeGenerator tracks whether the current laid-out iteration may throw in place. CastEmitter checks this state before returning the matched coercion.

Call-discovery flags

Layer / File(s) Summary
Define and store per-function flags
Source/JavaScriptCore/aot/facts/AOTLinkFlow.h, Source/JavaScriptCore/aot/facts/AOTLinkFlow.cpp, Source/JavaScriptCore/aot/support/AOTThreads.h
LinkFlow stores callback and proxy-discovery flags per function. BytesSharedByThreads adds atomic byte updates, and iteration over appended fields acquires the shared-data lock.
Record and read call-discovery flags
Source/JavaScriptCore/aot/facts/AOTLinkCalls.cpp, Source/JavaScriptCore/aot/facts/AOTLink.cpp
Call analysis records callback and proxy flags through LinkFlow. Function writing reads the accumulated flags through foundByCalls.

Typed-element walking and bindings

Layer / File(s) Summary
Clear bindings and handle String.fromCharCode in walker paths
Source/JavaScriptCore/aot/walk/AOTWalkTypedElements.cpp, Source/JavaScriptCore/aot/walk/AOTWalkBuiltins.cpp, Source/JavaScriptCore/aot/tests/walk/handlers/from-char-code-under-a-handler.ir
tryOpenInBoundsPath clears bindings outside the active slow-path exit before binding required values. The String.fromCharCode walker uses Walker::StandIn, and the IR test checks the call and handler argument.

List-field analysis

Layer / File(s) Summary
Discover holders and filter list candidates
Source/JavaScriptCore/aot/facts/AOTLinkListsOfFields.cpp
ListsOfFields discovers possible holder layouts and scans function summaries and calls for holder use. It filters candidate records based on holder access, stored values, and written-call conditions.

Closure static-field writes

Layer / File(s) Summary
Prepare static fields before direct writes
Source/JavaScriptCore/aot/object/AOTClassTable.cpp, Source/JavaScriptCore/aot/object/AOTPropertyWalk.h, Source/JavaScriptCore/aot/object/AOTClosure.cpp, Source/JavaScriptCore/runtime/JSObject.cpp
StaticFields empties a variable slot before inserting its value into the class object. Direct writes invoke a pre-write hook that can materialize the class object for a matching static field.

Cached value-use access

Layer / File(s) Summary
Centralize cached value-use access
Source/JavaScriptCore/aot/walk/AOTWalkGuesses.cpp
Guess and expectation code obtains cached value-use data through usesOfValues. The objects-expected cache appends new entries while holding its lock.

Callback-chain fusion

Layer / File(s) Summary
Check the first call receiver
Source/JavaScriptCore/aot/walk/AOTWalkFusedChains.cpp
Callback-chain fusion returns false when the first call has no this value operand.

Slot planning

Layer / File(s) Summary
Check whether fields may be filled in sight
Source/JavaScriptCore/aot/plan/AOTSlotPlan.cpp
Slot planning checks whether a field may be filled in sight before treating a never-written field as described by its type alone.
Merge Risk: Minimal · up to 4abf4

The AOT-only changes in this PR have no confirmed merge-blocking defect. One slot-planning edge case could not be inspected and is unverified.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description does not follow the WebKit template. It has no bug title, no Bugzilla link (the template requires a bugs.webkit.org show_bug.cgi?id= link), no 'Reviewed by' line, and no ChangeLog-styl… 1) Add a bug title and a Bugzilla link (https://bugs.webkit.org/show_bug.cgi?id=#####). Multiple changes may share one bug, but each change must be tied to a bug. 2) Replace the custom sections with the template format: the commit message l…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names one fix, loop stores lost when a loop ends with a TypeError, and it also mentions a second fix. The changeset covers that loop fix (AOTCastEmitter.cpp, AOTCodeGenerator.cpp) but also m…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names one fix, loop stores lost when a loop ends with a TypeError, and it also mentions a second fix. The changeset covers that loop fix (AOTCastEmitter.cpp, AOTCodeGenerator.cpp) but also many unrelated AOT fixes: slot plans, list fields, class static fields, fused chains, typed elements, thread-shared notes, and String.fromCharCode. The title therefore refers to a real part of the change but not the bulk of it, so it is partially related. It also uses a non-standard phrase, 'two fixes of builds', which is vague about the other fixes and is hard to scan.

Full details: Description check

Explanation

The description does not follow the WebKit template. It has no bug title, no Bugzilla link (the template requires a bugs.webkit.org show_bug.cgi?id= link), no 'Reviewed by' line, and no ChangeLog-style list of changed paths and functions. It uses its own sections instead (What's in it, How it was run, Known issues, Merge order). It does explain the purpose clearly: it lists 14 user-visible fixes in the AOT compiler, each with the affected files, and describes how each fix was tested. The explanation of why each fix works is thin, however. The author gives symptoms and test counts but does not explain the root cause for most changes. The description also cites #1040 and oven-sh/bun#48714, while the PR objectives mention oven-sh/bun#48677, which is an inconsistency to resolve.

Resolution

  1. Add a bug title and a Bugzilla link (https://bugs.webkit.org/show_bug.cgi?id=#####). Multiple changes may share one bug, but each change must be tied to a bug. 2) Replace the custom sections with the template format: the commit message layout with 'Reviewed by', an explanation of why each fix works, and a list of changed paths and functions (for example * aot/codegen/AOTCastEmitter.cpp: with the function names). 3) For each of the 14 fixes, explain the root cause and the change that fixes it, not only the symptom. 4) Resolve the bun PR number mismatch: the description says AOT: update the engine; stores in defaults of parameters, paths that stores rule out bun#48714, while the objectives say AOT: strings that packages evaluate, modules in bundles, class factories, mocks in import cycles bun#48677. 5) Confirm the commit-message text for the AOTSlotPlan fix (the spread of require() results) is reflected in the description, since the objectives mention it but the description table does not list a separate entry for it.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 78762df8-434f-4d8d-88bf-b70b3314a0ff
Commits

Reviewing files that changed from the base of the PR and between 4da9aa5 and 4abf4e5.

Files selected for processing: 1

  • Source/JavaScriptCore/aot/plan/AOTSlotPlan.cpp

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Preview build of 22a187a: autobuild-preview-pr-1042-22a187ad

…lock in the link

3 files, +46 -3: aot/walk/AOTWalkBuiltins.cpp, aot/facts/AOTLinkFlow.h and an IR test.

- Where a loop in a `try` passes a value of unknown type to String.fromCharCode() and a later error
  is caught, the `catch` could read that value cut to 16 bits. It reads the value itself now.

- A build on many threads can stop by chance: one thread read the fields that others append. It
  takes the lock for that now.

@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 updated PR (including the second commit) and found no bugs; since this changes loop-unrolling codegen and the walker's binding protocol, a human look is still worthwhile.

What was reviewed:

  • The new lock in LinkFlow::forEachAppendedField: LockerOfWhatIsShared is reentrant via a thread-local depth counter, so the callers that already hold it (appendAppendedFields, addEdge paths) do not self-deadlock, and all four functors passed in are non-blocking (vector append, counter, hash-set insert).
  • BytesSharedByThreads::add and the FoundByCalls bits: atomicExchangeOr is idempotent so the relaxed check-then-OR cannot lose a bit; the only reader (writeFunction) runs after the parallel phase; no stale references to the removed BitVectors remain.
  • mayThrowInPlace: true in emitFirstConditions is sound because peeling requires no loop-carried stores and the copied-conditions path runs before any iteration mutates them; throwAfterFailedTest returning nullptr only falls back to the general path.
  • forgetOtherPaths in tryOpenInBoundsPath keeps the existing savedBindings save-once/restore ordering intact across repeated slow paths and the join; Walker::StandIn matches the signature used and restores on the plan() failure path.
    The IR test and native test runs cited in the description were not re-run here.
Extended reasoning...

The diff touches only Source/JavaScriptCore/aot (11 files, +81/-20): x86_64-only codegen for unrolled counted loops, the parallel link's per-function callback/proxy flags and one shared-data lock, the walker's String.fromCharCode inlining, and the typed-array in-bounds path binding logic, plus one new .ir walk test. It touches no security-sensitive surface (no auth, crypto, injection, or data exposure). Approval is withheld rather than granted because the loop-unrolling store semantics and the walker's binding/rebinding invariants are subtle compiler internals whose correctness depends on invariants only partially visible in the diff, and the author's fuzz-based verification could not be reproduced in this run. A second commit landed after the earlier automated review, adding the lock, the RAII StandIn, and the test, so this body covers material that review could not have seen.

aot/walk/AOTWalkGuesses.cpp, +6 -3.

A build on many threads could, rarely, stop. A list that the threads share has a lock of its own
now.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
…ns the same; settled evals

51 files, +1199 -1774. Pins the preview build `autobuild-preview-pr-1042-599d6ae7`.

- A copy of a function that creates classes or functions looks its names up where the function is
  written. Where a name around the call hides one of them, the function isn't copied.

- An arrow function that creates classes isn't copied where `this`, `new.target`, `arguments` or
  `super` in an `extends` or a computed key belong to what is around it.

- A function that reads a private name of the class around it isn't copied.

- Where code that never runs replaces a function that creates classes, the build no longer stops.

- An executable keeps `eval()` itself beside each text that the build knows, and compares the texts
  in front of it.

- In a file that begins with `// @bun`, and in a text that is evaluated, functions and classes have
  the names that they have as written.

- A build warns (TS100172) again where a path that a package is handed is also the path of a read
  that a later store rules out.

- A parameter whose default writes files counts as writing unless the argument in its place is seen.
  `bun test --aot` threw at the load of a file that such a function had written. An argument that is
  `undefined` takes the default, and a spread behind the parameter's place changes nothing.

- Tests: test/aot/run-parallel.ts compares both sides of its check of memory below a small process,
  and a memory that was not told fails. test/aot/mock-factories.test.ts reads plain Bun's side on
  one thread; with several, plain Bun has two answers in two cases.

- Tests of plain Bun that could fail on a busy machine: the generator of
  serve-direct-readable-stream.test.ts ends by the abort alone, csrf.test.ts waits for the expiry,
  filesink.test.ts counts the descriptors of its own file, and the server of
  node-http-connect.test.ts runs until the test ends it.

- Programs of a fix in oven-sh/WebKit#1042: code units under handlers.
…ative functions define again

- Where a method called in a loop gives a field a new list and Object.assign() copied the object
  before, the copy could show another list's elements. It shows its own now.

- Where a native function such as Error.captureStackTrace() defines a static field of a class again,
  a method of the class could read the value from before. It reads the new one now.

- The build of a method of an array that is called without a receiver in a loop stopped. It no
  longer does.

- A build on many threads could, rarely, stop, or differ from another. What a thread asks for is
  there for it until it ends.

@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 fourth commit (the Object.assign lists pass, the static-field hook, and the guesses lock) and found no bugs; because it adds a new soundness pass to the link and a hook that every compiled program's native puts on closures run, a human look is still worthwhile.

What was reviewed:

  • BytesSharedByThreads::add and the forEachAppendedField lock: the relaxed read only skips an already-set byte and the OR is an atomic RMW, so concurrent notes are not lost; LockerOfWhatIsShared is depth-counted per thread, so callers already holding it do not deadlock, and listsOfObjectsExpected has no reader besides the locked append.
  • moveToProperties now empties the static slot before putDirect, which is what keeps willPutDirectOnClosure from re-entering ensureClassObject on the closure's own put; the moved value is a stack local, so it stays rooted across the put.
  • usesOfValues is unique at namespace scope across aot/ (the other hits are members); check-unified-sources.py and find-structures-decoded-behind-calls.py were not run in this review.
Extended reasoning...

The range adds four commits under Source/JavaScriptCore/aot plus one call in runtime/JSObject.cpp; the newest commit since the prior review adds a ~200-line checkHolderUses/isEnteredByWrittenCalls pass to AOTLinkListsOfFields.cpp, a willPutDirectOnClosure runtime hook with a reorder in moveToProperties, a receiver guard in fused chains, and a Lock plus a usesOfValues helper in AOTWalkGuesses.cpp. It touches no auth, crypto or injection surface; the sensitive surface is compiler soundness (which list-of-fields records are kept) and runtime object layout. The concurrency changes check out by reading (atomic RMW, reentrant locker, write-only vector) and no concrete bug was found, but the new link pass is a heuristic whose coverage cannot be settled by reading alone, and the change is large and owned by the AOT author, so defer rather than approve.

aot/plan/AOTSlotPlan.cpp, +10 -1.

A spread (`{ ...q }`) of what `require()` of an ES file gave in a `try` or behind a condition ended
the executable with an abort. It copies the exports now.

@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 two commits pushed since my last review (4da9aa5, 4abf4e5) and found no bugs; because they add a ~200-line holder analysis in AOTLinkListsOfFields.cpp and a new runtime hook on the putDirectInternal path of every compiled closure, a human look is still worthwhile.

What was reviewed:

  • willPutDirectOnClosure -> ensureClassObject -> moveToProperties re-entrance: the static variable is now emptied before putDirect, so the nested hook finds no field under that uid and does not recurse; the hook runs before putDirectInternal reads the structure, so no decoded Structure* is held across the possible allocation.
  • The new LockerOfWhatIsShared in forEachAppendedField: re-entrant through the thread-local depth counter, so callers already holding it do not deadlock; BytesSharedByThreads::add is an idempotent check-then-atomic-or.
  • New namespace-scope statics usesOfValues and mayBeFilledInSightForSlotPlan: no other definition under aot/, so unified-source bundles stay unambiguous.
  • checkHolderUses and isEnteredByWrittenCalls were read for cache keying and sort/binary_search consistency only; no build, IR test run or thread-sanitizer run was done here, so the author's reported runs stand as the evidence for those.
Extended reasoning...

The range covers five commits to Bun's AOT JavaScript compiler under Source/JavaScriptCore/aot plus one hook line in runtime/JSObject.cpp: loop codegen gating for in-place throws, a new fixpoint holder analysis and indirect-call-site check in the lists-of-fields link pass, a bitmask shared-by-threads replacement for four BitVectors, a lock on a per-body speculation cache, a runtime pre-put hook that may allocate, and a slot-plan tweak. It touches no auth, injection or data-exposure surface, but it does touch GC-sensitive runtime object code and multi-threaded compiler state. Two substantive commits landed after my last posted review, which is why a new body is warranted. The change is large and intricate compiler work covered by the /Source/JavaScriptCore CODEOWNERS entry, nothing was executed in this run, and the hunt ran dry without findings, so defer rather than approve.

Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
14 files, +245 -11. Pins the preview build `autobuild-preview-pr-1042-4abf4e5c`.

- A body in the output of a bundler may call its exports (`module.exports(x)`); the call threw.

- An iteration that awaits or yields behind a condition disposes the resources that it declares with
  `using`.

- Programs of fixes in oven-sh/WebKit#1042: copies by Object.assign(), static fields that native
  functions define again, methods of arrays without a receiver, spreads of namespaces.

- one-data-file-under-two-types/untyped-import-answers-before-text has its output stored: plain Bun
  prints another one in a few of 400 runs, by which of its reading threads ends first.
8 files, +52 -10, all under Source/JavaScriptCore/aot.

- A property that a loop stores on an array to which it also pushes could lose its value. It keeps
  it now.

- The build of a function that calls itself with a large number added (`a + 2147483647`) behind
  `a >> 0` or `a | 0` could stop, and, under --aot-harden=proof-checks, of a function that reads an
  object literal under a template key.

@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 three commits pushed since my last review (holder analysis, FindsAgain address lookup, moving-storage check, static-field hook) and found no bugs; because this is a large change across several interacting compiler analyses plus a runtime path that now asserts instead of falling back, a human look would still be worthwhile.

What was reviewed:

  • facts/AOTLinkListsOfFields.cpp holder analysis (findHolders fixpoint, checkHolderUses over summaries, isEnteredByWrittenCalls) and the lock changes: LockerOfWhatIsShared is depth-counted so the new lock in forEachAppendedField nests safely, and BytesSharedByThreads::add's read-before-OR is only a fast path over an atomic OR.
  • The FindsAgain path in operationAOTOwnNamedPropertyAddress: its RELEASE_ASSERTs are reached only from the restartIteration lookup that re-finds a property the same iteration already stored, and the moving-storage check is added in both the emitter and the FindReplaceableValue stub.
  • New namespace-scope names (usesOfValues, addressFoundAgain, mayBeFilledInSightForSlotPlan, AddressLookup, typesWithMovingStorage) were checked by search for unified-source collisions in aot/; check-unified-sources.py itself was not run.
Extended reasoning...

The change touches 27 files (+403/-102) in the experimental AOT compiler under Source/JavaScriptCore/aot plus one hook line in runtime/JSObject.cpp, spanning the link (new holder analysis, thread-shared flag bytes, a lock on appended fields), the walk (BodySpeculationCache access routed through usesOfValues, several build-stop fixes), codegen (loop iterations may no longer throw in place when loop-carried stores exist, moving-storage check on cached addresses) and runtime (a FindsAgain lookup that RELEASE_ASSERTs). It touches no auth, injection or data-exposure surface; the risk is compiler correctness and abort paths in compiled programs. The bug hunt ran dry with no findings and the one candidate (FindsAgain aborting where main fell back) was ruled out, but the size and the number of independent subtle analyses changed, three of them new since my prior review, make this unsuitable to approve without a human look.

3 files, +28 -3, all under Source/JavaScriptCore/aot.

- A text that a loop with a `continue` cuts (`s = s.slice(-11)`, `substring()`, a template) could
  come out uncut. It is cut now.

- Where a function asks `data[Symbol.asyncIterator]` and then walks a generator by `for..of`, the
  generator of the caller could be unfinished afterwards. It is finished now.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

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

27 files, +909 -108. Pins the preview build `autobuild-preview-pr-1042-22a187ad`.

- The build shares what it knows of the ways of a file that chooses a path through many members,
  items, variables, or calls in a `try`: in the stored tests it takes 235 to 312 MB where it took
  535 to 2,124.

- A text that the build computes with `indexOf("")` or `includes("")` is the one that the program
  computes; the executable ended with exit 134.

- A text that the build knows and that stores to a constant, an import or a member of a namespace
  throws where it does so; the executable ended with exit 134.

- An executable holds no times of folders outside what it embeds, so two builds of the same files
  are the same when such a folder changes: a folder is as new as the newest embedded file in it.

- With `--trim`, an executable no longer holds the JavaScript parser of `bun test --coverage`: Hello
  world has 25,599,456 bytes (27,340,320 without this).

- Programs of fixes in oven-sh/WebKit#1042: properties of arrays that a loop pushes to, texts that
  loops cut, generators that are passed on, and two builds that stopped.
@Jarred-Sumner
Jarred-Sumner merged commit b553971 into main Nov 12, 2026
88 checks passed
Jarred-Sumner added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
…stores rule out (#48714)

106 files, +3051 -368. Pins oven-sh/WebKit#1042 (merged) by the build of its last commit,
`autobuild-preview-pr-1042-22a187ad`.

- A store in the default of a parameter of a function with an empty body is seen, so a string that
  `eval()` is given is not taken for settled; the executable ended with an error (exit 134).

- A default that writes files is taken for the function that is called only where it is known to be,
  so a file that such a parameter reads is embedded.

- The build no longer warns (TS100098) about a path that a later store rules out; the file is
  embedded as before.

- A copy of a function that creates classes or functions looks its names up where the function is
  written. Where a name around the call hides one of them, the function isn't copied.

- An arrow function that creates classes isn't copied where `this`, `new.target`, `arguments` or
  `super` in an `extends` or a computed key belong to what is around it.

- A function that reads a private name of the class around it isn't copied.

- Where code that never runs replaces a function that creates classes, the build no longer stops.

- An `eval()` is left out only where every text that can arrive is proven; everywhere else the
  `eval()` itself stands there.

- In a file that begins with `// @bun`, and in a text that is evaluated, functions and classes have
  the names that they have as written.

- An async or generator function in the form of webpack's `require` is no such function: a call
  answers with its promise or its generator.

- A loader in the form of webpack's or Browserify's is taken for one only where no default runs,
  nothing is disposed and no variable is read before its declaration.

- A body in the output of a bundler may call its exports (`module.exports(x)`).

- An iteration that awaits or yields behind a condition disposes the resources that it declares with
  `using`.

- A text that the build computes with `indexOf("")` or `includes("")` is the one that the program
  computes.

- The build shares what it knows of the ways of a file that chooses a path: in stored tests it takes
  235 to 312 MB where it took 535 to 2,124.

- A text that the build knows and that stores to a constant, an import or a member of a namespace
  throws where it does so; the executable ended with exit 134.

- An executable holds no times of folders outside what it embeds: a folder is as new as the newest
  embedded file in it.

- With `--trim`, an executable no longer holds the JavaScript parser of `bun test --coverage`: Hello
  world has 25,599,456 bytes (27,340,320 without this).

- With the engine, on x64: where a `for`, `while` or `for..of` loop in a function changes a number
  in a variable of the file or of an enclosing function, and then ends with the engine's TypeError
  for a null or undefined element, the loop's changes are kept.

- With the engine: a text that a loop with a `continue` cuts is cut.

- With the engine: where a function asks `data[Symbol.asyncIterator]` and then walks a generator by
  `for..of`, the generator of the caller is finished afterwards.

- With the engine: a property that a loop stores on an array to which it also pushes keeps its
  value.

- With the engine: the build of a function that calls itself with a large number added no longer
  stops; nor, under `--aot-harden=proof-checks`, of one that reads an object literal under a
  template key.

- With the engine: a spread (`{ ...q }`) of what `require()` of an ES file gave in a `try` or behind
  a condition copies the exports; the executable ended with an abort.

- With the engine: where a method called in a loop gives a field a new list and Object.assign()
  copied the object before, the copy shows its own list's elements.

- With the engine: where a native function defines a static field of a class again, a method of the
  class reads the new value.

- With the engine: the build of a method of an array that is called without a receiver in a loop no
  longer stops.

- With the engine: the build of some programs that read and write several elements of a typed array
  held by a file's variable no longer stops.

- With the engine: where a loop in a `try` passes a value of unknown type to String.fromCharCode()
  and a later error is caught, the `catch` reads the value itself.

- With the engine: a build on many threads could, rarely, stop, or differ from another; it no longer
  does.

- Tests: Linux counts for a child the memory of the process that starts it until the child runs its
  program, so the driver of the stored programs could be told 248 MB of a program that holds 31 to
  34. Where that count is over the bound, both sides are run again below a small process and judged
  by that; a memory that was not told fails. The bound stays.

- Tests of plain Bun that could fail on a busy machine are restated by their causes: the abort test
  of `serve-direct-readable-stream.test.ts`, `csrf.test.ts`, `filesink.test.ts` and
  `node-http-connect.test.ts`.

- Known issue, on main too: where a program stores a method again and again on a prototype to which
  it also adds elements under integer keys, an older method can be called.

- Known issue, on main too: on x64, where a loop stores eight or more numbers 4 KB apart into one
  typed array, a number that it carries from the iteration before can be stored as it was in front
  of the loop.

- Known issue, on main too: `x % y` beside `(x / y) | 0` can give `-4294967296` instead of `-0`
  where `x` is `-2147483648` and `y` is `-1`.

- Known issue, on main too: the build of a program that captures an alias of `globalThis` in a
  closure, beside a property `get`, `has` or `apply` of an unknown object, can stop.

- Known issue, on main too: on x64, the build of a program whose outer loop sums integers around a
  relaxation over the rows of a grid can abort.

- Known issue, on main too: where a helper applies a generator function that it is given and its
  `catch` names the generator, the generator does not see what was added to the function's own
  `prototype`.
robobun added a commit that referenced this pull request Nov 12, 2026
main has #1041 (upstream cherry-picks) and #1042 (AOT). No conflicts, and no file of this change but
BUN-TEST-DIFFERENCES.md is touched. Nothing in the new code takes the async context.

b553971 is #1042 as merged. Bun's main pins the preview build of its head (oven-sh/bun#48714).
dylan-conway added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
### What does this PR do?

Pins WebKit to `b553971ea817`, the merge of oven-sh/WebKit#1042, in
place of its preview build `autobuild-preview-pr-1042-22a187ad`.

That commit also contains oven-sh/WebKit#1041, so this supersedes
#48730.

### How did you verify your code works?

The release for the commit is published. CI is the check.


---
_Generated by [Claude Code](https://claude.ai/code)_

Co-authored-by: Claude <noreply@anthropic.com>
robobun added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
main has #48714, which pins the preview build of oven-sh/WebKit#1042. That pull request is merged as b553971ea8.
WEBKIT_VERSION is now the preview build of the head of oven-sh/WebKit#941 (1c4943f623), which is b553971ea8 with the
change.

Conflicts: the pin, and one list of CI's runner, which takes main's and gets the test of this branch again
(test/aot/ci-lists.test.ts).
robobun added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
main has #48750: its pin is b553971ea8 itself now, which is oven-sh/WebKit#1042 as merged. WEBKIT_VERSION stays the
preview build of the head of oven-sh/WebKit#941 (1c4943f623), which is b553971ea8 with the change.

Conflict: the pin.
Jarred-Sumner added a commit that referenced this pull request Nov 13, 2026
…s, proxies, string searches (#1045)

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 a pull request that pins this one.
This follows #1042.

723 files, +61,098 -6,183: the rest of aot/ 580 files, +55,517 -5,820; aot/tests 113 files, +4,709
-247; outside aot/ 30 files, +872 -116. Nothing in heap/, WTF or bmalloc.

Arrays and loops

- Callbacks of array methods that read fields, compare, add or multiply run in stubs, also for
  arrays the build knows nothing about. Loops and functions get a version for the kind of array they
  meet. Checks of an array are shared by the iterations, and made before the loop where they can be.

- Loops that move elements, rotate values or search have their own machine code; sums over several
  rows run side by side. Objects that a loop reaches through an array are prefetched. Counters,
  remainders and positions stay int32s in more loops.

Objects and classes

- Accessors that a program defines at run time are called from their places without a lookup.
  Properties beyond an object's class are found by name in one step.

- A function that fills the fields of its argument is compiled for the object of the caller. Classes
  whose parents are parameters, members or results of calls keep their layouts.

- A Proxy is allocated in a stub and its traps are entered directly. Reflect.construct() runs in a
  stub. A get() or set() after has() uses the entry that was found.

Calls, strings and code from strings

- Spread calls don't create an array for the arguments. Small recursive functions are inlined into
  themselves.

- Short substrings of UTF-16 strings are shared as Latin-1 strings. A switch over strings goes
  through a table. Searches for words and for two prefixes test several characters at once.

- Strings that are known when the program is built are compiled, with the names they see.

Fixed

- A `return` that a loop's callee defines on a generator's prototype is called when the loop is
  left.

- Reflect.set() of a class field that was deleted stores nothing and answers false where the
  prototype has a read-only property of that name.

- Where the constructor of a base class returns an older object and the heir defines a field, a read
  of that field around a call that makes an heir gives the value that is there.

- A method that a program stores again and again on a prototype to which it also adds elements under
  integer keys is the one that is called; an older one could be.

- A read by name, behind a store under a key that is only known at run time, of a property that the
  program adds behind the object's literal gives the value that the loop stored.

- On x64, a loop that stores eight or more numbers 4 KB apart into one typed array stores the number
  that it carries from the iteration before. `x % y` beside `(x / y) | 0` is `-0` where `x` is
  `-2147483648` and `y` is `-1`.

- A generator function that a helper applies and its `catch` names keeps what was added to its own
  `prototype`.

- `Reflect.get()` or getOwnPropertyDescriptor() that a program hands on, bound or inherited, finds a
  built-in under a name that is made while the program runs; the executable ended with an abort
  where nothing else used it.

- A field that is written as a number and that a loop sets to `undefined` reads `undefined` in the
  next turn, and so does an optional field that an accessor of another new object reads before it is
  filled.

- Objects of a constructor function whose `prototype` is a primitive for some constructions have its
  own one later. The build of `(x * x) % m` of BigInts with a modulus out of a list no longer
  aborts. Nor does an executable with an eval() that stores `null` into a private field that is
  written as a number.

- `in` with a list as a key, and the last capture of a pattern that is nested 257 deep, no longer
  end with an abort. Some builds no longer stop: derived classes with a private field and an eval()
  behind super(), loops that carry objects and leave by side paths, outer loops that sum integers
  around a relaxation over rows. A for-in copy of many names no longer takes time with the square of
  their number, nor a function of many statements that reckon with what calls give with their cube.

- `bun test --aot`: a CommonJS file that a test file mocked, with a file that it requires, is mocked
  no more in the next test file.

Plain Bun too

- The length of `[, ...list]` where the list is empty; the message of replaceAll() on null or
  undefined in optimized code.

`Wire::schemaHash` changes, so this engine and Bun's side go together.
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