Cross-crate dead code elimination
Cross-crate dead code elimination
Posted Dec 14, 2024 2:32 UTC (Sat) by saethlin (guest, #175049)In reply to: Cross-crate dead code elimination by intgr
Parent article: Rust's incremental compiler architecture
But apart from that, you can do a crude version of this right now by setting the flags -Zmir-opt-level=0 and -Zcross-crate-inline-threshold=always in your dependencies. Cargo profile overrides can do this unstably, for example:
[profile.release.package.aws_sdk_ec2]
rustflags = ["-Zmir-opt-level=0", "-Zcross-crate-inline-threshold=always"]
This basically delays all codegen to dependencies of the named crate, and then you get dead code elimination through the mechanism that rustc already uses to only lower required functions through the codegen backend. But those flags also may or may not ruin the incrementality of your builds, and may also make the entire compilation single-threaded, because the whole program is a single codegen unit based on your main.
I've worked a fair bit on this part of the compiler recently.