Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c47d3f4

Browse files
committed
Don't add inlinehint to big closures
1 parent 92c6c03 commit c47d3f4

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,14 @@ pub fn from_fn_attrs<'ll, 'tcx>(
337337
OptimizeAttr::Speed => {}
338338
}
339339

340-
let inline =
341-
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
342-
InlineAttr::Hint
343-
} else {
344-
codegen_fn_attrs.inline
345-
};
340+
let inline = if codegen_fn_attrs.inline == InlineAttr::None
341+
&& (cx.tcx.cross_crate_inlinable(instance.def_id())
342+
|| matches!(instance.def, rustc_middle::ty::InstanceKind::CloneShim(..)))
343+
{
344+
InlineAttr::Hint
345+
} else {
346+
codegen_fn_attrs.inline
347+
};
346348
to_add.extend(inline_attr(cx, inline));
347349

348350
// The `uwtable` attribute according to LLVM is:

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,7 @@ impl<'tcx> InstanceKind<'tcx> {
300300
ty::InstanceKind::ThreadLocalShim(_) => return false,
301301
_ => return true,
302302
};
303-
matches!(
304-
tcx.def_key(def_id).disambiguated_data.data,
305-
DefPathData::Ctor | DefPathData::Closure
306-
)
303+
matches!(tcx.def_key(def_id).disambiguated_data.data, DefPathData::Ctor)
307304
}
308305

309306
/// Returns `true` if the machine code for this instance is instantiated in

compiler/rustc_mir_transform/src/cross_crate_inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
2525

2626
// This just reproduces the logic from Instance::requires_inline.
2727
match tcx.def_kind(def_id) {
28-
DefKind::Ctor(..) | DefKind::Closure => return true,
29-
DefKind::Fn | DefKind::AssocFn => {}
28+
DefKind::Ctor(..) => return true,
29+
DefKind::Fn | DefKind::AssocFn | DefKind::Closure => {}
3030
_ => return false,
3131
}
3232

tests/coverage/closure.cov-map

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,16 @@ Number of file 0 mappings: 24
3131
= (c0 - c1)
3232
- Code(Counter(0)) at (prev + 1, 5) to (start + 3, 2)
3333

34-
Function name: closure::main::{closure#0}
35-
Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 28, 05, 02, 14, 05, 02, 15, 02, 0a, 02, 02, 0a, 00, 0b, 01, 01, 09, 01, 06]
34+
Function name: closure::main::{closure#0} (unused)
35+
Raw bytes (24): 0x[01, 01, 00, 04, 00, 28, 05, 02, 14, 00, 02, 15, 02, 0a, 00, 02, 0a, 00, 0b, 00, 01, 09, 01, 06]
3636
Number of files: 1
3737
- file 0 => global file 1
38-
Number of expressions: 1
39-
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
38+
Number of expressions: 0
4039
Number of file 0 mappings: 4
41-
- Code(Counter(0)) at (prev + 40, 5) to (start + 2, 20)
42-
- Code(Counter(1)) at (prev + 2, 21) to (start + 2, 10)
43-
- Code(Expression(0, Sub)) at (prev + 2, 10) to (start + 0, 11)
44-
= (c0 - c1)
45-
- Code(Counter(0)) at (prev + 1, 9) to (start + 1, 6)
40+
- Code(Zero) at (prev + 40, 5) to (start + 2, 20)
41+
- Code(Zero) at (prev + 2, 21) to (start + 2, 10)
42+
- Code(Zero) at (prev + 2, 10) to (start + 0, 11)
43+
- Code(Zero) at (prev + 1, 9) to (start + 1, 6)
4644

4745
Function name: closure::main::{closure#10} (unused)
4846
Raw bytes (10): 0x[01, 01, 00, 01, 00, 9b, 01, 07, 00, 21]

0 commit comments

Comments
 (0)