From 75eccbd7c346875af900343bab368a5b3751c877 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Thu, 17 Sep 2026 16:55:32 +0000 Subject: [PATCH] Remove dead code from four platform shims, bun_core, and bun_resolver The C++ shims for NoOrphansTracker, the CoreGraphics and WIC image backends, and the io_darwin waker defined empty stubs on the platforms they do not support. Every Rust caller of those symbols is behind a target_os cfg, so nothing references the stubs on any target. Also remove two trait impls that nothing calls: OptionsEnvArg for Box and From> for cache::Contents. --- src/bun_core/util.rs | 19 +------------------ src/io/io_darwin.cpp | 15 +-------------- src/jsc/bindings/NoOrphansTracker.cpp | 10 +--------- src/jsc/bindings/image_coregraphics_shim.cpp | 12 +----------- src/jsc/bindings/image_wic_shim.cpp | 7 +------ src/resolver/lib.rs | 10 ---------- 6 files changed, 5 insertions(+), 68 deletions(-) diff --git a/src/bun_core/util.rs b/src/bun_core/util.rs index 662242c10620..eb4705d687b9 100644 --- a/src/bun_core/util.rs +++ b/src/bun_core/util.rs @@ -3838,8 +3838,7 @@ pub(crate) fn set_bun_options_argc(n: usize) { } /// Trait for arg types accepted by [`append_options_env`]. -/// Impl'd for `bun_core::String` -/// and `Box` in their owning crates. +/// Impl'd for `&'static ZStr` and `bun_core::String`. pub trait OptionsEnvArg { fn from_slice(s: &[u8]) -> Self; fn from_buf(buf: Vec) -> Self; @@ -3863,22 +3862,6 @@ impl OptionsEnvArg for &'static ZStr { } } -/// Owned `Box` arm of `appendOptionsEnv` — used by `bun::init_argv`'s -/// BUN_OPTIONS splice path, which stores argv entries as `Box`. -impl OptionsEnvArg for Box { - fn from_slice(s: &[u8]) -> Self { - ZStr::boxed(s) - } - fn from_buf(mut buf: Vec) -> Self { - buf.push(0); - let b: Box<[u8]> = buf.into_boxed_slice(); - // SAFETY: `ZStr` is `#[repr(transparent)]` over `[u8]`; the fat-pointer - // metadata (len includes the trailing NUL) is preserved by the cast — - // identical to `ZStr::boxed` but consuming the Vec without re-copying. - unsafe { crate::heap::take(crate::heap::into_raw(b) as *mut ZStr) } - } -} - /// Parse a `BUN_OPTIONS`-style string /// (`--flag=value --flag2 "quoted value" bare`) and insert each token into /// `args` starting at index 1 (callers prepend a placeholder at [0]). diff --git a/src/io/io_darwin.cpp b/src/io/io_darwin.cpp index 4f9ca1ed60e5..b8ffcff6ee39 100644 --- a/src/io/io_darwin.cpp +++ b/src/io/io_darwin.cpp @@ -102,17 +102,4 @@ extern "C" bool io_darwin_schedule_wakeup(mach_port_t waker) } } -#else - -// stub out these symbols -extern "C" int io_darwin_create_machport(int fd, - void* wakeup_buffer_, - unsigned long long nbytes) -{ - return 0; -} - -// stub out these symbols -extern "C" bool io_darwin_schedule_wakeup(void* waker) { return false; } - -#endif +#endif // __APPLE__ diff --git a/src/jsc/bindings/NoOrphansTracker.cpp b/src/jsc/bindings/NoOrphansTracker.cpp index 621e11102c57..db59c2a01ad5 100644 --- a/src/jsc/bindings/NoOrphansTracker.cpp +++ b/src/jsc/bindings/NoOrphansTracker.cpp @@ -268,12 +268,4 @@ extern "C" void Bun__noOrphans_onFork() { Bun::NoOrphansTracker::get().scan(); } extern "C" void Bun__noOrphans_onExit(pid_t pid) { Bun::NoOrphansTracker::get().onExit(pid); } extern "C" void Bun__noOrphans_killTracked() { Bun::NoOrphansTracker::get().killTracked(); } -#else // !OS(DARWIN) - -extern "C" void Bun__noOrphans_begin(int, int) {} -extern "C" void Bun__noOrphans_releaseKq() {} -extern "C" void Bun__noOrphans_onFork() {} -extern "C" void Bun__noOrphans_onExit(int) {} -extern "C" void Bun__noOrphans_killTracked() {} - -#endif +#endif // OS(DARWIN) diff --git a/src/jsc/bindings/image_coregraphics_shim.cpp b/src/jsc/bindings/image_coregraphics_shim.cpp index 26874e691869..0a30edd784e4 100644 --- a/src/jsc/bindings/image_coregraphics_shim.cpp +++ b/src/jsc/bindings/image_coregraphics_shim.cpp @@ -592,14 +592,4 @@ int64_t bun_coregraphics_clipboard_change_count() } // extern "C" -#else -// Non-Apple: stubs so the link succeeds; callers only reference these on -// macOS so they're dead code, but LTO needs the definitions. -extern "C" int bun_coregraphics_decode(const void*, unsigned long, unsigned long long, void*, void*, void*) { return 1; } -extern "C" int bun_coregraphics_encode(const void*, unsigned, unsigned, int, int, void*, void*) { return 1; } -extern "C" int bun_coregraphics_scale(const void*, unsigned, unsigned, void*, unsigned, unsigned) { return 1; } -extern "C" int bun_coregraphics_rotate90(const void*, unsigned, unsigned, void*, unsigned) { return 1; } -extern "C" int bun_coregraphics_reflect(const void*, unsigned, unsigned, void*, int) { return 1; } -extern "C" int bun_coregraphics_clipboard(void*, void*, int) { return 1; } -extern "C" long long bun_coregraphics_clipboard_change_count() { return -1; } -#endif +#endif // defined(__APPLE__) diff --git a/src/jsc/bindings/image_wic_shim.cpp b/src/jsc/bindings/image_wic_shim.cpp index fe9796980e23..8358ddd9f0a3 100644 --- a/src/jsc/bindings/image_wic_shim.cpp +++ b/src/jsc/bindings/image_wic_shim.cpp @@ -54,9 +54,4 @@ extern "C" int32_t bun_wic_propbag_write_u8(void* props, const wchar_t* name, ui return write1(props, name, VT_UI1, [](VARIANT& var) { var.bVal = v; }); } -#else -// Stubs so the symbols exist everywhere; backend_wic.rs is Windows-only so -// these are never called, but the linker wants them. -extern "C" int bun_wic_propbag_write_f32(void*, const void*, float) { return 0; } -extern "C" int bun_wic_propbag_write_u8(void*, const void*, unsigned char) { return 0; } -#endif +#endif // defined(_WIN32) diff --git a/src/resolver/lib.rs b/src/resolver/lib.rs index 273ca6723195..f92757538dcf 100644 --- a/src/resolver/lib.rs +++ b/src/resolver/lib.rs @@ -2211,16 +2211,6 @@ pub mod cache { } } - impl From> for Contents { - fn from(b: Box<[u8]>) -> Self { - if b.is_empty() { - Contents::Empty - } else { - Contents::Owned(b.into_vec()) - } - } - } - /// Adapter for the canonical `fs::read_file_contents` (returns /// `Cow<'buf,[u8]>` per the spec `PathContentsPair` shape). `Borrowed` /// always points into the per-thread `shared_buffer` on the