about summary refs log tree commit diff
path: root/compiler/rustc_interface
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-10-18 02:00:44 +0000
committerbors <bors@rust-lang.org>2023-10-18 02:00:44 +0000
commit5d5edf0248d967baa6ac5cbea09b91c7c9947942 (patch)
treef25d7284cfee91d52927cec8f62b66516990ed21 /compiler/rustc_interface
parentca89f732ec0f910fc92111a45dd7e6829baa9d4b (diff)
parenta76cae02345a861285334446cd24c6eb9616866a (diff)
downloadrust-5d5edf0248d967baa6ac5cbea09b91c7c9947942.tar.gz
rust-5d5edf0248d967baa6ac5cbea09b91c7c9947942.zip
Auto merge of #116505 - saethlin:infer-inline, r=cjgillot
Automatically enable cross-crate inlining for small functions

This is basically reviving https://github.com/rust-lang/rust/pull/70550

The `#[inline]` attribute can have a significant impact on code generation or runtime performance (because it enables inlining between CGUs where it would normally not happen) and also on compile-time performance (because it enables MIR inlining). But it has to be added manually, which is awkward.

This PR factors whether a DefId is cross-crate inlinable into a query, and replaces all uses of `CodegenFnAttrs::requests_inline` with this new query. The new query incorporates all the other logic that is used to determine whether a Def should be treated as cross-crate-inlinable, and as a last step inspects the function's optimized_mir to determine if it should be treated as cross-crate-inlinable.

The heuristic implemented here is deliberately conservative; we only infer inlinability for functions whose optimized_mir does not contain any calls or asserts. I plan to study adjusting the cost model later, but for now the compile time implications of this change are so significant that I think this very crude heuristic is well worth landing.
Diffstat (limited to 'compiler/rustc_interface')
-rw-r--r--compiler/rustc_interface/src/tests.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs
index 7799af37008..ec4fd78994e 100644
--- a/compiler/rustc_interface/src/tests.rs
+++ b/compiler/rustc_interface/src/tests.rs
@@ -770,6 +770,7 @@ fn test_unstable_options_tracking_hash() {
     );
     tracked!(codegen_backend, Some("abc".to_string()));
     tracked!(crate_attr, vec!["abc".to_string()]);
+    tracked!(cross_crate_inline_threshold, Some(200));
     tracked!(debug_info_for_profiling, true);
     tracked!(debug_macros, true);
     tracked!(dep_info_omit_d_target, true);