@@ -24,6 +24,7 @@ use rustc_middle::{
24
24
Instance , Ty , TyCtxt ,
25
25
} ,
26
26
} ;
27
+ use rustc_session:: config:: InliningThreshold ;
27
28
use rustc_span:: def_id:: { CrateNum , DefId } ;
28
29
use rustc_span:: { Span , SpanData , Symbol } ;
29
30
use rustc_target:: abi:: { Align , Size } ;
@@ -1525,24 +1526,29 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
1525
1526
instance : Option < ty:: Instance < ' tcx > > ,
1526
1527
) -> usize {
1527
1528
let unique = if let Some ( instance) = instance {
1528
- // Functions cannot be identified by pointers, as asm-equal functions can get deduplicated
1529
- // by the linker (we set the "unnamed_addr" attribute for LLVM) and functions can be
1530
- // duplicated across crates. We thus generate a new `AllocId` for every mention of a
1531
- // function. This means that `main as fn() == main as fn()` is false, while `let x = main as
1532
- // fn(); x == x` is true. However, as a quality-of-life feature it can be useful to identify
1533
- // certain functions uniquely, e.g. for backtraces. So we identify whether codegen will
1534
- // actually emit duplicate functions. It does that when they have non-lifetime generics, or
1535
- // when they can be inlined. All other functions are given a unique address.
1536
- // This is not a stable guarantee! The `inline` attribute is a hint and cannot be relied
1537
- // upon for anything. But if we don't do this, backtraces look terrible.
1529
+ // Functions cannot be identified by pointers, as asm-equal functions can get
1530
+ // deduplicated by the linker (we set the "unnamed_addr" attribute for LLVM) and
1531
+ // functions can be duplicated across crates. We thus generate a new `AllocId` for every
1532
+ // mention of a function. This means that `main as fn() == main as fn()` is false, while
1533
+ // `let x = main as fn(); x == x` is true. However, as a quality-of-life feature it can
1534
+ // be useful to identify certain functions uniquely, e.g. for backtraces. So we identify
1535
+ // whether codegen will actually emit duplicate functions. It does that when they have
1536
+ // non-lifetime generics, or when they can be inlined. All other functions are given a
1537
+ // unique address. This is not a stable guarantee! The `inline` attribute is a hint and
1538
+ // cannot be relied upon for anything. But if we don't do this, the
1539
+ // `__rust_begin_short_backtrace`/`__rust_end_short_backtrace` logic breaks and panic
1540
+ // backtraces look terrible.
1538
1541
let is_generic = instance
1539
1542
. args
1540
1543
. into_iter ( )
1541
1544
. any ( |kind| !matches ! ( kind. unpack( ) , ty:: GenericArgKind :: Lifetime ( _) ) ) ;
1542
- let can_be_inlined = match ecx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) . inline {
1543
- InlineAttr :: Never => false ,
1544
- _ => true ,
1545
- } ;
1545
+ let can_be_inlined = matches ! (
1546
+ ecx. tcx. sess. opts. unstable_opts. cross_crate_inline_threshold,
1547
+ InliningThreshold :: Always
1548
+ ) || !matches ! (
1549
+ ecx. tcx. codegen_fn_attrs( instance. def_id( ) ) . inline,
1550
+ InlineAttr :: Never
1551
+ ) ;
1546
1552
!is_generic && !can_be_inlined
1547
1553
} else {
1548
1554
// Non-functions are never unique.
0 commit comments