@@ -192,6 +192,7 @@ use rustc::hir;
192
192
use rustc:: hir:: itemlikevisit:: ItemLikeVisitor ;
193
193
194
194
use rustc:: hir:: map as hir_map;
195
+ use rustc:: hir:: def:: Def ;
195
196
use rustc:: hir:: def_id:: DefId ;
196
197
use rustc:: middle:: const_val:: ConstVal ;
197
198
use rustc:: middle:: lang_items:: { ExchangeMallocFnLangItem , StartFnLangItem } ;
@@ -301,6 +302,18 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
301
302
mode : MonoItemCollectionMode )
302
303
-> ( FxHashSet < MonoItem < ' tcx > > ,
303
304
InliningMap < ' tcx > ) {
305
+ let current_crate_is_mir_only_rlib =
306
+ if tcx. sess . opts . debugging_opts . mir_only_rlibs != Some ( false ) {
307
+ let crate_types = tcx. sess . crate_types . borrow ( ) ;
308
+ crate_types. len ( ) == 1 && crate_types[ 0 ] == config:: CrateTypeRlib
309
+ } else {
310
+ false
311
+ } ;
312
+
313
+ if current_crate_is_mir_only_rlib {
314
+ return ( FxHashSet ( ) , InliningMap :: new ( ) )
315
+ }
316
+
304
317
let roots = collect_roots ( tcx, mode) ;
305
318
306
319
debug ! ( "Building mono item graph, beginning at roots" ) ;
@@ -342,6 +355,22 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
342
355
} ;
343
356
344
357
tcx. hir . krate ( ) . visit_all_item_likes ( & mut visitor) ;
358
+
359
+ // Collect upstream roots
360
+ for & cnum in tcx. crates ( ) . iter ( ) {
361
+ if tcx. is_mir_only_rlib ( cnum) {
362
+ for & def_id in tcx. exported_symbol_ids ( cnum) . iter ( ) {
363
+ match tcx. describe_def ( def_id) {
364
+ Some ( Def :: Static ( ..) ) => {
365
+ visitor. output . push ( MonoItem :: Static ( def_id) ) ;
366
+ }
367
+ _ => {
368
+ visitor. push_if_root ( def_id) ;
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
345
374
}
346
375
347
376
// We can only translate items that are instantiable - items all of
@@ -383,7 +412,8 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
383
412
}
384
413
MonoItem :: Fn ( instance) => {
385
414
// Sanity check whether this ended up being collected accidentally
386
- debug_assert ! ( should_monomorphize_locally( tcx, & instance) ) ;
415
+ debug_assert ! ( should_monomorphize_locally( tcx, & instance) ,
416
+ "Instantiation Error: {:?}" , instance) ;
387
417
388
418
// Keep track of the monomorphization recursion depth
389
419
recursion_depth_reset = Some ( check_recursion_limit ( tcx,
@@ -736,8 +766,8 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
736
766
}
737
767
Some ( _) => true ,
738
768
None => {
739
- if tcx. is_exported_symbol ( def_id) ||
740
- tcx. is_foreign_item ( def_id)
769
+ if tcx. is_foreign_item ( def_id) ||
770
+ ( !tcx . is_mir_only_rlib ( def_id . krate ) && tcx. is_exported_symbol ( def_id) )
741
771
{
742
772
// We can link to the item in question, no instance needed
743
773
// in this crate
0 commit comments