Skip to content

AOT: fixes after #1001: module mocks, module loading, programs that did not build - #1005

Merged
Jarred-Sumner merged 1 commit into
claude/one-walk-nextfrom
claude/one-walk-next-2
Nov 7, 2026
Merged

Jarred-Sumner merged 1 commit into
claude/one-walk-nextfrom
claude/one-walk-next-2

Conversation

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

On b0d7520. 19 files, +191 -30: Source/JavaScriptCore/aot/facts 7 files +34 -1 .
Source/JavaScriptCore/aot/runtime 6 files +134 -21 . Source/JavaScriptCore/aot/walk 4 files +15 -4 .
Source/JavaScriptCore/aot/tests 2 files +8 -4. Nothing outside aot/ changes. Fixes and their tests
alone. Bun's side is the pull request that follows oven-sh/bun#48120. Known problems, old and new,
are in its message.

  • Test runs with a preload that mocks; the shapes below answer as under bun test now. The host's
    half is in Bun's commit (aot/runtime/AOTModules.cpp, AOTModules.h, AOTModuleHost.h,
    AOTModuleEvaluation.cpp, AOTTestRunMockViews.cpp). Who owns the preload's mock under its key is
    asked anew behind the end of a test file that emptied the key, by a require() of a value too:
    two test files each did require, vi.doMock(), require, vi.doUnmock(), require, and the second
    got the file itself for the preload's mock. require.cache and a mock laid over the preload's
    read that the key was emptied, until the file itself has run under it. The run of an original
    beside a mock whose factory answers late is kept where the mock comes to stand in place: the body
    ran a second time. The run time is told what the host knows of whether the preload's mock comes
    back at the end of a mock. Known, new with this: asked by import() alone, behind a vi.doMock()
    that has ended and then a mock.module() that has ended too, the preload's mock answers where
    bun test gives the file itself. One test run.

  • A correct program did not build: word.charCodeAt(first) in a loop inside a for..of over a
    generator, with an index that was worked out in front of both: the compiler's own verifier stopped
    the build (UseNotDominated). What is noted of flat texts is taken in front of a loop only where it
    lies in front of that loop, as the notes of conversions and of equal operations are
    (aot/walk/AOTWalk.h, AOTWalkLoopInvariants.cpp, AOTWalkStringFlattening.cpp: +12 -1).

  • Silent, in executables, new with AOT: the next base #1001: a JSON file is imported with { with: { type: "text" } }, the program holds an import of it as JSON that does not run, and import()
    loads it by a name made at the run: a require() by that name gave what the first import made. It
    finds first what the import without a type left, as the loader does
    (aot/runtime/AOTModuleEvaluation.cpp: +3).

  • Silent, in executables, new with AOT: more fixes, stacked on #999 #1000: one .sqlite file imported twice under a name
    made at the run, as { type: "text" } and then as { type: "sqlite" }: each type got a form of
    its own (string object; the other way round object string), where bun <file> hands out the
    first form again (string string, object object). What is found under the written name goes
    through the loader's two questions like every other form: it is the module that came first
    (aot/runtime/AOTModules.cpp, AOTModules.h: +36 -8).

  • A correct program did not build, new with AOT: the next base #1001: each turn of a loop that a number
    bounds fills a list that is born empty or with its length and then pushes onto one that is born
    with an element that is no constant: const low = []; const high = [list[0]]; for (let i = 1; i < n; i++) { low.push(..); high.push(..); }: the build stopped with "panic: abort() called". What
    the list before was given, or that it was given nothing, stood for the bound of the next one; the
    bound has a name of its own (aot/walk/AOTWalkListReadsInLoops.cpp: +3 -3).

  • In executables, old: main.mjs imports first.mjs, second.mjs and shared.mjs, in this order,
    first.mjs imports shared.mjs, shared.mjs imports alpha.cjs, and second.mjs imports beta.cjs. If
    both .cjs files require fs, stream, crypto, http, https, net or zlib, the executable
    threw RangeError: Maximum call stack size exceeded when it started; in other shapes, and without
    an error, the default import of alpha.cjs was undefined or a require() in a try went without
    the module. Where such a built-in makes the run time hand the graph to the loader, the hand-over
    ran a file inside the file that was running. It runs none there
    (aot/runtime/AOTModuleEvaluation.cpp: +17 -2).

  • Known, old: where a CommonJS file calls import() at its top level, and is loaded by a
    require() of an ES module out of another CommonJS file that has already loaded such a file,
    modules that import it can run inside that call and read undefined for what it exports behind
    the call. No error tells you.

  • Silent, test runs: a package's file holds export * from two files that both export one name, and
    a mock that leaves that name out lies over one or both and has been loaded: bun test refuses
    with "Cannot export 'square' multiple times", and the compiled run passed with undefined.
    Whether a name is hidden in the file itself was asked of the list of what its mock lacks
    (aot/runtime/AOTModules.cpp: one line).

  • Silent, test runs, old: a CommonJS file that the end of a mock sends back to run anew is captured
    anew for whoever imports it: (await import("./lib.cjs")).n said the earlier run's 1 where
    require("./lib.cjs").n said 2 (aot/runtime/AOTModuleLinking.cpp, AOTModules.cpp, AOTModules.h:
    +15 -5). An importer that stays loaded reads the new run too, where bun test keeps the old: not
    fixed.

  • What a container holds is proven at an operation in fewer places (aot/facts/AOTLink.cpp: +1 -1).

  • A built-in that hands out the prototype of an operand and may be called out of sight counts as a
    climb from what is out of sight (aot/facts: 6 files, +33).

  • Tests alone: two IR tests on then() and catch() hand Promise to the driver that makes their
    promises: under --mechanisms=none a count of one operation differed since AOT: the next base #1001;
    no check line moves.

Built here, release, x64, no LTO, not hardened, with Bun's side: 0 errors. The engine's tests: 3,156
passed, 0 failed, 3 todo; with the table of the stand-in host 5,071 passed, 0 failed, 46 todo, 19
left out, which need entries of Bun. Not run here: arm64, musl, Windows, macOS, ASAN, the hardened
build, LTO.

…id not build

On b0d7520. 19 files, +191 -30: Source/JavaScriptCore/aot/facts 7 files +34 -1 .
Source/JavaScriptCore/aot/runtime 6 files +134 -21 . Source/JavaScriptCore/aot/walk 4 files +15 -4 .
Source/JavaScriptCore/aot/tests 2 files +8 -4. Nothing outside aot/ changes. Fixes and their tests
alone. Bun's side is the pull request that follows oven-sh/bun#48120. Known problems, old and new,
are in its message.

- Test runs with a preload that mocks; the shapes below answer as under `bun test` now. The host's
  half is in Bun's commit (aot/runtime/AOTModules.cpp, AOTModules.h, AOTModuleHost.h,
  AOTModuleEvaluation.cpp, AOTTestRunMockViews.cpp). Who owns the preload's mock under its key is
  asked anew behind the end of a test file that emptied the key, by a `require()` of a value too:
  two test files each did require, `vi.doMock()`, require, `vi.doUnmock()`, require, and the second
  got the file itself for the preload's mock. `require.cache` and a mock laid over the preload's
  read that the key was emptied, until the file itself has run under it. The run of an original
  beside a mock whose factory answers late is kept where the mock comes to stand in place: the body
  ran a second time. The run time is told what the host knows of whether the preload's mock comes
  back at the end of a mock. Known, new with this: asked by `import()` alone, behind a `vi.doMock()`
  that has ended and then a `mock.module()` that has ended too, the preload's mock answers where
  `bun test` gives the file itself. One test run.

- A correct program did not build: `word.charCodeAt(first)` in a loop inside a `for..of` over a
  generator, with an index that was worked out in front of both: the compiler's own verifier stopped
  the build (UseNotDominated). What is noted of flat texts is taken in front of a loop only where it
  lies in front of that loop, as the notes of conversions and of equal operations are
  (aot/walk/AOTWalk.h, AOTWalkLoopInvariants.cpp, AOTWalkStringFlattening.cpp: +12 -1).

- Silent, in executables, new with #1001: a JSON file is imported with `{ with: {
  type: "text" } }`, the program holds an import of it as JSON that does not run, and `import()`
  loads it by a name made at the run: a `require()` by that name gave what the first import made. It
  finds first what the import without a type left, as the loader does
  (aot/runtime/AOTModuleEvaluation.cpp: +3).

- Silent, in executables, new with #1000: one .sqlite file imported twice under a name
  made at the run, as `{ type: "text" }` and then as `{ type: "sqlite" }`: each type got a form of
  its own (`string object`; the other way round `object string`), where `bun <file>` hands out the
  first form again (`string string`, `object object`). What is found under the written name goes
  through the loader's two questions like every other form: it is the module that came first
  (aot/runtime/AOTModules.cpp, AOTModules.h: +36 -8).

- A correct program did not build, new with #1001: each turn of a loop that a number
  bounds fills a list that is born empty or with its length and then pushes onto one that is born
  with an element that is no constant: `const low = []; const high = [list[0]]; for (let i = 1; i <
  n; i++) { low.push(..); high.push(..); }`: the build stopped with "panic: abort() called". What
  the list before was given, or that it was given nothing, stood for the bound of the next one; the
  bound has a name of its own (aot/walk/AOTWalkListReadsInLoops.cpp: +3 -3).

- In executables, old: main.mjs imports first.mjs, second.mjs and shared.mjs, in this order,
  first.mjs imports shared.mjs, shared.mjs imports alpha.cjs, and second.mjs imports beta.cjs. If
  both .cjs files require `fs`, `stream`, `crypto`, `http`, `https`, `net` or `zlib`, the executable
  threw `RangeError: Maximum call stack size exceeded` when it started; in other shapes, and without
  an error, the default import of alpha.cjs was `undefined` or a `require()` in a `try` went without
  the module. Where such a built-in makes the run time hand the graph to the loader, the hand-over
  ran a file inside the file that was running. It runs none there
  (aot/runtime/AOTModuleEvaluation.cpp: +17 -2).

- Known, old: where a CommonJS file calls `import()` at its top level, and is loaded by a
  `require()` of an ES module out of another CommonJS file that has already loaded such a file,
  modules that import it can run inside that call and read `undefined` for what it exports behind
  the call. No error tells you.

- Silent, test runs: a package's file holds `export *` from two files that both export one name, and
  a mock that leaves that name out lies over one or both and has been loaded: `bun test` refuses
  with "Cannot export 'square' multiple times", and the compiled run passed with `undefined`.
  Whether a name is hidden in the file itself was asked of the list of what its mock lacks
  (aot/runtime/AOTModules.cpp: one line).

- Silent, test runs, old: a CommonJS file that the end of a mock sends back to run anew is captured
  anew for whoever imports it: `(await import("./lib.cjs")).n` said the earlier run's 1 where
  `require("./lib.cjs").n` said 2 (aot/runtime/AOTModuleLinking.cpp, AOTModules.cpp, AOTModules.h:
  +15 -5). An importer that stays loaded reads the new run too, where `bun test` keeps the old: not
  fixed.

- What a container holds is proven at an operation in fewer places (aot/facts/AOTLink.cpp: +1 -1).

- A built-in that hands out the prototype of an operand and may be called out of sight counts as a
  climb from what is out of sight (aot/facts: 6 files, +33).

- Tests alone: two IR tests on `then()` and `catch()` hand `Promise` to the driver that makes their
  promises: under `--mechanisms=none` a count of one operation differed since #1001;
  no check line moves.

Built here, release, x64, no LTO, not hardened, with Bun's side: 0 errors. The engine's tests: 3,156
passed, 0 failed, 3 todo; with the table of the stand-in host 5,071 passed, 0 failed, 46 todo, 19
left out, which need entries of Bun. Not run 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, a few neighbouring paths were also checked and ruled out: the emptied-key bookkeeping around didEmptyKeyOfMockInPlace / noteAskUnderMockInPlace (AOTModules.cpp, AOTTestRunMockViews.cpp) does not consume the marker from the engine's own asks before the test asks; forgetCapturedExports in letGoOfRecordThatAnswersByMock does not re-capture from undefined exports since the capture is left to the next run; and the roomByCount hoist in AOTWalkListReadsInLoops.cpp plus the isInSightWhereWalkBuilds guard in flatStringInSight follow the existing conversion-note pattern without reusing a refused record.

Extended reasoning...

The change touches aot/ only: link-time facts (a new climb-from-unseen flag), the module runtime's mock-in-place and loader hand-over bookkeeping, and three walk-side fixes for programs that failed to build. No security-sensitive surface (auth, crypto, injection) is involved. Three inline findings already signal that a human look is needed; this note only records what else was examined.

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

Comment on lines +3550 to +3564
static String pathBesideFile(StringView file, StringView written)
{
Vector<StringView, 16> segments;
for (StringView segment : file.left(file.reverseFind('/') + 1).split('/'))
segments.append(segment);
for (StringView segment : written.split('/')) {
if (segment == ".."_s && !segments.isEmpty())
segments.removeLast();
else if (segment != "."_s && segment != ".."_s)
segments.append(segment);
}
StringBuilder path;
for (StringView segment : segments)
path.append('/', segment);
return path.toString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 On Windows (or any path with backslashes or a drive letter) the new sqlite/text dedupe for import() by a run-time name stays inert, and each attribute type still gets a form of its own as on the base branch. pathBesideFile at AOTModules.cpp:3553 only splits on '/' and rebuilds every path with a leading '/', so a referrer path like C:\a\main.js yields /x.sqlite and C:/a/main.js yields /C:/a/x.sqlite, keys the loader never holds. Fix: derive the directory the way the file already does for Windows (both separators and a drive prefix, as in directoryOf at AOTModules.cpp:5143 and isAbsoluteFileSystemPath at AOTModules.cpp:71) and keep the referrer's own prefix instead of prepending '/'. [also at: Source/JavaScriptCore/aot/runtime/AOTModules.cpp:3580 - On hosts whose module paths are not POSIX absolute paths (Windows drive letters or backslashes, or a resolver that normalizes), the new first-form bookkeeping for import() with attributes is keyed under a path nobody else looks up, so the sqlite/text double-form behaviour this PR fixes stays as…]

Why this was flagged

importDynamic at AOTModules.cpp:4316 calls findFormUnderWrittenName with the referrer and a written name starting with './' or '../'. findFormUnderWrittenName at AOTModules.cpp:3580 builds keyBesideAsker from pathBesideFile(m_table.pathText(referrer), written). pathBesideFile at AOTModules.cpp:3553 takes the part of the referrer up to the last '/' only, and at AOTModules.cpp:3563 writes every segment behind a '/'. When pathText holds backslashes (this file expects them: AOTModules.cpp:71-77 treats '\' as a separator on Windows) no segment of the referrer survives and the key becomes '/x.sqlite'; with forward slashes and a drive letter it becomes '/C:/a/x.sqlite'. Neither key is in loader()->moduleMap() or m_formsAnsweredFirst, so findWithAttributes at AOTModules.cpp:3538 falls through to the module found under the written name and returns it, and AOTModules.cpp:3583 returns found as the base did. The user on Windows keeps getting string object / object string for one file imported twice under two types where bun <file> gives string string.

Verification: On a Windows build, when a referrer's table path holds a drive letter and/or backslashes, pathBesideFile at AOTModules.cpp:3553 splits the referrer only at '/' and line 3563 rebuilds every segment behind a leading '/', so C:\a\main.js + ./x.sqlite yields /x.sqlite and C:/a/main.js yields /C:/a/x.sqlite. The key built at 3580 therefore never equals the loader-resolved key.

Comment on lines 6744 to +6747
if (modules->letsMockOverModuleThatHasRunStandForLoadInFlight(module))
return;
auto scope = DECLARE_THROW_SCOPE(realm->vm());
bool isBack = modules->bringBackMockKeptByImportersOfThisTestFile(module);
bool isBack = wasLaidOverMockOfPreload && modules->bringBackMockKeptByImportersOfThisTestFile(module);

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) Test runs whose mock ends while its factory is still running lose the host's new wasLaidOverMockOfPreload = false and can get the preload's mock brought back anyway. didEndMock returns at AOTModules.cpp:6744 when letsMockOverModuleThatHasRunStandForLoadInFlight defers the end, before the flag is read at AOTModules.cpp:6747. The deferred end is re-issued by endMockThatStandsForLoadsInFlight at AOTTestRunFactories.cpp:351 as AOT::didEndMock(m_instance.globalObject, module), so the default true applies. Fix: keep the host's flag across the deferral, so bringBackMockKeptByImportersOfThisTestFile is skipped on both paths whenever the host said the mock was not laid over the preload's.

Why this was flagged

Trigger: in a test run with a preload mock on module M, the host calls AOT::didEndMock(realm, M, original, false) at AOTModules.cpp:6735 while M's mock factory is running (m_modulesWhoseFactoryRuns.get(M)), M is left alone by its mock and no import asks for it, so letsMockOverModuleThatHasRunStandForLoadInFlight at AOTModules.h:310 returns true and didEndMock returns at AOTModules.cpp:6744-6745 before line 6747 reads wasLaidOverMockOfPreload. Later endMocksThatStandForLoadsInFlight at AOTTestRunFactories.cpp:333 calls endMockThatStandsForLoadsInFlight, which at AOTTestRunFactories.cpp:351 re-issues AOT::didEndMock(m_instance.globalObject, module) with the defaults from AOTModuleHost.h:270, so wasLaidOverMockOfPreload is true and bringBackMockKeptByImportersOfThisTestFile at AOTTestRunMockViews.cpp:438 runs and may call setMockInPlace(fileOrModule, ofPreload, ...) at line 452 and return early. The host's false is meant to suppress exactly that; on this path the behavior is the base branch's, where the preload's mock answers for M where bun test gives the file itself.

Verification: AOTModules.cpp:6744-6745 if (modules->letsMockOverModuleThatHasRunStandForLoadInFlight(module)) return; runs before line 6747. Every re-issue goes through Modules::endMockThatStandsForLoadsInFlight at AOTTestRunFactories.cpp:351, so the deferred end runs bringBackMockKeptByImportersOfThisTestFile unconditionally.

Comment on lines +1552 to +1553
if (!m_call.builtin && (m_shared || m_call.numberOfArguments || m_call.passesList) && !m_flow.codeAtWorkIsOfLibrary())
m_flow.noteOperandsHandedToCalleeNobodyKnows();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟣 pre-existing, not blocking: Pre-existing gap this partial fix leaves open: a program that hands objects to unseen code only through a built-in's callback (arr.forEach(unseenFn), promise.then(unseenFn), setTimeout(fn, 0, obj)) still gets no climb from unseen objects counted. The new note at AOTLinkCalls.cpp:1553 runs only inside callUnseen. Row callbacks go applyCallback -> callValues -> passToUnseen (AOTLinkCalls.cpp:3001, 2958), which escapes the operands without the note. Fix: call noteOperandsHandedToCalleeNobodyKnows wherever program operands reach an unseen callee, including passToUnseen when passed holds operands and the code at work is not library code, so the same climb is forced as for a direct call.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

A program passes an object to unseen code through a built-in's callback, for example [obj].forEach(unseenFn) or promise.then(unseenFn), and never calls an unseen function directly. The row's callback is applied at AOTLinkCalls.cpp:3967 through callValues; for a callee that holdsUnseen, AOTLinkCalls.cpp:3001-3002 calls passToUnseen (AOTLinkCalls.cpp:2958-2964), which escapes the operands but never calls m_flow.noteOperandsHandedToCalleeNobodyKnows. That note exists only at AOTLinkCalls.cpp:1552-1553 inside callUnseen, which the callback path does not reach. So handsOperandsToCalleesNobodyKnows stays false and BuiltinsInReach::settle (AOTFactsOfProgram.cpp:6481-6484) never forces climbsFromUnseenObjects. isReachedThroughUnseen (AOTFactsOfProgram.cpp:3085) then answers false for an engine prototype, and reasonToLeaveOpenUnder (AOTFactsOfProgram.cpp:3140) keeps its members lockable, exactly as the base branch does. The PR fixes this for direct calls to unseen callees only; the callback hand-off is the sibling path left failing as before.

Verification: The new note lives only in CallInLinkCalls::callUnseen (AOTLinkCalls.cpp:1552-1553). A row's callback goes applyCallback (line 3967) to callValues (lines 3001-3002) to passToUnseen (lines 2958-2964), which never calls noteOperandsHandedToCalleeNobodyKnows. So settle (AOTFactsOfProgram.cpp:6481-6484) never forces climbsFromUnseenObjects and the prototype can be wrongly locked, as before.

@Jarred-Sumner
Jarred-Sumner merged commit f3cc5db into claude/one-walk-next Nov 7, 2026
86 of 87 checks passed
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Preview build of bdc2fa6: autobuild-preview-pr-1005-bdc2fa67

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