@@ -324,9 +324,14 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
324
324
let mut roots = Vec :: new ( ) ;
325
325
326
326
{
327
+ let entry_fn = tcx. sess . entry_fn . borrow ( ) . map ( |( node_id, _) | {
328
+ tcx. hir . local_def_id ( node_id)
329
+ } ) ;
330
+
327
331
let mut visitor = RootCollector {
328
332
tcx,
329
333
mode,
334
+ entry_fn,
330
335
output : & mut roots,
331
336
} ;
332
337
@@ -875,6 +880,7 @@ struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
875
880
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
876
881
mode : TransItemCollectionMode ,
877
882
output : & ' b mut Vec < TransItem < ' tcx > > ,
883
+ entry_fn : Option < DefId > ,
878
884
}
879
885
880
886
impl < ' b , ' a , ' v > ItemLikeVisitor < ' v > for RootCollector < ' b , ' a , ' v > {
@@ -932,10 +938,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
932
938
let tcx = self . tcx ;
933
939
let def_id = tcx. hir . local_def_id ( item. id ) ;
934
940
935
- if ( self . mode == TransItemCollectionMode :: Eager ||
936
- !tcx. is_const_fn ( def_id) || tcx. is_exported_symbol ( def_id) ) &&
937
- !item_has_type_parameters ( tcx, def_id) {
938
-
941
+ if self . is_root ( def_id) {
939
942
debug ! ( "RootCollector: ItemFn({})" ,
940
943
def_id_to_string( tcx, def_id) ) ;
941
944
@@ -957,10 +960,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
957
960
let tcx = self . tcx ;
958
961
let def_id = tcx. hir . local_def_id ( ii. id ) ;
959
962
960
- if ( self . mode == TransItemCollectionMode :: Eager ||
961
- !tcx. is_const_fn ( def_id) ||
962
- tcx. is_exported_symbol ( def_id) ) &&
963
- !item_has_type_parameters ( tcx, def_id) {
963
+ if self . is_root ( def_id) {
964
964
debug ! ( "RootCollector: MethodImplItem({})" ,
965
965
def_id_to_string( tcx, def_id) ) ;
966
966
@@ -973,6 +973,20 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
973
973
}
974
974
}
975
975
976
+ impl < ' b , ' a , ' v > RootCollector < ' b , ' a , ' v > {
977
+ fn is_root ( & self , def_id : DefId ) -> bool {
978
+ !item_has_type_parameters ( self . tcx , def_id) && match self . mode {
979
+ TransItemCollectionMode :: Eager => {
980
+ true
981
+ }
982
+ TransItemCollectionMode :: Lazy => {
983
+ self . entry_fn == Some ( def_id) ||
984
+ self . tcx . is_exported_symbol ( def_id)
985
+ }
986
+ }
987
+ }
988
+ }
989
+
976
990
fn item_has_type_parameters < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> bool {
977
991
let generics = tcx. generics_of ( def_id) ;
978
992
generics. parent_types as usize + generics. types . len ( ) > 0
0 commit comments