Remove dead code from the class generator: the unreachable DOMJIT paths - #43840
Conversation
|
Status: open, waiting for CI and review. How to check the change:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: oven-sh/bun/.coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (6)
💤 Files with no reviewable changes (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. WalkthroughThe ChangesDOMJIT removal
Suggested reviewers: Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is established; the change is mergeable after normal checks. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
Problem
src/codegen/generate-classes.tsstill has the DOMJIT emitter (C++ signatures,WithoutTypeCheckswrappers, result-type asserts, Rust thunks). None of it can run:define()inclass-definitions.tshas setDOMJIT = undefinedon each field since disable most DOMJIT #14005 (2024-09), and all 31*.classes.tsfiles go throughdefine().*_without_type_checksfast path, and Remove dead code from webcore DOMJIT/EventPath/EventContext and misc C++ bindings #36756 and Remove dead code from webcore events/abort C++, ZigGeneratedCode DOMJIT, bun_alloc, libarchive, http #36903 removed the C++ leftovers.DOMJIT:option in a.classes.tsfile does nothing. Five exist.Fix
define(), the five ignored blocks, and the stale notes next to them: 6 files, 273 lines removed.#if BUN_DEBUG/#endifpairs inZigGeneratedClasses.hand three DOMJIT-only#includes inZigGeneratedClasses.cpp.generated_classes.rsis byte-identical.bun bd,tsc -p src, and the tests in the Notes.Background
Buffer.alloc,performance.now,bun:ffi) do not use this generator. They stay.Downsides
.cpp,.hand.rsdiffer only as Fix says.Notes
Removed
generate-classes.ts:DOMJITName,argTypeName,DOMJITType,DOMJITFunctionDeclaration,DOMJITFunctionDefinition,domJITTypeCheckFields,RustDOMJITArgType. Also theDOMJITbranches inzigExportName,propRow,renderDecls, theexpectedResultTypeasserts in the host-function wrapper, both Rust thunk loops, and theDOMJITAbstractHeap.h,FrameTracers.h,DFGAbstractHeap.hincludes of the generated prologue. The destructures that namedDOMJITalso lose the unusedcacheandvaluebindings.class-definitions.ts: theDOMJIT?:option type and the two.map()calls indefine()that erased it.Crypto.randomUUID,Crypto.timingSafeEqual(crypto.classes.ts),ServerWebSocket.publishText,publishBinary(server.classes.ts),TextDecoder.decode(encoding.classes.ts).// DOMJIT: {blocks with their crash notes onsendText,sendBinary(2023) andgetRandomValues(Disable DOMJIT for crypto.getRandomValues() #13470, 2024-08), and three orphan "DOMJIT fast path" comments insrc/runtime/webcore/Crypto.rswhose functions Remove ~39k lines of dead Rust across the workspace #35002 deleted.Self-review, and what changed because of it
Crypto.rs, the commented-out blocks) are folded in.builtins.d.tslines were dropped too:src/codegen/replacements.tsdefines$ImportKindLabelToId, so that declaration is live.History
getRandomValues. disable most DOMJIT #14005 (2024-09) added the strip indefine()as the repair for the try/catch not catching an error + Segmentation fault when executingTextDecoder.decode#14001 segfault. DOMJIT wrappers: route returns through OPERATION_RETURN #35224 found the cause (the wrappers returned{ result }with a null exception slot) and tried to repair the generated wrappers. A stale-PR cleanup closed it with no maintainer comment. Remove ~39k lines of dead Rust across the workspace #35002 deleted the Rust fast paths, so the option cannot come back without new native code.Kept on purpose
DomCallpath forbun:ffi(src/jsc/host_fn.rs,src/runtime/ffi), the C++ DOMJIT signatures inJSBuffer.cpp,JSPerformance.cpp,NodeVM.cpp,JSSQLStatement.cpp, andtest/js/bun/jsc/domjit.test.ts.Tests (debug build)
test/js/web/encoding/text-decoder.test.js127 pass,test/js/web/web-globals.test.js23 pass,test/js/bun/util/randomUUIDv5.test.ts40 pass,test/js/bun/websocket/websocket-server.test.ts -t sendBinary5 pass.websocket-server.test.ts -t "publish|send": 44 pass, 4 time out near 19 s under debug+ASAN. A debug binary built from main fails the same 4.test/js/bun/jsc/domjit.test.ts: 40 pass, 10 time out at the 100k-iteration sizes. A debug binary built from main gives the same 40/10.The rest of this sweep
-Wl,--gc-sections, then the DWARF line table of the result: 2,290 of 31,118 Rustfns have no live line. Aftercargo checkon six targets only threepub fns had no caller anywhere. The 96 trait impls with no caller are the ones Remove dead code: 49 trait impls nothing uses, across 12 crates #43664 kept on purpose.-fsyntax-only -Wunused-function -Wunused-template -Wunused-member-function -Wunused-macrosover bun's 177 C/C++ translation units (the build passes-Wno-unused-function): ten hits. Open PRs delete them, or an#ifuses them.no-unused-varsoversrc/js,src/codegen,scripts,packages. cargo'sunused_dependencieslint over four targets. A scan for commented-out blocks (62 lines in the repo). Nothing new that is certain.Bun__napi_get_version(Remove dead code from the JSC bindings, headers.h, the console builtin, and bun_jsc #40232), two unused generator locals (Remove dead code from bun_core, the JSC bindings, the debugger, and 24 other crates #41385).Verified and held for the next run (branch
robobun/9a0817f5/dead-code-scopes-fields, 25 files, 81 lines removed)declare_scope!scopes that nothing logs to:JSC,STR,Bundleandscan_counter(outer pair),Store,hot_reloader,CLI,LibUVBackend,ResolveInfoRequest,GetHostByAddrInfoRequest,CAresNameInfo,GetNameInfoRequest,CAresReverse,CAresLookup,quic_session,PathWatcherManager,S3Client,S3Stat,AWS,uws(uws_sys/socket.rs). rustc does not lint an item that another crate's macro expands.Runtime::Features.jsx_optimization_inlinewith the localcan_be_inlined,DebugOptions.output_file,ArchiveIterator.filter,PackageManager.total_scripts,CommandLineArguments.lockfile,ArgumentsSlice::_vm. Alsostruct_Channeldataand two empty modules innapi_body.rs.rust:check-all(12 targets), release and--cfg bun_debug --cfg bun_asanchecks on linux, windows and darwin, andcargo check --testsbefore the trim below. The trimmed commit passescargo checkon linux.BundleOptions.code_coverage(bun test: count code that runs in a Worker under --coverage #43283 reads it), scopeModuleLoader(Restore smol-gated retain-with-limit reset for the module loader transpile arena #31855), scopePROCESS(Remove libuv on Windows #42819, watch: reap child processes inherited across a --watch restart #39222),impl Clone for JsPosterand its vtable slot (event_loop: replace JsPoster's hand-rolled vtable with Arc<dyn JsPost> #37518 rewrites the vtable).Follow-up candidates, not verified dead
Parser Options.preserve_unused_imports_tsis nevertrue. tsconfigimportsNotUsedAsValuesis parsed intopreserve_imports_not_used_as_valuesbut never reaches the parser, in the released binary too. This looks like a missing feature.completions/bun-cli.json(4,513 lines) andmisctools/generate-cli-completions.ts(728 lines): nothing in the repo reads the JSON, but feature PRs still edit it by hand.bench/snippets/runner-entrypoint.js(244 lines): no reference, first line says "this isn't done yet", last real change 2023-05.impl_timer_owner!accessors have no caller becausedispatch.rsrecovers the owner with its ownowner!macro. Which mechanism stays is a design call.mordant-baseline.tomlstill counts about 170unused_pubfindings (sys/lib.rs56,libuv_sys/libuv.rs41,errno/windows_errno.rs31).bun run rust:mordantnames them.