You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MCP: Add -Z dead-fn-elimination to skip codegen of BFS-unreachable functions
Proposal
Add an unstable -Z dead-fn-elimination flag that performs BFS reachability from binary entry points over the MIR call graph, then excludes unreachable functions from codegen via an is_codegened_item query override. ~462 lines across 6 files.
Large binary crates spend significant LLVM time on functions the linker later discards via --gc-sections. This flag moves that elimination before LLVM, at the MIR level. On a patched stage2 compiler, zed builds 8% faster and rustc builds 6% faster; smaller projects break even. The algorithm has been validated as an external RUSTC_WRAPPER tool (cargo-slicer).
An 12-point safety checklist ensures only private, non-generic, non-async, safe, non-Drop standalone functions are eliminated. Generic functions, async functions, unsafe functions, vtable-dispatched methods, #[no_mangle]/#[used] items, and functions whose signatures involve fn() pointers or dyn Trait are unconditionally kept. This MCP also provides foundational BFS infrastructure for a broader crate slicing project goal (a separate proposal).
MCP: Add
-Z dead-fn-eliminationto skip codegen of BFS-unreachable functionsProposal
Add an unstable
-Z dead-fn-eliminationflag that performs BFS reachability from binary entry points over the MIR call graph, then excludes unreachable functions from codegen via anis_codegened_itemquery override. ~462 lines across 6 files.Large binary crates spend significant LLVM time on functions the linker later discards via
--gc-sections. This flag moves that elimination before LLVM, at the MIR level. On a patched stage2 compiler, zed builds 8% faster and rustc builds 6% faster; smaller projects break even. The algorithm has been validated as an externalRUSTC_WRAPPERtool (cargo-slicer).An 12-point safety checklist ensures only private, non-generic, non-async, safe, non-Drop standalone functions are eliminated. Generic functions, async functions, unsafe functions, vtable-dispatched methods,
#[no_mangle]/#[used]items, and functions whose signatures involvefn()pointers ordyn Traitare unconditionally kept. This MCP also provides foundational BFS infrastructure for a broader crate slicing project goal (a separate proposal).Detailed design, benchmarks, and the full safety proof: docs/upstream-rfc.md
Mentors or Reviewers
Community feedback incorporated from @lcnr, @Amanieu, @workingjubilee, @oli-obk.
Note
Concerns (0 active)
relation-with-project-goalresolved in this commentManaged by
@rustbot—see help for details.