Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5d5edf0

Browse files
committedOct 18, 2023
Auto merge of #116505 - saethlin:infer-inline, r=cjgillot
Automatically enable cross-crate inlining for small functions This is basically reviving #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.
2 parents ca89f73 + a76cae0 commit 5d5edf0

File tree

68 files changed

+457
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+457
-350
lines changed
 

‎compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ fn test_unstable_options_tracking_hash() {
770770
);
771771
tracked!(codegen_backend, Some("abc".to_string()));
772772
tracked!(crate_attr, vec!["abc".to_string()]);
773+
tracked!(cross_crate_inline_threshold, Some(200));
773774
tracked!(debug_info_for_profiling, true);
774775
tracked!(debug_macros, true);
775776
tracked!(dep_info_omit_d_target, true);

‎compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12731273
self.root.tables.optimized_mir.get(self, id).is_some()
12741274
}
12751275

1276+
fn cross_crate_inlinable(self, id: DefIndex) -> bool {
1277+
self.root.tables.cross_crate_inlinable.get(self, id).unwrap_or(false)
1278+
}
1279+
12761280
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
12771281
self.root
12781282
.tables

0 commit comments

Comments
 (0)
Please sign in to comment.