rust/compiler/rustc_session/src
Urgau 33185d3fd9
Rollup merge of #135656 - joshtriplett:hint-mostly-unused, r=saethlin
Add `-Z hint-mostly-unused` to tell rustc that most of a crate will go unused

This hint allows the compiler to optimize its operation based on this assumption, in order to compile faster. This is a hint, and does not guarantee any particular behavior.

This option can substantially speed up compilation if applied to a large dependency where the majority of the dependency does not get used. This flag may slow down compilation in other cases.

Currently, this option makes the compiler defer as much code generation as possible from functions in the crate, until later crates invoke those functions. Functions that never get invoked will never have code generated for them. For instance, if a crate provides thousands of functions, but only a few of them will get called, this flag will result in the compiler only doing code generation for the called functions. (This uses the same mechanisms as cross-crate inlining of functions.) This does not affect `extern` functions, or functions marked as `#[inline(never)]`.

This option has already existed in nightly as `-Zcross-crate-inline-threshold=always` for some time, and has gotten testing in that form. However, this option is still unstable, to give an opportunity for wider testing in this form.

Some performance numbers, based on a crate with many dependencies having just *one* large dependency set to `-Z hint-mostly-unused` (using Cargo's `profile-rustflags` option):

A release build went from 4m07s to 2m04s.

A non-release build went from 2m26s to 1m28s.
2025-06-18 19:40:30 +02:00
..
config Implement the internal feature cfg_target_has_reliable_f16_f128 2025-04-27 19:58:44 +00:00
code_stats.rs Document why CodeStats::type_sizes is public 2025-04-21 17:36:36 +02:00
config.rs Temporarily add back -Zwasm-c-abi=spec 2025-06-17 17:15:01 +00:00
cstore.rs Initial support for dynamically linked crates 2025-05-04 22:03:15 +03:00
errors.rs -Zretpoline and -Zretpoline-external-thunk flags (target modifiers) to enable retpoline-related target features 2025-06-09 21:29:59 +07:00
features.rs -Zretpoline and -Zretpoline-external-thunk flags (target modifiers) to enable retpoline-related target features 2025-06-09 21:29:59 +07:00
filesearch.rs Replace all uses of sysroot_candidates with get_or_default_sysroot 2025-06-05 16:54:10 +00:00
lib.rs -Zretpoline and -Zretpoline-external-thunk flags (target modifiers) to enable retpoline-related target features 2025-06-09 21:29:59 +07:00
options.rs Rollup merge of #135656 - joshtriplett:hint-mostly-unused, r=saethlin 2025-06-18 19:40:30 +02:00
output.rs Initial support for dynamically linked crates 2025-05-04 22:03:15 +03:00
parse.rs refactor AttributeGate and rustc_attr! to emit notes during feature checking 2025-06-09 11:44:24 +02:00
search_paths.rs Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
session.rs Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
utils.rs session: Cleanup CanonicalizedPath::new 2025-04-26 18:42:15 +03:00