Repository navigation
AOT: array callbacks in stubs, loops by array kind, run-time accessors, proxies, string searches - #1045
Conversation
…s, proxies, string searches On #1042. 695 files, +59,955 -5,958: the rest of aot/ 557 files, +54,460 -5,602; aot/tests 111 files, +4,687 -247; outside aot/ 27 files, +808 -109. 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. - 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`. - `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. - `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.
22 files, +367 -117. - The build of a function of many statements that reckon with what calls give takes time that grows with their number, not with its cube: 400 of them take 0.8 G instructions where they took 126. Its stack frame holds a value that several ways hand on in one place: 800 such values had a frame over the limit, so the build stopped. - An object that a helper checks and that its `catch` names is one that other code sees, so its fields are read behind their stores. - `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 build with `--aot-harden=proof-checks` no longer stops where five or more functions out of a list are given a view and one of them has an arm for lists: nothing arrives at that arm. - `join()` and counts of a character are right for texts whose parts were cut from texts with wide characters. - A function of `ProxyObject` has a shorter name.
6 files, +138 -5. - A text that is matched several times in an async function is read again behind each `await`. The check of machine code that tests ask for knows joins of such reads.
There was a problem hiding this comment.
Beyond the inline findings, a few other candidates were examined and ruled out: the m => table[m] replace-callback keyed lookup in aot/runtime/AOTKeyedLookup.cpp (getter/Proxy/accessor cases fall back before the cached table is used), the row-sum loop over double arrays with holes in AOTCodeGeneratorRowLoops.cpp (hole-bearing shapes are still rejected before the vector path), the parseInt non-decimal radix path in AOTMathBuiltinEmitterNumbers.cpp (the inline number path is only taken for radix 10/absent), and the SourcesCompiledForMinimumSize.txt expansion (affects only compile options of the AOT compiler's own sources, not generated code).
Extended reasoning...
The change spans 701 files with roughly 60k insertions across the JSC AOT compiler, runtime, stubs, builtins and Yarr; two confirmed findings are posted inline, and this body only records the other concrete candidates that were investigated and did not hold up.
Findings marked 🟡 are optional suggestions and need no follow-up push.
There was a problem hiding this comment.
Warning
This review is incomplete: part of the automated analysis stopped early, so some of this change was not checked. The findings posted had already been confirmed.
Still open from earlier reviews (2):
- 🔴
Source/JavaScriptCore/aot/codegen/AOTCodeGeneratorRowLoops.cpp:1755—The AOT compiler can crash on a column-sum nest whose next-sum term reaches the running sum through a Narrowed or a bod… - Also unresolved: 1 minor or pre-existing.
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.
…w objects 14 files, +75 -26. - A loop that shifts an element, reads it plainly and stores to it stores the element as it is; it could be stored cut to an integer. - A store of `undefined` into a field ends what a loop has asked of the written type of that field. - A new object that is stored shows its optional fields to accessors of other new objects as they are. - Objects of a constructor function whose `prototype` is a primitive for some constructions have its own one later. - A callback of `forEach()` over listed names may also be called directly, with other names; the executable ended with an abort. - `concat()` takes the prototype of arrays for the list that it is. - The build of a remainder of a product of two `BigInt`s in a loop whose turns are laid out no longer stops. - `JSON.parse()` tests the end of its text before it compares a repeated part. - A debug build with assertions compiles `AOTEffects.cpp` again: the rows of its table are found by a hash, which takes 737,901 of the 1,048,576 steps that clang allows a constant; the search took 1,074,534. - `AOTLinkLayouts.cpp` includes the header of `JSFinalObject`; on Windows arm64 no other file of its unified source did.
|
Preview build of 78430a3: |
There was a problem hiding this comment.
Beyond the inline finding, I also checked the new ReplacerByKeyedLookup path in Source/JavaScriptCore/runtime/StringPrototypeInlines.h for a stale StringImpl pointer in the recent-replacement cache, and for getters or Proxy traps running more than once per match via AOTKeyedLookup.cpp. Both are ruled out: operationAOTGetByValGeneric is a leaf operation that never runs user code (it returns empty, and the callback is then called), and findReplacement clears the cache on every call path.
Extended reasoning...
The candidate issues in the keyed-lookup replace fast path were ruled out from the code: KeyedLookup::tryGetFromObject only uses fastGetOwnProperty and the noexcept leaf operation operationAOTGetByValGeneric, so no getter or Proxy trap runs during a lookup, and every path that calls the user function resets m_recent, so a cached StringImpl pointer cannot outlive code that could free it.
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.
…ths walked once more 21 files, +158 -57. - A name that a list gave and that was deleted since is `undefined` where a loop copies it; the executable could end with an abort. - A private field that is written as a number and that a loop stores as `null` no longer ends the executable with an abort where the program holds an `eval()`. - What a loop has asked of the written types of fields has a heap of its own in the schema: a store of `undefined` or `null`, in a call too, ends that and no more, so a constructor whose copy fails a guard is walked in line once more again. - `replace()` with a function that looks its match up makes the table of recent answers when there is an answer to remember, and clears the entries that were written. It cleared 64 KB behind each call of the function. - An `eval()` in a static block that stores a static field no longer ends the executable with an abort. - Two IR tests name no built-in of Bun.
There was a problem hiding this comment.
I reviewed the latest push (c2ed1b2) and didn't find any new bugs; since this is still a ~60k-line change across the AOT compiler, runtime and stubs, a human look remains worthwhile.
What was reviewed:
- The ReplacerByKeyedLookup rework in Source/JavaScriptCore/runtime/StringPrototypeInlines.h: the recent-replacement table is now sized from the match count on the first remembered answer and only written entries are cleared after a call; long texts are ref'd in remember() and deref'd in clear() and the destructor.
- Checked whether a lookup table with a getter or a Proxy could return a stale cached replacement, or run user code fewer times than the base — KeyedLookup::tryGetFromObject goes through the leaf readByKey, which answers nothing for any read that needs a slow path, so the callback is called and no user code runs inside a lookup.
- Spot-checked the lookup/call balance logic: skipping a lookup only means the real callback is called, which is always the conservative choice.
Extended reasoning...
The diff spans 707 files with about 60k insertions, adding and reworking the JavaScriptCore AOT compiler (facts, codegen, machine, image), its runtime and stubs, plus YARR changes. The latest commit (c2ed1b2) is small (21 files) and reworks the keyed-lookup string replacer that an earlier inline comment flagged for a 64KB fill per callback call, along with several AOT walk fixes. No auth, crypto or injection surface is touched, but the code is a native JIT-adjacent compiler and runtime where memory-safety errors are the main risk. The hunt ran dry with no new findings, and both candidate issues on the rewritten replacer were ruled out from the code, but the sheer size and complexity of the change rule out approving without a human reviewer.
…exceptions 4 files, +49 -18. - A loop over rows that only tests whether an element is there, or tests it and adds others up, leaves where the element is missing. - Where a mock ends, the exception scope also covers what puts files out of the cache, so builds that check exception scopes no longer stop there. - The allocator clears what takes a value in a plain loop. On Windows std::replace() over pointers needs a vectorized function of the standard library. - The storage of a list is asked in front of a loop wherever its elements are read there.
There was a problem hiding this comment.
I re-ran the review on the latest two commits and did not find any new bugs; given the size of this change (700+ files across the AOT compiler, runtime, stubs and Yarr), a human look is still worthwhile.
What was reviewed this run:
- The new keyed-lookup replace path (
AOTKeyedLookup.cpp/StringPrototypeInlines.hReplacerByKeyedLookup): checked whether a Proxy trap or getter on the lookup table could fire twice per match (tryGetOwnbails to the generic get only when the fast own-property read misses, so one trap per lookup) and whether the recent-replacement cache could skip a trap for repeated match text (cache entries are only written for string results of successful lookups and are cleared on every callback call, so each match that needs a call still gets one). - Replacement cache invalidation now clears only the places written since the last call (
m_usedPlaces) rather than the whole table.
Extended reasoning...
The diff spans 707 files with roughly 60k insertions, covering the AOT compiler (codegen, facts, machine, plan), its runtime and stubs, plus Yarr and StringPrototype changes; the latest two commits add keyed-lookup replace callbacks, exception checks for ended mocks, and element-test loops. It touches no auth or credential surface, but JSON parsing, regexp and string replacement are memory-safety-sensitive code paths generated by a JIT-adjacent compiler. The hunt ran dry this time with no findings on the new commits, and the two candidates about double or skipped trap invocation in the replace lookup path were ruled out by reading the code. The sheer scope and the earlier inline threads that were closed only by this bot's own session, not by an independent reviewer, are what keep this at defer rather than approve.
… now [skip size check] Merges main. Beside it and the pin 29 files, +543 -126. Pins the preview build `autobuild-preview-pr-1045-8f4d0f28`. - A member of an `enum`, or of `process.env` with `--minify-syntax`, under a key that a call passes to a function that another one returns is read when the program runs. - Nine findings of the Rust lints are gone. - Programs of fixes in oven-sh/WebKit#1045: names that were deleted, fields that calls clear, values of no type that are stored twice, static fields that evaluated texts store, loops that only test an element. - Tests of the engine say what is built now. `// STATISTIC on x64:` asks for a count on that processor alone; two counts that x64 alone makes are asked so. - The test of removed code knows what an executable says that was not trimmed, the test of deep evaluations nests fewer levels under ASan, and the test of numbers in frames makes its first link below them.
…eration - Tests of own names above a property access are looked up in a table of the function, not along all blocks above. - The class under construction of a field initializer is listed once for the program, and is not asked for where no super() call may answer with an older object. - The uses of a loop's counter are followed, where all operations of the loop were read for each counter. - What an object is expected to be by the names that a loop reads is asked of the cheap facts first. - Small functions of code generation, five of them in assembler/, are always inlined: builds of the engine that optimize for size called them by the million. The effects of a run-time operation are found once a call. - The names of a literal that Object.assign() stores one by one count among the strings that a program can list as keys, as the names of other literals do. - The values of such a literal, where there are many, are read from the literal. They stayed in the frame across a call behind them, and a deep recursion ran out of stack.
…me keys - A function in which over 4,096 values are alive at once keeps one callee-saved register, which holds the stack pointer plus a multiple of 16 or 32 KB. An access to a word of the frame out of reach of the stack pointer took two instructions each time, or three; it takes one off that register. The register is set before the first such access of a block where the ways into the block leave different values in it, and again behind what may have written it and at a landing pad. Functions with fewer values alive at once, and all functions on x64, are as before. - A store or a read under a key that is known at run time alone was said to write or read the fields that a literal or class lists. Fields that the program adds later count too: a read by name behind such a store could have the value from in front of the loop. - The stores of a loop's carried value that stand behind an unrolled turn are generated in the blocks they belong to. Where a turn has a rare arm, the build stopped. - The layouts of a name are listed in one pass, and a layout under construction is asked for once a function. Four small functions are always inlined.
There was a problem hiding this comment.
I reviewed this PR through 8c5fe16 and didn't find any bugs; because it is a 700+-file change adding an AOT compiler front end, register allocator, machine encoder and runtime, a human look would still be worthwhile.
What was reviewed:
- The newest commit's arm64 far-word base register (AOTMachineEncoder.cpp, addressOffBaseOfFarWords / settleBaseOfFarWordsAtHead): the base offset is dropped at landing pads and after any patch whose clobber mask covers the kept register, and only single-entry rare regions with no out-of-reach spill access skip re-settling it.
- The keyed-lookup replacement cache in StringPrototypeInlines.h (findReplacement / remember): entries are cleared after every callback call and keyed on the atomized match impl, so a cached answer is reused only for an identical repeated match; a Proxy or accessor-backed lookup table with a side-effecting get would see fewer reads than the callback path, which is inherent to the cache rather than a defect.
- AOT::KeyedLookup::tryGetFromObject: falls back to the generic get and rejects object-valued answers, so getters and Proxies are not bypassed.
Extended reasoning...
The diff adds roughly 61k lines across 723 files: the AOT compiler (facts, link, plan, codegen, machine allocator and encoder), its runtime (JSON parse/write, property caches, modules, string and regexp operations), builtins in TypeScript, and edits to shared JSC runtime headers such as StringPrototypeInlines.h and JSString.h. It touches no auth or credential surface, but it generates machine code and parses JSON in place over JSString buffers, which is memory-safety-sensitive. The bug hunt ran dry on this push and the one candidate it examined (lookup-table get traps running once per distinct match) is a consequence of the new replacement cache's design rather than a defect. The size and depth of the change, with no build or test run performed by this review, are what decide defer over approve.
…sors, counts for two loops [skip size check] Beside the pin 15 files, +267 -16. Pins the preview build `autobuild-preview-pr-1045-8c5fe16d`. - Programs of fixes in oven-sh/WebKit#1045: a field that a program adds behind a literal is read by name behind a store under a key that is known at run time alone; a number that a loop carries is stored behind the turns that are laid out, beside another arm. - CI runs three of the files that start test runs at once, and each of their tests starts two runs. The files count their runs together, so that not more runs stand beside one another than the machine has processors. - Two loops whose twins got cheaper than them are held to a count of instructions: a static field that is written to 8.5, a key that a helper makes to 240, on arm64 to 275. A test that names don't decide how a function is compiled asks for exactly two bounds in front of its loop. Five tests ask for counts again that they had given up. - The test of errors below many evaluations imports a thousand modules under ASan and four thousand elsewhere: its plain run met the five seconds that a test of `bun test` has.
… nest - A generator is not walked in place of a loop that closes it where an iteration may store the `return` of its prototype. The executable ended with an internal error. - A string that the copies of a nest of loops share is read inside the loop that takes it. - A fix in a cache of the runtime.
Pins oven-sh/WebKit at `de043228c294c72404a687634e1943f549f39048`, where oven-sh/WebKit#1045 is merged. throw-below-many-evaluations: the test loads its modules outside of its timed body.
… awaiting files, known strings (#48771) 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#1045, as `de043228c294c72404a687634e1943f549f39048`. This follows #48714. 1,718 files, +70,470 -2,660: test 1,466 files, +55,460 -853; src 250 files, +15,006 -1,803; docs 1 file, +3 -3; scripts 1 file, +1 -1. [skip size check], as in 607519a. Tests - CI compiles a stored program with `--aot`, runs it and compares it with `bun run`; a stored test run likewise, with `bun test --aot` and `bun test`. If you don't use `--aot` - What oven-sh/WebKit#1045 lists: the length of `[, ...list]`, and the message of replaceAll() on null or undefined. - `click(selector)` of `Bun.WebView` could click an element that was about to move. It looks once a frame now, and an element with a pending animation counts as moving. Wrong on main, fixed - Where an entry point imports a file only for its effects, the file's package says `"sideEffects": false`, and the file reads a member that an index of `export *` takes off a built-in module and passes the namespace on, the build stopped, or the member was undefined. - Where a closure captures an alias of `globalThis`, beside a property `get`, `has` or `apply` of an unknown object, the build could stop. - Where a `catch` behind a top-level `await`, or an operator, sets a path, the build did not warn that the program may read another file. - Where the value of a destructuring assignment stores to a field that the pattern reads, or an attribute of an element to one that its `key` reads (JSX's automatic runtime), the field was read as it was before. - With `--minify-syntax`, a function that another one returns and that reads `process.env[key]` gave the value of the build for the key `"NODE_ENV"`. A member of an `enum` under a key that a call passes to such a function was read as it was written, though the program stored into it. Executables and builds - Classes: parents that are parameters, members, results of calls or of `require()` are followed, also through the helpers of Babel, TypeScript and swc. Functions with prototypes assigned later, and decorated classes that are exported, are classes. - Objects: prototypes written into literals, `Object.create()` with a literal, and accessors that a helper defines are read from the source. - Bundles: universal wrappers (UMD), standalone output of Browserify, and exports that are getters are read directly. Requests beside `eval()` and `with` in a bundle are kept. - Strings the build knows: scripts that are joined from constants, names that such code declares, and calls of constants are evaluated when the program is built. - Files: an embedded file that a child process writes is read from the disk. A library that `dlopen()` opens stays the one that was embedded. - Size: an executable leaves out the test runner where nothing in it can reach `Bun.jest`, `bun:test` or `node:test`. With `--trim` it leaves out what only mocks enter, too. `bun test --aot` - The original of a mocked file outlives later runs of the file, and a mock visits only the modules that it concerns. Known issues - #48677 lists what main has; what it says of typed arrays in a file's variable, of the defaults of parameters and of products under `--aot-harden=proof-checks` is fixed since or here. Of the rest, main has too: - Executables, silent: Where a method of a constructor function gives many names to a few of its objects, all of them take the larger size (at most 128 bytes an object). - Executables away from their sources, silent: A route of `Bun.serve()` that is a `Bun.file()` of a file embedded by `--asset` or an import keeps the build's bytes when the program writes or removes that file later by a `__dirname` path, and answers a `Range` request with the whole file (status 200). - Builds, loud: The build of a program whose object literals have more than about 65,000 different numbers as fields stops. - Executables, loud: A method of lists called on a typed array whose prototype was set to that of a class that extends `Array` aborts where nothing else uses that method. - Executables, loud: A store to `process.env` behind `Object.setPrototypeOf(process.env, {})` throws a `RangeError`. - Executables, silent: A CommonJS file whose code threw and that is asked for again by `require.bind()`, `eval()`, `new Function()` or `node:vm` gives its first error instead of running again. - Builds, loud: Under `--aot-harden=proof-checks`, the build of some loops over lists that may be buffers stops; with default flags the answer is right.
main has #1045 (AOT). One file conflicts: aot/runtime/AOTTestRunImportTurns.cpp. #1045 keeps each import() call whose text comes in a later turn in a heap object of its own (BatchedFetch, in the new BatchedFetches) and fills the fields one by one. This side had added the async context of the call to the old initializer list. Resolved with main's code. holdTextOfCall() stores the async context in the new object, for a call of the program. putCallsThatWaitApartInLine() moves it into the QueuedFetch, as before. makeCallAgain() is unchanged: it makes the call under the stored context. A fetch that main now adds for a static import of such a call (fetchImports()) is not a call and carries no context: the call that waits for it is made again under its own. main removes the two jobs that made such calls again (runJobOfRound(), runJobThatMakesCallsAgain()). No code of this change was in them. main adds no job of the module loader and no loadModule() call. de04322 is #1045 as merged. Bun's main pins it (oven-sh/bun d0f4fdd65f).
main has #48771: its pin is de043228c2, which is oven-sh/WebKit#1045 as merged. WEBKIT_VERSION is now the preview build of the head of oven-sh/WebKit#941 (4ee8e65bd8), which is de043228c2 with the change. Conflicts: the pin, and the end of test/parallel-allowlist.json (main's list, then the one test file of this change).
…, generators that a loop closes (#1047) 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 a pull request that pins this one. This follows #1045. 50 files, +676 -572, all in Source/JavaScriptCore/aot/. The text of functions - An executable stores the source text of its functions for Function.prototype.toString(), and the source that error messages quote, as it is, where it stored both in compressed blocks. The text is read in place. The compressor's hooks between JavaScriptCore and Bun are gone. - An executable is larger by what the compression saved: about 1.5% over 119 npm packages, and 3.4 MB for the TypeScript compiler. With --no-compile-function-source nothing changes. Reads through super, and generators - `super.name` in a loop, where the parent of the home object may be a module namespace, asks the tables of the program first. It called the run time for each read after #1045. - A loop that closes a generator is walked in place again in more places: the check for a store of the `return` of its prototype looks into the functions that an iteration calls. Fixed - Some builds no longer stop: under --aot-harden=proof-checks, loops with an await and loops that store into lists that may be views; nests of loops over the rows of a table where a condition joins two values that nothing reads; a nest that swaps elements with another loop behind it; loops that read and write an element under a constant key that the compiler holds as a double; a CommonJS file that defines module.exports by a getter; a loop that reads an element of a list in a field of an object of the file, compares it with a text and stores elsewhere. - A loop over a generator that is left early aborted the program where a call in the loop runs a getter, a setter, a proxy, an iterator or an operator that stores the `return` of the generator's prototype under a computed key. - In a loop over rows that came out of JSON, what a default does beside its number (`row.extra ?? (calls++, 0)`) did not run in an executable. - `--aot-stored-strings` read an executable of an earlier Bun as one of its own. The format of the image is 5. - `bun test --aot`: while the factory of a second mock over a loaded first one waits, imports keep the first until it settles; a load in flight gets the mock that it has fetched; a file that runs again behind the end of its own mock sees the mocks that came since over what it imports; and a run no longer aborts where a mock ends while the body of its file runs, behind a require() that could not wait for the mock's factory.
The JavaScriptCore side of a round of work on Bun's ahead-of-time compiler (
bun build --compile --aotandbun test --aot, both experimental). Bun's side is a pull request that pins this one's preview. This follows #1042.Merge order
This merges first; then Bun's pull request pins the merged commit and runs CI once more.
Wrong on main, fixed
returnon the generator's prototype under a computed namereturn()Reflect.set()of a class field that was deleted, where the prototype has a read-only property of that nametrueand stores nothingbun test --aot: a test file mocks a CommonJS file and also a file that it requiresx % ybeside(x / y) | 0, wherexis-2147483648andyis-1-4294967296instead of-0catchnames the generatorprototypeReflect.get()orgetOwnPropertyDescriptor()is handed on, bound or inherited, and asked for a built-in by a name that is made while the program runsundefined, and the class has a name that its constructor does not store0forundefinedprototypeof a constructor function is a primitive for some constructionsObject.prototypeinstead of its own oneBigIntwith itself under a modulus out of a list ((x * x) % m)class Heir extends Back { x = 77 })Bun.inspect()of an object of a base class with a symbol-keyed methodkey in listwhere the key is a list, and the prototype of the list is a listthisand aneval()behindsuper()--aot-harden=proof-checks: a CommonJS file with a counter that a function steps in a loop over two kinds of listsfor..inloop copies an object of many namesnull, in a program that holds aneval()If you don't use
--aot[, ...list]with an emptylisthas the length that its holes give it:[, ...[]].lengthis 1 (0 on main).replaceAll()onnullorundefinedsays the same in optimized code as before it is optimized.What's in it
723 files, +61,098 −6,183 against main. Most of it is the compiler's own directory:
aot/walk: the main passaot/facts: the linkaot/codegen,stubs,machine: code generationaot/runtime,builtins,objectaot/testsaot/aot/Outside
aot/Only compiled programs take these paths; plain Bun runs a few checks more and gives the same answers. Rows marked Plain Bun too change an answer.
assembler/AssemblerBuffer.h,assembler/X86Assembler.hand 1 morebytecompiler/NodesCodegen.cpp[, ...list]: the length where the list is empty. Plain Bun toodfg/DFGOperations.cppreplaceAll()on null or undefined in optimized code. Plain Bun tooruntime/JSString.cppruntime/StringPrototypeInlines.h,runtime/StringReplaceCache.hand 2 morereplace()with tables of replacements, and the caches ofreplace()andsplit()runtime/RegExp.h,runtime/RegExpCache.cppand 1 moreruntime/ProxyObject.cpp,runtime/ProxyObject.hruntime/GetterSetter.hruntime/DatePrototype.cpp,runtime/DatePrototype.hruntime/JSOrderedHashTable.h,runtime/WeakMapImpl.hruntime/Structure.cpp,runtime/VM.cppwasm/WasmCallingConvention.h,wasm/WasmOperations.cppand 2 moreyarr/YarrFlatProgram.h,yarr/YarrFlatProgramBuilder.cppand 2 moreChanges
Arrays and loops
map(),filter(),some(),find(),reduce(),sort()and others) that read fields, compare, add or multiply run in stubs, also for arrays the build knows nothing about.Objects and classes
Object.create(),__proto__) are constructed from templates.Reflect.construct()runs in a stub. Aget()orset()afterhas()uses the entry that was found.Calls
f(...list),new C(...list)andpush(...list)don't create an array for the arguments. Rest parameters that are only passed on aren't created.next()is stepped in place where the generator is a local variable.Strings, regular expressions, JSON
switchover strings goes through a table. Numbers are converted to strings and back in place.JSON.stringify()remembers the order of the keys of a structure, andJSON.parse()continues in its lexer behind a value.Code from strings
Build
Known issues
What differs from
bun runandbun testis listed in Bun's pull request.Tests
IR tests and native tests are in
aot/tests; stored programs are in Bun's pull request. CI's run of this pull request is the first of this tree.