From 5c32d392ecbd701db19e356fed71445bc6a3c1e3 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 04:12:51 +0000 Subject: [PATCH 1/7] Remove dead code from C++ bindings, ErrorCode, bun_core C++ bindings: - JSX509CertificateConstructor.{h,cpp}: empty namespace blocks only; the real JSX509CertificateConstructor class is defined inline in JSX509Certificate.cpp - BunHeapProfiler.h: only included by its own .cpp; generateHeapProfile is now file-static - Bun::ERR::{CRYPTO_TIMING_SAFE_EQUAL_LENGTH, KEY_GENERATION_JOB_FAILED, CLOSED_MESSAGE_PORT, CRYPTO_INVALID_KEYTYPE (no-message overload)}: throw wrappers with zero C++ callers (the corresponding ErrorCode enum values remain live and are reached from Rust/JS) - JSDOMWrapperCache.h deprecatedGetDOMStructure / getOrCreateWrapper: forward-declared templates with zero instantiations - {ModuleLoader,JSNextTickQueue,JSMockFunction}.h createWithInitialValues: declared, never defined, never called - AsymmetricKeyValue.h AsymmetricKeyValue(EVP_PKEY*, bool): declared, never defined, never called - JSBufferList getBufferList: zero callers; ZigGlobalObject::JSBufferList() is used directly Rust: - bun_core::container_of_const: zero callers (the *mut-out container_of covers every call site); re-export in bun_ptr dropped - bun_core::literal! macro: zero invocations; callers use byte literals or w!() directly - http::ssl_config From> for SharedPtr: Arc is never constructed outside ssl_config.rs; both construction sites use SharedPtr::new or the tuple constructor Verified: rg -w across src/ and build/debug/codegen/ shows each removed symbol is referenced only at its own definition. bun bd passes; bun run rust:check-all passes all 10 target triples. --- src/bun_core/lib.rs | 7 -- src/bun_core/string/immutable/unicode.rs | 12 --- src/bun_core/string/mod.rs | 7 +- src/http/ssl_config.rs | 7 -- src/jsc/bindings/AsymmetricKeyValue.h | 1 - src/jsc/bindings/BunHeapProfiler.cpp | 3 +- src/jsc/bindings/BunHeapProfiler.h | 17 ---- src/jsc/bindings/ErrorCode.cpp | 31 -------- src/jsc/bindings/ErrorCode.h | 4 - src/jsc/bindings/JSBufferList.cpp | 5 -- src/jsc/bindings/JSBufferList.h | 2 - src/jsc/bindings/JSDOMWrapperCache.h | 9 --- src/jsc/bindings/JSMockFunction.h | 1 - src/jsc/bindings/JSNextTickQueue.h | 1 - .../bindings/JSX509CertificateConstructor.cpp | 11 --- .../bindings/JSX509CertificateConstructor.h | 15 ---- src/jsc/bindings/ModuleLoader.h | 1 - src/ptr/lib.rs | 3 +- ...ead-symbols-errorcode-x509-buncore.test.ts | 79 +++++++++++++++++++ 19 files changed, 84 insertions(+), 132 deletions(-) delete mode 100644 src/jsc/bindings/BunHeapProfiler.h delete mode 100644 src/jsc/bindings/JSX509CertificateConstructor.cpp delete mode 100644 src/jsc/bindings/JSX509CertificateConstructor.h create mode 100644 test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts diff --git a/src/bun_core/lib.rs b/src/bun_core/lib.rs index 1224fcfd0d42..cb1dad46de63 100644 --- a/src/bun_core/lib.rs +++ b/src/bun_core/lib.rs @@ -662,13 +662,6 @@ pub const unsafe fn container_of(field: *const F, offset: usize) -> *mut P unsafe { field.byte_sub(offset).cast::

().cast_mut() } } -/// `*const`-out variant of [`container_of`]. Same safety contract. -#[inline(always)] -pub const unsafe fn container_of_const(field: *const F, offset: usize) -> *const P { - // SAFETY: per fn contract. - unsafe { field.byte_sub(offset).cast::

() } -} - /// Recover a typed `&mut T` from a C-callback's opaque user-data pointer. /// /// This is the canonical spelling for the ubiquitous trampoline pattern where diff --git a/src/bun_core/string/immutable/unicode.rs b/src/bun_core/string/immutable/unicode.rs index e591bab46055..6901ec9fceb8 100644 --- a/src/bun_core/string/immutable/unicode.rs +++ b/src/bun_core/string/immutable/unicode.rs @@ -906,18 +906,6 @@ pub fn utf16_codepoint(input: &[u16]) -> UTF16Replacement { } } -/// `b"..."` for u8, `$crate::w!("...")` for u16. -/// New callers should use byte/wide literals directly. -#[macro_export] -macro_rules! literal { - (u8, $s:literal) => { - concat!($s, "\0").as_bytes() - }; - (u16, $s:literal) => { - $crate::w!($s) - }; -} - pub(super) use crate::strings_impl::push_codepoint_utf16; // `unreachable_pub`: these are re-exported externally via the parent's diff --git a/src/bun_core/string/mod.rs b/src/bun_core/string/mod.rs index e9e248ab711c..ef7942e5ef8e 100644 --- a/src/bun_core/string/mod.rs +++ b/src/bun_core/string/mod.rs @@ -9,10 +9,9 @@ //! Merged into `bun_core` to break the `bun_core ↔ bun_string` dep edge; //! the `bun_string` crate is now a thin re-export shim over this module. -// `#[macro_export]` macros defined in submodules (`w!`, `literal!`) land at -// the *crate* root (`bun_core::`). -// Re-export them here so `crate::string::w` / `bun_core::w` paths resolve. -pub use crate::{literal, w}; +// `#[macro_export]` macros defined in submodules (`w!`) land at the *crate* +// root (`bun_core::`). Re-export here so `crate::string::w` resolves. +pub use crate::w; #[path = "escapeRegExp.rs"] pub mod escape_reg_exp; diff --git a/src/http/ssl_config.rs b/src/http/ssl_config.rs index 3a6c9b56eda2..c6bea951364a 100644 --- a/src/http/ssl_config.rs +++ b/src/http/ssl_config.rs @@ -92,13 +92,6 @@ impl core::ops::Deref for SharedPtr { } } -impl From> for SharedPtr { - #[inline] - fn from(a: Arc) -> Self { - Self(a) - } -} - impl SSLConfig { pub(crate) const ZERO: SSLConfig = SSLConfig { server_name: core::ptr::null(), diff --git a/src/jsc/bindings/AsymmetricKeyValue.h b/src/jsc/bindings/AsymmetricKeyValue.h index 5869721c52d9..269a5999fa9f 100644 --- a/src/jsc/bindings/AsymmetricKeyValue.h +++ b/src/jsc/bindings/AsymmetricKeyValue.h @@ -18,7 +18,6 @@ class AsymmetricKeyValue { bool operator!() const { return !key; } ~AsymmetricKeyValue(); - AsymmetricKeyValue(EVP_PKEY* key, bool owned); AsymmetricKeyValue(CryptoKey&); }; diff --git a/src/jsc/bindings/BunHeapProfiler.cpp b/src/jsc/bindings/BunHeapProfiler.cpp index 2eadd8070e8d..656230dc540a 100644 --- a/src/jsc/bindings/BunHeapProfiler.cpp +++ b/src/jsc/bindings/BunHeapProfiler.cpp @@ -1,5 +1,4 @@ #include "root.h" -#include "BunHeapProfiler.h" #include "headers-handwritten.h" #include #include @@ -111,7 +110,7 @@ static WTF::String formatBytes(size_t bytes) return sb.toString(); } -WTF::String generateHeapProfile(JSC::VM& vm) +static WTF::String generateHeapProfile(JSC::VM& vm) { vm.ensureHeapProfiler(); auto& heapProfiler = *vm.heapProfiler(); diff --git a/src/jsc/bindings/BunHeapProfiler.h b/src/jsc/bindings/BunHeapProfiler.h deleted file mode 100644 index cb3035b53470..000000000000 --- a/src/jsc/bindings/BunHeapProfiler.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "root.h" -#include - -namespace JSC { -class VM; -} - -namespace Bun { - -// Generate a Claude-friendly text-based heap profile -// This format is designed specifically for analysis by LLMs with grep/sed/awk tools -// The output is hierarchical but with clear section markers for easy navigation -WTF::String generateHeapProfile(JSC::VM& vm); - -} // namespace Bun diff --git a/src/jsc/bindings/ErrorCode.cpp b/src/jsc/bindings/ErrorCode.cpp index b9fc1144b82d..12684ed4ecdb 100644 --- a/src/jsc/bindings/ErrorCode.cpp +++ b/src/jsc/bindings/ErrorCode.cpp @@ -1299,14 +1299,6 @@ JSC::EncodedJSValue CRYPTO_INVALID_KEYTYPE(JSC::ThrowScope& throwScope, JSC::JSG return {}; } -JSC::EncodedJSValue CRYPTO_INVALID_KEYTYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject) -{ - auto message = "Invalid key type"_s; - throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_CRYPTO_INVALID_KEYTYPE, message)); - throwScope.release(); - return {}; -} - JSC::EncodedJSValue CRYPTO_UNKNOWN_CIPHER(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, const WTF::StringView& cipherName) { // Node dropped the cipher name from the message (exact-match asserted by @@ -1549,14 +1541,6 @@ JSC::EncodedJSValue CRYPTO_HASH_UPDATE_FAILED(JSC::ThrowScope& throwScope, JSC:: return {}; } -JSC::EncodedJSValue CRYPTO_TIMING_SAFE_EQUAL_LENGTH(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject) -{ - auto message = "Input buffers must have the same byte length"_s; - scope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH, message)); - scope.release(); - return {}; -} - JSC::EncodedJSValue CRYPTO_UNKNOWN_DH_GROUP(JSC::ThrowScope& scope, JSGlobalObject* globalObject) { auto message = "Unknown DH group"_s; @@ -1579,14 +1563,6 @@ JSC::EncodedJSValue MISSING_PASSPHRASE(JSC::ThrowScope& throwScope, JSC::JSGloba return {}; } -JSC::EncodedJSValue KEY_GENERATION_JOB_FAILED(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject) -{ - auto message = "Key generation job failed"_s; - throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_KEY_GENERATION_JOB_FAILED, message)); - throwScope.release(); - return {}; -} - JSC::EncodedJSValue INCOMPATIBLE_OPTION_PAIR(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, ASCIILiteral opt1, ASCIILiteral opt2) { WTF::StringBuilder builder; @@ -1630,13 +1606,6 @@ JSC::EncodedJSValue INVALID_MIME_SYNTAX(JSC::ThrowScope& scope, JSC::JSGlobalObj return {}; } -EncodedJSValue CLOSED_MESSAGE_PORT(ThrowScope& scope, JSGlobalObject* globalObject) -{ - scope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_CLOSED_MESSAGE_PORT, "Cannot send data on closed MessagePort"_s)); - scope.release(); - return {}; -} - JSC::EncodedJSValue INVALID_THIS(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, ASCIILiteral expectedType) { WTF::StringBuilder builder; diff --git a/src/jsc/bindings/ErrorCode.h b/src/jsc/bindings/ErrorCode.h index 61c87682caa6..850de5d68457 100644 --- a/src/jsc/bindings/ErrorCode.h +++ b/src/jsc/bindings/ErrorCode.h @@ -136,10 +136,8 @@ JSC::EncodedJSValue CRYPTO_INVALID_DIGEST(JSC::ThrowScope& throwScope, JSC::JSGl JSC::EncodedJSValue CRYPTO_HASH_FINALIZED(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject); JSC::EncodedJSValue CRYPTO_HASH_UPDATE_FAILED(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject); JSC::EncodedJSValue MISSING_PASSPHRASE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, WTF::ASCIILiteral message); -JSC::EncodedJSValue CRYPTO_TIMING_SAFE_EQUAL_LENGTH(JSC::ThrowScope&, JSC::JSGlobalObject*); JSC::EncodedJSValue CRYPTO_UNKNOWN_DH_GROUP(JSC::ThrowScope&, JSC::JSGlobalObject*); JSC::EncodedJSValue CRYPTO_INVALID_KEYTYPE(JSC::ThrowScope&, JSC::JSGlobalObject*, WTF::ASCIILiteral message); -JSC::EncodedJSValue CRYPTO_INVALID_KEYTYPE(JSC::ThrowScope&, JSC::JSGlobalObject*); JSC::EncodedJSValue CRYPTO_UNKNOWN_CIPHER(JSC::ThrowScope&, JSC::JSGlobalObject*, const WTF::StringView& cipherName); JSC::EncodedJSValue CRYPTO_INVALID_AUTH_TAG(JSC::ThrowScope&, JSC::JSGlobalObject*, const WTF::String& message); JSC::EncodedJSValue CRYPTO_INVALID_IV(JSC::ThrowScope&, JSC::JSGlobalObject*); @@ -149,11 +147,9 @@ JSC::EncodedJSValue CRYPTO_INVALID_KEYLEN(JSC::ThrowScope&, JSC::JSGlobalObject* JSC::EncodedJSValue CRYPTO_INVALID_STATE(JSC::ThrowScope&, JSC::JSGlobalObject*, WTF::ASCIILiteral message); JSC::EncodedJSValue CRYPTO_INVALID_MESSAGELEN(JSC::ThrowScope&, JSC::JSGlobalObject*); JSC::EncodedJSValue OSSL_EVP_INVALID_DIGEST(JSC::ThrowScope&, JSC::JSGlobalObject*); -JSC::EncodedJSValue KEY_GENERATION_JOB_FAILED(JSC::ThrowScope&, JSC::JSGlobalObject*); JSC::EncodedJSValue INCOMPATIBLE_OPTION_PAIR(JSC::ThrowScope&, JSC::JSGlobalObject*, ASCIILiteral opt1, ASCIILiteral opt2); JSC::EncodedJSValue MISSING_OPTION(JSC::ThrowScope&, JSC::JSGlobalObject*, ASCIILiteral message); JSC::EncodedJSValue INVALID_MIME_SYNTAX(JSC::ThrowScope&, JSC::JSGlobalObject*, const String& part, const String& input, int position); -JSC::EncodedJSValue CLOSED_MESSAGE_PORT(JSC::ThrowScope&, JSC::JSGlobalObject*); JSC::EncodedJSValue INVALID_THIS(JSC::ThrowScope& scope, JSC::JSGlobalObject* globalObject, ASCIILiteral expectedType); JSC::EncodedJSValue DLOPEN_DISABLED(JSC::ThrowScope&, JSC::JSGlobalObject*, ASCIILiteral message); diff --git a/src/jsc/bindings/JSBufferList.cpp b/src/jsc/bindings/JSBufferList.cpp index a7a3ed9ac90b..11cc614b7eb6 100644 --- a/src/jsc/bindings/JSBufferList.cpp +++ b/src/jsc/bindings/JSBufferList.cpp @@ -462,9 +462,4 @@ void JSBufferListConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* const ClassInfo JSBufferListConstructor::s_info = { "BufferList"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSBufferListConstructor) }; -JSValue getBufferList(Zig::GlobalObject* globalObject) -{ - return static_cast(globalObject)->JSBufferList(); -} - } // namespace Zig diff --git a/src/jsc/bindings/JSBufferList.h b/src/jsc/bindings/JSBufferList.h index 635312f270e9..1c8e89ff121a 100644 --- a/src/jsc/bindings/JSBufferList.h +++ b/src/jsc/bindings/JSBufferList.h @@ -168,6 +168,4 @@ class JSBufferListConstructor final : public JSC::InternalFunction { void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSBufferListPrototype* prototype); }; -JSValue getBufferList(Zig::GlobalObject* globalObject); - } diff --git a/src/jsc/bindings/JSDOMWrapperCache.h b/src/jsc/bindings/JSDOMWrapperCache.h index 9a49a7126fc6..5a887bfb261f 100644 --- a/src/jsc/bindings/JSDOMWrapperCache.h +++ b/src/jsc/bindings/JSDOMWrapperCache.h @@ -40,7 +40,6 @@ WEBCORE_EXPORT JSC::Structure* getCachedDOMStructure(const JSDOMGlobalObject&, c WEBCORE_EXPORT JSC::Structure* cacheDOMStructure(JSDOMGlobalObject&, JSC::Structure*, const JSC::ClassInfo*); template JSC::Structure* getDOMStructure(JSC::VM&, JSDOMGlobalObject&); -template JSC::Structure* deprecatedGetDOMStructure(JSC::JSGlobalObject*); template JSC::JSObject* getDOMPrototype(JSC::VM&, JSC::JSGlobalObject*); JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, JSC::ArrayBuffer*); @@ -58,8 +57,6 @@ bool clearInlineCachedWrapper(DOMWrapperWorld&, void*, JSDOMObject*); bool clearInlineCachedWrapper(DOMWrapperWorld&, ScriptWrappable*, JSDOMObject* wrapper); bool clearInlineCachedWrapper(DOMWrapperWorld&, JSC::ArrayBuffer*, JSC::JSArrayBuffer* wrapper); -template JSC::JSObject* getOrCreateWrapper(DOMWrapperWorld&, DOMClass&); - template JSC::JSObject* getCachedWrapper(DOMWrapperWorld&, DOMClass&); template inline JSC::JSObject* getCachedWrapper(DOMWrapperWorld& world, Ref& object) { return getCachedWrapper(world, object.get()); } template void cacheWrapper(DOMWrapperWorld&, DOMClass*, WrapperClass*); @@ -87,12 +84,6 @@ template inline JSC::Structure* getDOMStructure(JSC::VM& return cacheDOMStructure(globalObject, WrapperClass::createStructure(vm, &globalObject, WrapperClass::createPrototype(vm, globalObject)), WrapperClass::info()); } -template inline JSC::Structure* deprecatedGetDOMStructure(JSC::JSGlobalObject* lexicalGlobalObject) -{ - // FIXME: This function is wrong. It uses the wrong global object for creating the prototype structure. - return getDOMStructure(JSC::getVM(lexicalGlobalObject), *deprecatedGlobalObjectForPrototype(lexicalGlobalObject)); -} - template inline JSC::JSObject* getDOMPrototype(JSC::VM& vm, JSDOMGlobalObject& globalObject) { return asObject(getDOMStructure(vm, globalObject)->storedPrototype()); diff --git a/src/jsc/bindings/JSMockFunction.h b/src/jsc/bindings/JSMockFunction.h index a22b8d960dc9..1200e289e2c5 100644 --- a/src/jsc/bindings/JSMockFunction.h +++ b/src/jsc/bindings/JSMockFunction.h @@ -59,7 +59,6 @@ class MockWithImplementationCleanupData : public JSC::JSInternalFieldObjectImpl< JS_EXPORT_PRIVATE static MockWithImplementationCleanupData* create(VM&, Structure*); static MockWithImplementationCleanupData* create(JSC::JSGlobalObject* globalObject, JSMockFunction* fn, JSValue impl, JSValue tail, JSValue fallback); - static MockWithImplementationCleanupData* createWithInitialValues(VM&, Structure*); static Structure* createStructure(VM&, JSGlobalObject*, JSValue); static std::array initialValues() diff --git a/src/jsc/bindings/JSNextTickQueue.h b/src/jsc/bindings/JSNextTickQueue.h index 63c75f6453fd..5237e9b3b77d 100644 --- a/src/jsc/bindings/JSNextTickQueue.h +++ b/src/jsc/bindings/JSNextTickQueue.h @@ -16,7 +16,6 @@ class JSNextTickQueue : public JSC::JSInternalFieldObjectImpl<3> { JS_EXPORT_PRIVATE static JSNextTickQueue* create(VM&, Structure*); static JSNextTickQueue* create(JSC::JSGlobalObject* globalObject); - static JSNextTickQueue* createWithInitialValues(VM&, Structure*); static Structure* createStructure(VM&, JSGlobalObject*, JSValue); static std::array initialValues() diff --git a/src/jsc/bindings/JSX509CertificateConstructor.cpp b/src/jsc/bindings/JSX509CertificateConstructor.cpp deleted file mode 100644 index 04b7fc1fb851..000000000000 --- a/src/jsc/bindings/JSX509CertificateConstructor.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "root.h" -#include "JSX509CertificateConstructor.h" -#include "JSX509Certificate.h" -#include "ZigGlobalObject.h" -#include - -namespace Bun { - -using namespace JSC; - -} // namespace Bun diff --git a/src/jsc/bindings/JSX509CertificateConstructor.h b/src/jsc/bindings/JSX509CertificateConstructor.h deleted file mode 100644 index ee740d0ee1a0..000000000000 --- a/src/jsc/bindings/JSX509CertificateConstructor.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "root.h" -#include -#include - -namespace Zig { -class GlobalObject; -} - -namespace Bun { - -using namespace JSC; - -} // namespace Bun diff --git a/src/jsc/bindings/ModuleLoader.h b/src/jsc/bindings/ModuleLoader.h index 5f8380c67242..c2a3d65ac588 100644 --- a/src/jsc/bindings/ModuleLoader.h +++ b/src/jsc/bindings/ModuleLoader.h @@ -68,7 +68,6 @@ class PendingVirtualModuleResult : public JSC::JSInternalFieldObjectImpl<3> { JS_EXPORT_PRIVATE static PendingVirtualModuleResult* create(VM&, Structure*); static PendingVirtualModuleResult* create(JSC::JSGlobalObject* globalObject, const WTF::String& specifier, const WTF::String& referrer, bool wasModuleMock); - static PendingVirtualModuleResult* createWithInitialValues(VM&, Structure*); static Structure* createStructure(VM&, JSGlobalObject*, JSValue); JSC::JSPromise* internalPromise(); diff --git a/src/ptr/lib.rs b/src/ptr/lib.rs index d67003b8700e..b428f457764c 100644 --- a/src/ptr/lib.rs +++ b/src/ptr/lib.rs @@ -59,8 +59,7 @@ pub use weak_ptr::WeakPtr; // (lowest tier, every crate can reach them); re-exported here so callers can // spell `bun_ptr::container_of` / `bun_ptr::from_field_ptr!`. pub use bun_core::{ - IntrusiveField, container_of, container_of_const, from_field_ptr, impl_field_parent, - intrusive_field, + IntrusiveField, container_of, from_field_ptr, impl_field_parent, intrusive_field, }; // C-callback `void *user_data` → `&mut T` recovery — same tiering rationale diff --git a/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts b/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts new file mode 100644 index 000000000000..dae2b0ce2985 --- /dev/null +++ b/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts @@ -0,0 +1,79 @@ +// Guards against reintroduction of symbols removed as dead code from the +// top-level C++ bindings and bun_core. Each entry was verified to have zero +// callers across src/ and build/debug/codegen/ before deletion; this test +// fails if any reappear. +// +// This is a source-tree lint: it reads files from src/ and does not touch the +// built binary, so it belongs in test/internal/source-lints/ per the README. + +import { expect, test } from "bun:test"; +import { existsSync, readFileSync } from "node:fs"; +import path from "node:path"; + +const repoRoot = path.resolve(import.meta.dir, "..", "..", ".."); + +function src(p: string): string { + return readFileSync(path.join(repoRoot, p), "utf8"); +} + +test("empty JSX509CertificateConstructor.{h,cpp} and BunHeapProfiler.h do not reappear", () => { + // JSX509CertificateConstructor.{h,cpp} contained only includes and an empty + // `namespace Bun { }` block; the real constructor class is defined inline in + // JSX509Certificate.cpp. BunHeapProfiler.h was only included by its own .cpp; + // generateHeapProfile is now file-static. + const deleted = [ + "src/jsc/bindings/JSX509CertificateConstructor.h", + "src/jsc/bindings/JSX509CertificateConstructor.cpp", + "src/jsc/bindings/BunHeapProfiler.h", + ]; + const resurrected = deleted.filter(p => existsSync(path.join(repoRoot, p))); + expect(resurrected).toEqual([]); +}); + +test("dead Bun::ERR:: throw wrappers and binding declarations do not reappear", () => { + const checks: Array<[string, RegExp]> = [ + // Bun::ERR:: wrappers with zero C++ callers (the corresponding ErrorCode + // enum values remain; only these convenience throw functions are dead). + ["src/jsc/bindings/ErrorCode.h", /EncodedJSValue CRYPTO_TIMING_SAFE_EQUAL_LENGTH\(/], + ["src/jsc/bindings/ErrorCode.h", /EncodedJSValue KEY_GENERATION_JOB_FAILED\(/], + ["src/jsc/bindings/ErrorCode.h", /EncodedJSValue CLOSED_MESSAGE_PORT\(/], + ["src/jsc/bindings/ErrorCode.h", /CRYPTO_INVALID_KEYTYPE\(JSC::ThrowScope&, JSC::JSGlobalObject\*\);/], + ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue CRYPTO_TIMING_SAFE_EQUAL_LENGTH\(/], + ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue KEY_GENERATION_JOB_FAILED\(/], + ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue CLOSED_MESSAGE_PORT\(/], + ["src/jsc/bindings/ErrorCode.cpp", /CRYPTO_INVALID_KEYTYPE\(JSC::ThrowScope& throwScope, JSC::JSGlobalObject\* globalObject\)\n/], + // Forward-declared template that was never defined or instantiated. + ["src/jsc/bindings/JSDOMWrapperCache.h", /deprecatedGetDOMStructure/], + ["src/jsc/bindings/JSDOMWrapperCache.h", /getOrCreateWrapper/], + // Static factory methods declared but never defined (would link-error if called). + ["src/jsc/bindings/ModuleLoader.h", /createWithInitialValues/], + ["src/jsc/bindings/JSNextTickQueue.h", /createWithInitialValues/], + ["src/jsc/bindings/JSMockFunction.h", /createWithInitialValues/], + // Constructor declared but never defined. + ["src/jsc/bindings/AsymmetricKeyValue.h", /AsymmetricKeyValue\(EVP_PKEY\* key, bool owned\);/], + // Free function with zero callers; ZigGlobalObject::JSBufferList() is used directly. + ["src/jsc/bindings/JSBufferList.h", /getBufferList/], + ["src/jsc/bindings/JSBufferList.cpp", /getBufferList/], + ]; + const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`); + expect(resurrected).toEqual([]); +}); + +test("bun_core dead helpers do not reappear", () => { + const checks: Array<[string, RegExp]> = [ + // *const-out variant of container_of with zero callers; the *mut-out + // container_of covers every call site. + ["src/bun_core/lib.rs", /pub const unsafe fn container_of_const\b/], + ["src/ptr/lib.rs", /\bcontainer_of_const\b/], + // #[macro_export] literal! macro with zero invocations; callers use byte + // literals or w!() directly. + ["src/bun_core/string/immutable/unicode.rs", /macro_rules! literal \{/], + ["src/bun_core/string/mod.rs", /pub use crate::\{literal,/], + // From> for SharedPtr: Arc is never constructed + // outside ssl_config.rs; construction sites use SharedPtr::new or the + // tuple constructor directly. + ["src/http/ssl_config.rs", /impl From> for SharedPtr/], + ]; + const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`); + expect(resurrected).toEqual([]); +}); From 8cb0f4a4ba67a289b0e52ea665d61ce404894e5e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 04:15:31 +0000 Subject: [PATCH 2/7] [autofix.ci] apply automated fixes --- .../source-lints/dead-symbols-errorcode-x509-buncore.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts b/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts index dae2b0ce2985..d676cd0aad71 100644 --- a/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts +++ b/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts @@ -41,7 +41,10 @@ test("dead Bun::ERR:: throw wrappers and binding declarations do not reappear", ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue CRYPTO_TIMING_SAFE_EQUAL_LENGTH\(/], ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue KEY_GENERATION_JOB_FAILED\(/], ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue CLOSED_MESSAGE_PORT\(/], - ["src/jsc/bindings/ErrorCode.cpp", /CRYPTO_INVALID_KEYTYPE\(JSC::ThrowScope& throwScope, JSC::JSGlobalObject\* globalObject\)\n/], + [ + "src/jsc/bindings/ErrorCode.cpp", + /CRYPTO_INVALID_KEYTYPE\(JSC::ThrowScope& throwScope, JSC::JSGlobalObject\* globalObject\)\n/, + ], // Forward-declared template that was never defined or instantiated. ["src/jsc/bindings/JSDOMWrapperCache.h", /deprecatedGetDOMStructure/], ["src/jsc/bindings/JSDOMWrapperCache.h", /getOrCreateWrapper/], From 9629caf6f00119f62c0584be3209f2d1d4bbbd67 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 04:19:41 +0000 Subject: [PATCH 3/7] Drop explanatory comment above the w! re-export The re-export speaks for itself; dropping the comment also keeps the diff minimal now that literal! is gone from the list. --- src/bun_core/string/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bun_core/string/mod.rs b/src/bun_core/string/mod.rs index ef7942e5ef8e..a01cfced60ee 100644 --- a/src/bun_core/string/mod.rs +++ b/src/bun_core/string/mod.rs @@ -9,8 +9,6 @@ //! Merged into `bun_core` to break the `bun_core ↔ bun_string` dep edge; //! the `bun_string` crate is now a thin re-export shim over this module. -// `#[macro_export]` macros defined in submodules (`w!`) land at the *crate* -// root (`bun_core::`). Re-export here so `crate::string::w` resolves. pub use crate::w; #[path = "escapeRegExp.rs"] From 75589a0cbb8a708b5e29fee861ef825ab859fb7c Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 04:27:36 +0000 Subject: [PATCH 4/7] Make generateHeapSnapshotV8 file-static to match generateHeapProfile Same usage pattern: only called by extern "C" Bun__generateHeapSnapshotV8 in the same translation unit, never declared in a header. --- src/jsc/bindings/BunHeapProfiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jsc/bindings/BunHeapProfiler.cpp b/src/jsc/bindings/BunHeapProfiler.cpp index 656230dc540a..c4a0647b7eba 100644 --- a/src/jsc/bindings/BunHeapProfiler.cpp +++ b/src/jsc/bindings/BunHeapProfiler.cpp @@ -935,7 +935,7 @@ static WTF::String generateHeapProfile(JSC::VM& vm) return output.toString(); } -WTF::String generateHeapSnapshotV8(JSC::VM& vm) +static WTF::String generateHeapSnapshotV8(JSC::VM& vm) { vm.ensureHeapProfiler(); auto& heapProfiler = *vm.heapProfiler(); From a6f58e616df33a1232fb2c8702b07a51e5147aeb Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 04:50:37 +0000 Subject: [PATCH 5/7] JSDOMWrapperCache.h: fix getDOMPrototype fwd-decl param, drop undefined wrap overload The getDOMPrototype forward declaration took JSC::JSGlobalObject* but the definition takes JSDOMGlobalObject&, making them distinct overloads (the forward-declared one was never defined or called). Corrected the declaration to match. The wrap(JSGlobalObject*, DOMWrapperWorld&, DOMClass&) overload was declared but never defined; only the (JSGlobalObject*, JSDOMGlobalObject*, DOMClass&) overload is defined and used. --- src/jsc/bindings/JSDOMWrapperCache.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/jsc/bindings/JSDOMWrapperCache.h b/src/jsc/bindings/JSDOMWrapperCache.h index 5a887bfb261f..657938a92584 100644 --- a/src/jsc/bindings/JSDOMWrapperCache.h +++ b/src/jsc/bindings/JSDOMWrapperCache.h @@ -40,7 +40,7 @@ WEBCORE_EXPORT JSC::Structure* getCachedDOMStructure(const JSDOMGlobalObject&, c WEBCORE_EXPORT JSC::Structure* cacheDOMStructure(JSDOMGlobalObject&, JSC::Structure*, const JSC::ClassInfo*); template JSC::Structure* getDOMStructure(JSC::VM&, JSDOMGlobalObject&); -template JSC::JSObject* getDOMPrototype(JSC::VM&, JSC::JSGlobalObject*); +template JSC::JSObject* getDOMPrototype(JSC::VM&, JSDOMGlobalObject&); JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld&, JSC::ArrayBuffer*); void* wrapperKey(JSC::ArrayBuffer*); @@ -64,7 +64,6 @@ template void uncacheWrapper(DOMWrappe template auto createWrapper(JSDOMGlobalObject*, Ref&&) -> typename std::enable_if::value, typename JSDOMWrapperConverterTraits::WrapperClass*>::type; template auto createWrapper(JSDOMGlobalObject*, Ref&&) -> typename std::enable_if::value, typename JSDOMWrapperConverterTraits::WrapperClass*>::type; -template JSC::JSValue wrap(JSC::JSGlobalObject*, DOMWrapperWorld&, DOMClass&); template JSC::JSValue wrap(JSC::JSGlobalObject*, JSDOMGlobalObject*, DOMClass&); // Inline functions and template definitions. From ddeb3130424b9fb708c637b7b56c1c673b04388c Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 31 Jul 2026 05:03:38 +0000 Subject: [PATCH 6/7] ci: retrigger From 9dec3414f5b997f6b5267bde73484da109a0aa58 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 30 Jul 2026 23:52:19 -0700 Subject: [PATCH 7/7] Delete test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts --- ...ead-symbols-errorcode-x509-buncore.test.ts | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts diff --git a/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts b/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts deleted file mode 100644 index d676cd0aad71..000000000000 --- a/test/internal/source-lints/dead-symbols-errorcode-x509-buncore.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -// Guards against reintroduction of symbols removed as dead code from the -// top-level C++ bindings and bun_core. Each entry was verified to have zero -// callers across src/ and build/debug/codegen/ before deletion; this test -// fails if any reappear. -// -// This is a source-tree lint: it reads files from src/ and does not touch the -// built binary, so it belongs in test/internal/source-lints/ per the README. - -import { expect, test } from "bun:test"; -import { existsSync, readFileSync } from "node:fs"; -import path from "node:path"; - -const repoRoot = path.resolve(import.meta.dir, "..", "..", ".."); - -function src(p: string): string { - return readFileSync(path.join(repoRoot, p), "utf8"); -} - -test("empty JSX509CertificateConstructor.{h,cpp} and BunHeapProfiler.h do not reappear", () => { - // JSX509CertificateConstructor.{h,cpp} contained only includes and an empty - // `namespace Bun { }` block; the real constructor class is defined inline in - // JSX509Certificate.cpp. BunHeapProfiler.h was only included by its own .cpp; - // generateHeapProfile is now file-static. - const deleted = [ - "src/jsc/bindings/JSX509CertificateConstructor.h", - "src/jsc/bindings/JSX509CertificateConstructor.cpp", - "src/jsc/bindings/BunHeapProfiler.h", - ]; - const resurrected = deleted.filter(p => existsSync(path.join(repoRoot, p))); - expect(resurrected).toEqual([]); -}); - -test("dead Bun::ERR:: throw wrappers and binding declarations do not reappear", () => { - const checks: Array<[string, RegExp]> = [ - // Bun::ERR:: wrappers with zero C++ callers (the corresponding ErrorCode - // enum values remain; only these convenience throw functions are dead). - ["src/jsc/bindings/ErrorCode.h", /EncodedJSValue CRYPTO_TIMING_SAFE_EQUAL_LENGTH\(/], - ["src/jsc/bindings/ErrorCode.h", /EncodedJSValue KEY_GENERATION_JOB_FAILED\(/], - ["src/jsc/bindings/ErrorCode.h", /EncodedJSValue CLOSED_MESSAGE_PORT\(/], - ["src/jsc/bindings/ErrorCode.h", /CRYPTO_INVALID_KEYTYPE\(JSC::ThrowScope&, JSC::JSGlobalObject\*\);/], - ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue CRYPTO_TIMING_SAFE_EQUAL_LENGTH\(/], - ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue KEY_GENERATION_JOB_FAILED\(/], - ["src/jsc/bindings/ErrorCode.cpp", /EncodedJSValue CLOSED_MESSAGE_PORT\(/], - [ - "src/jsc/bindings/ErrorCode.cpp", - /CRYPTO_INVALID_KEYTYPE\(JSC::ThrowScope& throwScope, JSC::JSGlobalObject\* globalObject\)\n/, - ], - // Forward-declared template that was never defined or instantiated. - ["src/jsc/bindings/JSDOMWrapperCache.h", /deprecatedGetDOMStructure/], - ["src/jsc/bindings/JSDOMWrapperCache.h", /getOrCreateWrapper/], - // Static factory methods declared but never defined (would link-error if called). - ["src/jsc/bindings/ModuleLoader.h", /createWithInitialValues/], - ["src/jsc/bindings/JSNextTickQueue.h", /createWithInitialValues/], - ["src/jsc/bindings/JSMockFunction.h", /createWithInitialValues/], - // Constructor declared but never defined. - ["src/jsc/bindings/AsymmetricKeyValue.h", /AsymmetricKeyValue\(EVP_PKEY\* key, bool owned\);/], - // Free function with zero callers; ZigGlobalObject::JSBufferList() is used directly. - ["src/jsc/bindings/JSBufferList.h", /getBufferList/], - ["src/jsc/bindings/JSBufferList.cpp", /getBufferList/], - ]; - const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`); - expect(resurrected).toEqual([]); -}); - -test("bun_core dead helpers do not reappear", () => { - const checks: Array<[string, RegExp]> = [ - // *const-out variant of container_of with zero callers; the *mut-out - // container_of covers every call site. - ["src/bun_core/lib.rs", /pub const unsafe fn container_of_const\b/], - ["src/ptr/lib.rs", /\bcontainer_of_const\b/], - // #[macro_export] literal! macro with zero invocations; callers use byte - // literals or w!() directly. - ["src/bun_core/string/immutable/unicode.rs", /macro_rules! literal \{/], - ["src/bun_core/string/mod.rs", /pub use crate::\{literal,/], - // From> for SharedPtr: Arc is never constructed - // outside ssl_config.rs; construction sites use SharedPtr::new or the - // tuple constructor directly. - ["src/http/ssl_config.rs", /impl From> for SharedPtr/], - ]; - const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`); - expect(resurrected).toEqual([]); -});