1
1
use crate :: dep_graph:: { DepConstructor , DepNode , WorkProduct , WorkProductId } ;
2
2
use crate :: ich:: { NodeIdHashingMode , StableHashingContext } ;
3
3
use crate :: ty:: { subst:: InternalSubsts , Instance , InstanceDef , SymbolName , TyCtxt } ;
4
- use rustc_attr:: InlineAttr ;
5
4
use rustc_data_structures:: base_n;
6
5
use rustc_data_structures:: fingerprint:: Fingerprint ;
7
6
use rustc_data_structures:: fx:: FxHashMap ;
@@ -79,14 +78,6 @@ impl<'tcx> MonoItem<'tcx> {
79
78
}
80
79
81
80
pub fn instantiation_mode ( & self , tcx : TyCtxt < ' tcx > ) -> InstantiationMode {
82
- let generate_cgu_internal_copies = tcx
83
- . sess
84
- . opts
85
- . debugging_opts
86
- . inline_in_all_cgus
87
- . unwrap_or_else ( || tcx. sess . opts . optimize != OptLevel :: No )
88
- && !tcx. sess . link_dead_code ( ) ;
89
-
90
81
match * self {
91
82
MonoItem :: Fn ( ref instance) => {
92
83
let entry_def_id = tcx. entry_fn ( LOCAL_CRATE ) . map ( |( id, _) | id) ;
@@ -99,21 +90,26 @@ impl<'tcx> MonoItem<'tcx> {
99
90
return InstantiationMode :: GloballyShared { may_conflict : false } ;
100
91
}
101
92
93
+ let generate_cgu_internal_copies = tcx
94
+ . sess
95
+ . opts
96
+ . debugging_opts
97
+ . inline_in_all_cgus
98
+ . unwrap_or_else ( || tcx. sess . opts . optimize != OptLevel :: No )
99
+ && !tcx. sess . link_dead_code ( ) ;
100
+
102
101
// At this point we don't have explicit linkage and we're an
103
- // inlined function. If we're inlining into all CGUs then we'll
104
- // be creating a local copy per CGU.
102
+ // inlined function. If we should generate local copies for each CGU,
103
+ // then return `LocalCopy`, otherwise we'll just generate one copy
104
+ // and share it with all CGUs in this crate.
105
105
if generate_cgu_internal_copies {
106
- return InstantiationMode :: LocalCopy ;
107
- }
108
-
109
- // Finally, if this is `#[inline(always)]` we're sure to respect
110
- // that with an inline copy per CGU, but otherwise we'll be
111
- // creating one copy of this `#[inline]` function which may
112
- // conflict with upstream crates as it could be an exported
113
- // symbol.
114
- match tcx. codegen_fn_attrs ( instance. def_id ( ) ) . inline {
115
- InlineAttr :: Always => InstantiationMode :: LocalCopy ,
116
- _ => InstantiationMode :: GloballyShared { may_conflict : true } ,
106
+ InstantiationMode :: LocalCopy
107
+ } else {
108
+ // Finally, if we've reached this point, then we should optimize for
109
+ // compilation speed. In that regard, we will ignore any `#[inline]`
110
+ // annotations on the function and simply codegen it as usual. This could
111
+ // conflict with upstream crates as it could be an exported symbol.
112
+ InstantiationMode :: GloballyShared { may_conflict : true }
117
113
}
118
114
}
119
115
MonoItem :: Static ( ..) | MonoItem :: GlobalAsm ( ..) => {
0 commit comments