rust/compiler/rustc_mir_transform/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
..
coroutine Async drop - fix for StorageLive/StorageDead codegen for pinned async drop future 2025-06-14 15:10:08 +07:00
coverage coverage: Revert "unused local file IDs" due to empty function names 2025-05-27 23:33:29 +10:00
inline FIXME(-Znext-solver) triage 2025-06-03 14:23:56 +02:00
shim Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
abort_unwinding_calls.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
add_call_guards.rs Auto merge of #138076 - tmiasko:pred-count, r=matthewjasper 2025-03-12 22:33:54 +00:00
add_moves_for_packed_drops.rs AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
add_retag.rs Rustfmt 2025-02-08 22:12:13 +00:00
add_subtyping_projections.rs Remove some unnecessary erases 2025-05-08 16:20:57 +00:00
check_alignment.rs Extend the alignment check to borrows 2025-04-25 12:16:40 +00:00
check_call_recursion.rs Use is_lang_item and as_lang_item instead of handrolling their logic 2025-04-22 11:02:37 +00:00
check_const_item_mutation.rs Only look at trait impls in the current crate when looking for Drop impls 2025-04-02 07:30:11 +00:00
check_inline.rs don't depend on rustc_attr_parsing if rustc_data_structures will do 2025-05-09 23:16:55 +02:00
check_null.rs Extend the alignment check to borrows 2025-04-25 12:16:40 +00:00
check_packed_ref.rs use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
check_pointers.rs Rework the logic for PointerFinder::visit_place 2025-04-28 12:36:47 +00:00
cleanup_post_borrowck.rs Visit place in BackwardIncompatibleDropHint statement 2025-04-13 22:01:54 +00:00
copy_prop.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
coroutine.rs Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
cost_checker.rs Allow more top-down inlining for single-BB callees 2025-03-12 22:39:43 -07:00
cross_crate_inline.rs Add -Z hint-mostly-unused to tell rustc that most of a crate will go unused 2025-06-06 19:12:00 -07:00
ctfe_limit.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
dataflow_const_prop.rs Update InterpCx::project_field to take FieldIdx 2025-06-05 19:15:56 -07:00
dead_store_elimination.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
deduce_param_attrs.rs Remove obsolete comment from DeduceReadOnly 2025-03-04 12:26:01 +01:00
deref_separator.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
dest_prop.rs Separate Analysis and Results. 2025-04-24 11:36:07 +10:00
dump_mir.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
early_otherwise_branch.rs mir-opt: Do not create storage marks for temporary locals 2025-05-24 15:36:06 +08:00
elaborate_box_derefs.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
elaborate_drop.rs Async drop - fix for StorageLive/StorageDead codegen for pinned async drop future 2025-06-14 15:10:08 +07:00
elaborate_drops.rs AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
errors.rs Make UNNECESSARY_TRANSMUTES into a HIR lint 2025-05-25 15:57:48 +00:00
ffi_unwind_calls.rs compiler: use is_rustic_abi in mir_transform 2025-03-04 18:21:56 -08:00
function_item_references.rs Rename ClearCrossCrate::assert_crate_local. 2025-02-21 07:12:13 +11:00
gvn.rs Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
impossible_predicates.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
inline.rs don't depend on rustc_attr_parsing if rustc_data_structures will do 2025-05-09 23:16:55 +02:00
instsimplify.rs Rollup merge of #139644 - yotamofek:pr/mir_transform/instsimplify/simplify_primitive_clone, r=compiler-errors 2025-04-13 17:37:54 -04:00
jump_threading.rs Update InterpCx::project_field to take FieldIdx 2025-06-05 19:15:56 -07:00
known_panics_lint.rs AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
large_enums.rs extend allocbytes with associated type 2025-05-26 00:15:16 +02:00
lib.rs Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
lint.rs rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
lint_tail_expr_drop_order.rs Rollup merge of #140234 - nnethercote:separate-Analysis-and-Results, r=davidtwco 2025-05-07 18:19:04 +02:00
lower_intrinsics.rs intrinsics: rename min_align_of to align_of 2025-06-12 17:50:25 +02:00
lower_slice_len.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
match_branches.rs mir-opt: Do not transform non-int type in match_branches 2025-05-26 18:15:54 +08:00
mentioned_items.rs Fix binding mode problems 2025-02-22 00:13:19 +00:00
multiple_return_terminators.rs In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
nrvo.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
pass_manager.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
patch.rs Fix for async drop ice with partly dropped tuple 2025-04-29 21:41:15 +07:00
post_analysis_normalize.rs do not emit OpaqueCast projections with -Znext-solver 2025-04-17 12:15:04 +02:00
post_drop_elaboration.rs Make check_live_drops into a MirLint. 2024-09-10 09:11:17 +10:00
prettify.rs Use a closure instead of three chained iterators 2025-04-29 14:58:21 +00:00
promote_consts.rs Use newtype_index!-generated types more idiomatically 2025-04-14 16:17:06 +00:00
ref_prop.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_noop_landing_pads.rs Use a closure instead of three chained iterators 2025-04-29 14:58:21 +00:00
remove_place_mention.rs Do not optimize out SwitchInt before borrowck, or if Zmir-preserve-ub 2025-04-08 21:05:20 +00:00
remove_storage_markers.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_uninit_drops.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
remove_unneeded_drops.rs Do not optimize out SwitchInt before borrowck, or if Zmir-preserve-ub 2025-04-08 21:05:20 +00:00
remove_zsts.rs AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
required_consts.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
sanity_check.rs Move MirPass to rustc_mir_transform. 2024-09-03 16:03:46 +10:00
shim.rs Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
simplify.rs Add comment. 2025-06-16 12:31:36 +00:00
simplify_branches.rs Fix binding mode problems 2025-02-22 00:13:19 +00:00
simplify_comparison_integral.rs Fix binding mode problems 2025-02-22 00:13:19 +00:00
single_use_consts.rs Inline and replace Statement::replace_nop. 2025-02-18 13:43:43 +11:00
sroa.rs Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
ssa.rs Do not use for_each_assignment_mut to iterate over assignment statements 2025-04-02 19:27:17 +08:00
strip_debuginfo.rs Disable non-required MIR opts with optimize(none) 2025-01-23 17:40:41 +00:00
unreachable_enum_branching.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
unreachable_prop.rs Move MirPatch from rustc_middle to rustc_mir_transform. 2025-02-14 16:15:57 +11:00
validate.rs Allow transmute casts in pre-runtime-MIR 2025-06-06 16:19:38 +00:00