Repository navigation
Conversation
scripts/dead-code.mjs reports dead-code candidates from rustc, cargo-machete, knip, tsc and a repo-wide word search. It narrows every pub item in crates/core to pub(crate) in a scratch copy so rustc can flag exported items that no other crate uses. Run it with --linux to add a pass in a rust:latest container for Linux-only code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
rustc does not flag an unused
pubitem in a library crate.allow(dead_code)also hides items that nothing calls. So a cleancargo clippyrun says little about dead code incrates/coreor incrates/cli/tests/support.scripts/dead-code.mjscloses both gaps and runs the JS and dependency checks in the same pass. You can rerun it before any cleanup.On current
dev, it finds no dead code. This PR adds only the detector and deletes nothing.Scope
scripts/dead-code.mjs. Runnode scripts/dead-code.mjs --linux.allow(dead_code), and narrows everypubitem incrates/core/srctopub(crate). If another crate uses an item, the narrowed build fails, and the script restores that item topuband builds again. When the build passes, rustc flags the exported items that only core itself could use. Clippy runs with-W dead_code -W unreachable_pub.--linuxrepeats the build in arust:latestcontainer, because macOS builds skipcfg(target_os = "linux")code.cargo machete, unused[workspace.dependencies]entries, knip onplugins/opencodeandnpm/rift-snapshot,tsc --noUnusedLocals --noUnusedParameterson the plugin,scripts/files that nothing invokes, uncalled shell functions, and#[no_mangle]FFI symbols that nothing outsidecrates/ffinames.rg --word-regexpsearch across the repo, so string, dynamic, and cross-language references show up. The verdict isdeadwhen nothing references the item,test-onlywhen only tests do, andreviewotherwise.Tradeoffs
scripts/. It needscargo-machete,rg, andbunonPATH, plus Docker for--linux.reviewrows.Verification
Detector output on
devat5afb72b(node scripts/dead-code.mjs --linux, with the 15unreachable_pubrows forcrates/cli/tests/supportcollapsed):Manager::remove_allandManager::createare wrappers that pass default options. Onlycrates/core/src/tests.rsandlinux_filesystem_tests.rscall them. Thecreaterefs in the full output are npm JS names and shell commands. This PR leaves both wrappers in place because feat(core): add guarded lifecycle plans and recovery #44 editscrates/core/src/lib.rs.StrategyInit::Converted.strategy/btrfs.rsconstructs it on Linux, so the variant is live.Managermethod, an unused test-support fn, an unused TS export, an unused workspace dependency, an uncalled shell function, and an enum variant. The script reported the first six asdead. The enum variant broke exhaustivematches, so that test case was invalid.cargo +nightly udeps --workspace --all-targets --lockedagrees with machete: "All deps seem to have been used".cargo test --workspace --locked,bun test(5 pass), andbun run typecheckpass. I builtrift-cliand raninit,create,list, andremoveagainst a temp database.