Skip to content

Remove dead code: 15 trait impls nothing uses and two C++ overloads - #47264

Closed
robobun wants to merge 3 commits into
mainfrom
robobun/fc4ad666/dead-code-sweep
Closed

robobun wants to merge 3 commits into
mainfrom
robobun/fc4ad666/dead-code-sweep

Conversation

@robobun

@robobun robobun commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Behaviour change: none

Problem

  • 15 hand-written trait impls have no caller. A --gc-sections link keeps none of their methods, and the workspace compiles without them on all 12 targets.
  • JSCommonJSModule::create(Zig::GlobalObject*, const WTF::String&, ...) and HTTPHeaderMap::get(StringView) have no caller.
  • The removable_host_function_definition! macro has no user.

Fix

  • Delete them. The only added lines are a narrowed import and a reworded doc comment.
  • Correct because each deletion compiles: bun run rust:check-all (12 targets), cargo check --workspace --release, the unit tests and benches (--all-targets for Linux, macOS and Windows), and bun bd.
  • Verified: headers.test.ts, node-module-module.test.js, deflate-streaming.test.ts and test/cli/lint/bun-rules.test.ts pass on the debug ASAN build.

Background

  • A trait impl is dead when no code selects it. rustc's dead_code lint does not report it, and neither does hawk (the cross-crate lint behind hawk.toml): both treat an impl as reachable.
  • The candidates came from a relink of the debug binary with --gc-sections --print-gc-sections. The compiler then vetoed 68 of 84 candidates, and those stay.
  • Each deletion was checked against the open PRs that touch the same files. None of them removes the same code.

Downsides

  • None found for users. No removed function has a caller. A --gc-sections link of the Linux debug binary keeps none of them, so no code that can run is removed.
  • A later caller of {:?}, {}, Default::default() or .into() on one of these types gets a compile error and must add the impl back.
Notes

Removed

  • bun_core: impl Default for Ordinal, impl AsRef<ZStr> for ZStr.
  • bun_css: impl Debug for EnvironmentVariable.
  • bun_jsc: impl Debug for GlobalRef.
  • bun_lint: impl Spanned for estree_compat::Target (the inherent Target::span stays).
  • bun_ptr: impl AsRef<[u8]>, impl Borrow<[u8]>, impl Default and impl Debug for Interned.
  • bun_resolver: impl Debug for DirInfoRef.
  • bun_spawn: impl From<bun_sys::Error> for Error.
  • bun_sql_jsc: impl ErrName for Error.
  • bun_sys: impl Display for SystemError, impl Debug for net::Address.
  • bun_zlib: impl Default for ZStream.
  • bun_removable_features: macro_rules! removable_host_function_definition.
  • src/jsc/bindings/JSCommonJSModule.{cpp,h}: the const WTF::String& overload of create. Every caller passes a JSString* or a VM&.
  • src/jsc/bindings/webcore/HTTPHeaderMap.{cpp,h}: get(StringView). Every caller passes an HTTPHeaderName.

The two added lines are a narrowed import in estree_compat.rs and a doc comment on SystemError::fmt_with_path that named the removed Display impl.

impl ErrName for bun_archive::Error and Error::name also passed every check, but #47106 changed those lines on main while this ran. They are not in this PR.

No silent change of method resolution

  • Interned derefs to [u8]. A .as_ref() or .borrow() call on it now resolves to the std impl on the slice and returns the same slice. A generic bound on the removed impl fails to compile.
  • Target::span is inherent, so a target.span() call never selected the trait method.
  • GlobalRef and DirInfoRef deref to JSGlobalObject and DirInfo. Neither target implements Debug, so a .fmt() call cannot fall through to the target.
  • No file that uses Interned calls Debug::fmt by hand. A {:?} or a derive needs the removed impl, so it fails to compile and does not fall through to [u8].
  • No Drop, Clone, PartialEq or Hash impl is removed.

How the candidates were found

  • Relinked the Linux x64 debug binary with --gc-sections --print-gc-sections. A hand-written, non-generic trait impl became a candidate when the linker dropped every one of its methods. A second batch took impls with no method symbol in the linked binary at all.
  • The compiler decided each one. A deletion stays only if cargo check passes with it. It vetoed 68 of 84 candidates: a #[derive(Debug)] container, a test assert_eq!, a ? conversion, or a generic bound needs the impl. rust:check-all caught four that only Windows or macOS code uses (AsRef<[u16]> for WStr, Default for store::Bytes, Display for FilePoll and its FlagsFormatter). #[inline] impls have no symbol even when code uses them, so the second batch lost most of its candidates.
  • Ran hawk (the lint behind hawk.toml, rebuilt against the pinned nightly) for x86_64-unknown-linux-gnu, aarch64-apple-darwin and x86_64-pc-windows-msvc. No pub function, method, type or const is dead on all three that an open PR does not already remove.
  • 3 read-only passes checked the 189 hand-written C/C++ functions the linker dropped: 116 are already deleted by open PRs, 20 are alive on another platform or build config, 37 are destructors, template instantiations or vendored code, and 16 are dead (2 are in this PR, 14 are listed below).

Found dead, not in this PR

  • us_nq_settings_set_scid_len and us_nq_settings_set_delay_onclose (node_quic_shim.c, bun_lsquic_sys): no caller. http, net, tls: consolidate the open fetch, Bun.serve, node:http, node:http2, HTTP/3, node:net and node:tls pull requests #46528 already removes them, so this PR does not.
  • Zig::GlobalObject::create(JSC::VM&, JSC::Structure*) (ZigGlobalObject.cpp, ZigGlobalObject.h): no caller. The header is in the precompiled header, so the check needs a full C++ rebuild. Not done here.
  • PerformanceResourceTiming::create, its constructor, entryStartTime, entryEndTime, ResourceTiming's constructor, populateServerTiming, url(), PerformanceServerTiming::create and its constructor, NetworkLoadMetrics(): no caller, about 68 lines. Remove dead code from bun_core, the JSC bindings, the debugger, and 24 other crates #41385 edits lines inside these bodies, so this PR leaves them.
  • The #else stub of Bun__REPRL__resetCoverage in FuzzilliREPRL.cpp: the only caller is compiled only when FUZZILLI_ENABLED is set.
  • 29 #[no_mangle] Rust exports that the linker drops on Linux. Some are for macOS, Windows or lldb. Left alone.

Checks

  • bun run rust:check-all: 12 of 12 targets pass with the workspace lint levels (dead_code, unused_imports and the rest at deny).
  • These checks ran on 11c3671 plus this change. main has moved since. The branch merges with it without conflict.
  • cargo check --workspace --release on x86_64-unknown-linux-gnu, against release codegen (--profile=release --mode=codegen).
  • cargo check --workspace --all-targets on x86_64-unknown-linux-gnu, so unit tests and benches compile too. The full pass ran before the last six impls were restored. A restored impl cannot break a test target, and cargo check -p bun_runtime --all-targets passed afterwards.
  • cargo check --workspace --all-targets for aarch64-apple-darwin and x86_64-pc-windows-msvc, on the pushed tree. CI compiles test targets only for Linux, so this covers test-only code for macOS and Windows.
  • cargo fmt --all -- --check.
  • Overlap: the diffs of the 110 open dead-code PRs, and the heads of the 87 open PRs that touch these files or are too large to list. None removes the same lines.
  • bun bd (debug, ASAN) builds and links.
  • Size: the binary-size job compares the 12 release binaries with a main build that is 11 commits ahead of the base of this branch. Each is within 8 KB of it (116 to 142 MB per binary).
  • rust:check-all, the release check, bun bd and the tests ran on a commit that also removed impl ErrName for bun_archive::Error and the two QUIC setters. This branch differs from it only by keeping that code, and cargo check -p bun_archive -p bun_lsquic_sys passes on it.
  • test/js/web/fetch/headers.test.ts 142 pass, test/js/node/module/node-module-module.test.js 80 pass, test/js/bun/archive.test.ts 136 pass, test/js/node/quic/quic-endpoint.test.ts 9 pass, test/js/node/zlib/deflate-streaming.test.ts 1 pass, test/cli/lint/bun-rules.test.ts 115 pass (run with --timeout 120000: the debug ASAN binary exceeds the 5 s default here).

…QUIC setters

Delete 15 hand-written trait impls that no code selects (Debug, Display,
Default, From, AsRef, Borrow, ErrName, Spanned).

Delete JSCommonJSModule::create(Zig::GlobalObject*, const WTF::String&, ...)
and HTTPHeaderMap::get(StringView). Neither has a caller.

Delete us_nq_settings_set_scid_len and us_nq_settings_set_delay_onclose
with their Rust declarations and setter rows. Neither setter has a caller.

Delete the removable_host_function_definition! macro. It has no user.
@robobun

robobun commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 3:06 PM PT - Oct 29th, 2026

❌ @robobun, your commit 46fd1d4 has 60 failures in Build #135351 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 47264

That installs a local version of the PR into your bun-47264 executable, so you can run:

bun-47264 --bun

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 563272e and 3b70985.

Files selected for processing: 17
  • packages/bun-usockets/src/node_quic_shim.c
  • src/bun_core/util.rs
  • src/css/properties/custom.rs
  • src/jsc/JSGlobalObject.rs
  • src/jsc/bindings/JSCommonJSModule.cpp
  • src/jsc/bindings/JSCommonJSModule.h
  • src/jsc/bindings/webcore/HTTPHeaderMap.cpp
  • src/jsc/bindings/webcore/HTTPHeaderMap.h
  • src/lint/utils/estree_compat.rs
  • src/lsquic_sys/lib.rs
  • src/ptr/lib.rs
  • src/resolver/dir_info.rs
  • src/spawn/error.rs
  • src/sql_jsc/error.rs
  • src/sys/lib.rs
  • src/trim/removable_features/entry_point.rs
  • src/zlib/stream.rs
Files with no reviewable changes: 15
  • src/trim/removable_features/entry_point.rs
  • src/lsquic_sys/lib.rs
  • src/jsc/bindings/webcore/HTTPHeaderMap.h
  • src/zlib/stream.rs
  • src/spawn/error.rs
  • packages/bun-usockets/src/node_quic_shim.c
  • src/css/properties/custom.rs
  • src/jsc/JSGlobalObject.rs
  • src/jsc/bindings/JSCommonJSModule.cpp
  • src/sql_jsc/error.rs
  • src/jsc/bindings/webcore/HTTPHeaderMap.cpp
  • src/jsc/bindings/JSCommonJSModule.h
  • src/bun_core/util.rs
  • src/ptr/lib.rs
  • src/resolver/dir_info.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

This change removes selected QUIC settings, JSC method overloads, Rust trait implementations, and helper interfaces across multiple modules.

Changes

API and implementation removals

Layer / File(s) Summary
QUIC settings bindings
packages/bun-usockets/src/node_quic_shim.c, src/lsquic_sys/lib.rs
The scid_len and delay_onclose setting setters and FFI declarations are removed. The silent_close and cc_algo setters remain.
JSC binding overloads
src/jsc/bindings/JSCommonJSModule.*, src/jsc/bindings/webcore/HTTPHeaderMap.*
The WTF::String overload of JSCommonJSModule::create and the StringView overload of HTTPHeaderMap::get are removed. The other described overloads remain.
Value-type trait implementations
src/bun_core/util.rs, src/ptr/lib.rs, src/zlib/stream.rs
Selected Default, AsRef, Borrow, and Debug implementations are removed from Ordinal, ZStr, Interned, and ZStream.
Formatting implementations
src/css/properties/custom.rs, src/jsc/JSGlobalObject.rs, src/resolver/dir_info.rs, src/sys/lib.rs
Selected Debug and Display implementations are removed from EnvironmentVariable, GlobalRef, DirInfoRef, SystemError, and net::Address.
Error and helper interfaces
src/lint/utils/estree_compat.rs, src/spawn/error.rs, src/sql_jsc/error.rs, src/trim/removable_features/entry_point.rs
The Spanned implementation for Target, a system-error conversion, ErrName for SQL errors, and the removable host-function macro are removed.

Suggested reviewers: jarred-sumner

Priority: Low

Merge Risk: Minimal · previous review 3b709

No merge-blocking risk is established by these dead-code removals.

Pre-merge checks: Passed 4
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title names the main change: removal of dead code, specifically 15 trait impls and two C++ overloads. The objectives also list two QUIC setters and an unused macro, which the title omits. The titl…
Description check Passed The description follows the repository template with both required sections, "What does this PR do?" and "How did you verify your code works?", and both are substantively filled. It states the problem…
Full details: Title check

Explanation

The title names the main change: removal of dead code, specifically 15 trait impls and two C++ overloads. The objectives also list two QUIC setters and an unused macro, which the title omits. The title is specific and accurate for the primary change.

Full details: Description check

Explanation

The description follows the repository template with both required sections, "What does this PR do?" and "How did you verify your code works?", and both are substantively filled. It states the problem, the fix, and the background. It lists each removed impl, method, and macro, and it names the candidates left in place and the reasons. Verification covers bun run rust:check-all on 12 targets, cargo check runs across several targets, bun bd, and specific test files with pass counts. The description is detailed and matches the objectives and the file summaries. Minor gaps: the 'What does this PR do?' section does not open with a one-line statement of purpose, and the author's notes are long and dense. Neither gap makes the description incomplete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

@robobun

robobun commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status

  • This removes 15 trait impls with no caller, two C++ overloads and one unused macro. 15 files, 143 lines removed, 2 lines changed.
  • bun run rust:check-all passes on all 12 targets. cargo check --workspace --release passes. bun bd (debug, ASAN) builds. headers.test.ts, node-module-module.test.js, deflate-streaming.test.ts and test/cli/lint/bun-rules.test.ts pass on it.
  • These checks ran on a tree that also removed two QUIC setters and impl ErrName for bun_archive::Error. The pushed tree keeps that code as it is on main, and cargo check -p bun_archive -p bun_lsquic_sys passes on it.
  • cargo check --workspace --all-targets passes on the pushed tree for aarch64-apple-darwin and x86_64-pc-windows-msvc. Test-only code for macOS and Windows compiles too. The cargo clippy job runs the same check for Linux.
  • The second commit puts back the two QUIC setters, because http, net, tls: consolidate the open fetch, Bun.serve, node:http, node:http2, HTTP/3, node:net and node:tls pull requests #46528 already removes them. No open PR removes any other code that this PR removes.
  • The branch merges with main without conflict. The notes in the description list what was found dead and left out.

CI

  • No failure comes from this change. Build 135351 ran the head. Every required Linux and Windows lane passes, and all 14 build lanes pass (244 jobs).
  • The 10 required macOS test jobs of build 135351 run last, because the macOS agents are some hours behind. The same tree passed every required macOS test lane in build 134751: the head is an empty commit on top of the commit that build ran.
  • The only failed jobs are on the test-aot-drawn lanes. Those lanes are allowed to fail. Each commit draws a different part of the AoT programs, and the other builds of the same hours fail on these lanes too.

#46528 already removes them. This change no longer touches
node_quic_shim.c or bun_lsquic_sys.
@robobun robobun changed the title Remove dead code: 15 trait impls nothing uses, two C++ overloads, and two QUIC setters Remove dead code: 15 trait impls nothing uses and two C++ overloads Oct 29, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-29.

The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants