@@ -219,7 +219,7 @@ use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
219219use rustc_hir:: lang_items:: LangItem ;
220220use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
221221use rustc_middle:: mir:: interpret:: { AllocId , ErrorHandled , GlobalAlloc , Scalar } ;
222- use rustc_middle:: mir:: mono:: { InstantiationMode , MonoItem } ;
222+ use rustc_middle:: mir:: mono:: { CollectionMode , InstantiationMode , MonoItem } ;
223223use rustc_middle:: mir:: visit:: Visitor as MirVisitor ;
224224use rustc_middle:: mir:: { self , Location , MentionedItem , traversal} ;
225225use rustc_middle:: query:: TyCtxtAt ;
@@ -268,24 +268,6 @@ struct SharedState<'tcx> {
268268 usage_map : MTLock < UsageMap < ' tcx > > ,
269269}
270270
271- /// See module-level docs on some contect for "mentioned" items.
272- #[ derive( Copy , Clone , Debug , PartialEq ) ]
273- enum CollectionMode {
274- /// Collect items that are used, i.e., actually needed for codegen.
275- ///
276- /// Which items are used can depend on optimization levels, as MIR optimizations can remove
277- /// uses.
278- UsedItems ,
279- /// Collect items that are mentioned. The goal of this mode is that it is independent of
280- /// optimizations: the set of "mentioned" items is computed before optimizations are run.
281- ///
282- /// The exact contents of this set are *not* a stable guarantee. (For instance, it is currently
283- /// computed after drop-elaboration. If we ever do some optimizations even in debug builds, we
284- /// might decide to run them before computing mentioned items.) The key property of this set is
285- /// that it is optimization-independent.
286- MentionedItems ,
287- }
288-
289271impl < ' tcx > UsageMap < ' tcx > {
290272 fn new ( ) -> UsageMap < ' tcx > {
291273 UsageMap { used_map : Default :: default ( ) , user_map : Default :: default ( ) }
@@ -447,13 +429,9 @@ fn collect_items_rec<'tcx>(
447429 ) ) ;
448430
449431 rustc_data_structures:: stack:: ensure_sufficient_stack ( || {
450- collect_items_of_instance (
451- tcx,
452- instance,
453- & mut used_items,
454- & mut mentioned_items,
455- mode,
456- )
432+ let ( used, mentioned) = tcx. items_of_instance ( ( instance, mode) ) ;
433+ used_items. extend ( used) ;
434+ mentioned_items. extend ( mentioned) ;
457435 } ) ;
458436 }
459437 MonoItem :: GlobalAsm ( item_id) => {
@@ -1253,6 +1231,16 @@ fn collect_items_of_instance<'tcx>(
12531231 }
12541232}
12551233
1234+ fn items_of_instance < ' tcx > (
1235+ tcx : TyCtxt < ' tcx > ,
1236+ ( instance, mode) : ( Instance < ' tcx > , CollectionMode ) ,
1237+ ) -> ( & ' tcx [ Spanned < MonoItem < ' tcx > > ] , & ' tcx [ Spanned < MonoItem < ' tcx > > ] ) {
1238+ let mut used_items = MonoItems :: default ( ) ;
1239+ let mut mentioned_items = MonoItems :: default ( ) ;
1240+ collect_items_of_instance ( tcx, instance, & mut used_items, & mut mentioned_items, mode) ;
1241+ ( tcx. arena . alloc_slice ( & used_items) , tcx. arena . alloc_slice ( & mentioned_items) )
1242+ }
1243+
12561244/// `item` must be already monomorphized.
12571245#[ instrument( skip( tcx, span, output) , level = "debug" ) ]
12581246fn visit_mentioned_item < ' tcx > (
@@ -1623,4 +1611,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16231611
16241612pub ( crate ) fn provide ( providers : & mut Providers ) {
16251613 providers. hooks . should_codegen_locally = should_codegen_locally;
1614+ providers. items_of_instance = items_of_instance;
16261615}
0 commit comments