@@ -114,7 +114,12 @@ impl<'tcx> InstanceDef<'tcx> {
114114 tcx. get_attrs ( self . def_id ( ) )
115115 }
116116
117- pub fn is_inline ( & self , tcx : TyCtxt < ' tcx > ) -> bool {
117+ /// Returns `true` if the LLVM version of this instance is unconditionally
118+ /// marked with `inline`. This implies that a copy of this instance is
119+ /// generated in every codegen unit.
120+ /// Note that this is only a hint. See the documentation for
121+ /// `generates_cgu_internal_copy` for more information.
122+ pub fn requires_inline ( & self , tcx : TyCtxt < ' tcx > ) -> bool {
118123 use crate :: hir:: map:: DefPathData ;
119124 let def_id = match * self {
120125 ty:: InstanceDef :: Item ( def_id) => def_id,
@@ -127,8 +132,15 @@ impl<'tcx> InstanceDef<'tcx> {
127132 }
128133 }
129134
130- pub fn requires_local ( & self , tcx : TyCtxt < ' tcx > ) -> bool {
131- if self . is_inline ( tcx) {
135+ /// Returns `true` if the machine code for this instance is instantiated in
136+ /// each codegen unit that references it.
137+ /// Note that this is only a hint! The compiler can globally decide to *not*
138+ /// do this in order to speed up compilation. CGU-internal copies are
139+ /// only exist to enable inlining. If inlining is not performed (e.g. at
140+ /// `-Copt-level=0`) then the time for generating them is wasted and it's
141+ /// better to create a single copy with external linkage.
142+ pub fn generates_cgu_internal_copy ( & self , tcx : TyCtxt < ' tcx > ) -> bool {
143+ if self . requires_inline ( tcx) {
132144 return true ;
133145 }
134146 if let ty:: InstanceDef :: DropGlue ( ..) = * self {
0 commit comments