@@ -219,7 +219,7 @@ use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
219
219
use rustc_hir:: lang_items:: LangItem ;
220
220
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
221
221
use 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 } ;
223
223
use rustc_middle:: mir:: visit:: Visitor as MirVisitor ;
224
224
use rustc_middle:: mir:: { self , Location , MentionedItem , traversal} ;
225
225
use rustc_middle:: query:: TyCtxtAt ;
@@ -268,24 +268,6 @@ struct SharedState<'tcx> {
268
268
usage_map : MTLock < UsageMap < ' tcx > > ,
269
269
}
270
270
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
-
289
271
impl < ' tcx > UsageMap < ' tcx > {
290
272
fn new ( ) -> UsageMap < ' tcx > {
291
273
UsageMap { used_map : Default :: default ( ) , user_map : Default :: default ( ) }
@@ -447,13 +429,9 @@ fn collect_items_rec<'tcx>(
447
429
) ) ;
448
430
449
431
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) ;
457
435
} ) ;
458
436
}
459
437
MonoItem :: GlobalAsm ( item_id) => {
@@ -1253,6 +1231,16 @@ fn collect_items_of_instance<'tcx>(
1253
1231
}
1254
1232
}
1255
1233
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
+
1256
1244
/// `item` must be already monomorphized.
1257
1245
#[ instrument( skip( tcx, span, output) , level = "debug" ) ]
1258
1246
fn visit_mentioned_item < ' tcx > (
@@ -1623,4 +1611,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
1623
1611
1624
1612
pub ( crate ) fn provide ( providers : & mut Providers ) {
1625
1613
providers. hooks . should_codegen_locally = should_codegen_locally;
1614
+ providers. items_of_instance = items_of_instance;
1626
1615
}
0 commit comments