@@ -209,6 +209,7 @@ use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
209
209
use trans_item:: { TransItem , DefPathBasedNames , InstantiationMode } ;
210
210
211
211
use rustc_data_structures:: bitvec:: BitVector ;
212
+ use back:: symbol_export:: ExportedSymbols ;
212
213
213
214
#[ derive( PartialEq , Eq , Hash , Clone , Copy , Debug ) ]
214
215
pub enum TransItemCollectionMode {
@@ -293,13 +294,14 @@ impl<'tcx> InliningMap<'tcx> {
293
294
}
294
295
295
296
pub fn collect_crate_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > ,
297
+ exported_symbols : & ExportedSymbols ,
296
298
mode : TransItemCollectionMode )
297
299
-> ( FxHashSet < TransItem < ' tcx > > ,
298
300
InliningMap < ' tcx > ) {
299
301
// We are not tracking dependencies of this pass as it has to be re-executed
300
302
// every time no matter what.
301
303
scx. tcx ( ) . dep_graph . with_ignore ( || {
302
- let roots = collect_roots ( scx, mode) ;
304
+ let roots = collect_roots ( scx, exported_symbols , mode) ;
303
305
304
306
debug ! ( "Building translation item graph, beginning at roots" ) ;
305
307
let mut visited = FxHashSet ( ) ;
@@ -321,6 +323,7 @@ pub fn collect_crate_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
321
323
// Find all non-generic items by walking the HIR. These items serve as roots to
322
324
// start monomorphizing from.
323
325
fn collect_roots < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > ,
326
+ exported_symbols : & ExportedSymbols ,
324
327
mode : TransItemCollectionMode )
325
328
-> Vec < TransItem < ' tcx > > {
326
329
debug ! ( "Collecting roots" ) ;
@@ -330,6 +333,7 @@ fn collect_roots<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
330
333
let mut visitor = RootCollector {
331
334
scx : scx,
332
335
mode : mode,
336
+ exported_symbols,
333
337
output : & mut roots,
334
338
} ;
335
339
@@ -853,6 +857,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
853
857
854
858
struct RootCollector < ' b , ' a : ' b , ' tcx : ' a + ' b > {
855
859
scx : & ' b SharedCrateContext < ' a , ' tcx > ,
860
+ exported_symbols : & ' b ExportedSymbols ,
856
861
mode : TransItemCollectionMode ,
857
862
output : & ' b mut Vec < TransItem < ' tcx > > ,
858
863
}
@@ -908,20 +913,19 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
908
913
// const items only generate translation items if they are
909
914
// actually used somewhere. Just declaring them is insufficient.
910
915
}
911
- hir:: ItemFn ( _, _, constness, _, ref generics, _) => {
912
- let is_const = match constness {
913
- hir:: Constness :: Const => true ,
914
- hir:: Constness :: NotConst => false ,
915
- } ;
916
+ hir:: ItemFn ( ..) => {
917
+ let tcx = self . scx . tcx ( ) ;
918
+ let def_id = tcx. hir . local_def_id ( item. id ) ;
916
919
917
- if !generics. is_type_parameterized ( ) &&
918
- ( !is_const || self . mode == TransItemCollectionMode :: Eager ) {
919
- let def_id = self . scx . tcx ( ) . hir . local_def_id ( item. id ) ;
920
+ if ( self . mode == TransItemCollectionMode :: Eager ||
921
+ !tcx. is_const_fn ( def_id) ||
922
+ self . exported_symbols . local_exports ( ) . contains ( & item. id ) ) &&
923
+ !item_has_type_parameters ( tcx, def_id) {
920
924
921
925
debug ! ( "RootCollector: ItemFn({})" ,
922
- def_id_to_string( self . scx . tcx( ) , def_id) ) ;
926
+ def_id_to_string( tcx, def_id) ) ;
923
927
924
- let instance = Instance :: mono ( self . scx . tcx ( ) , def_id) ;
928
+ let instance = Instance :: mono ( tcx, def_id) ;
925
929
self . output . push ( TransItem :: Fn ( instance) ) ;
926
930
}
927
931
}
@@ -935,39 +939,18 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
935
939
936
940
fn visit_impl_item ( & mut self , ii : & ' v hir:: ImplItem ) {
937
941
match ii. node {
938
- hir:: ImplItemKind :: Method ( hir:: MethodSig {
939
- constness,
940
- ref generics,
941
- ..
942
- } , _) => {
943
- let hir_map = & self . scx . tcx ( ) . hir ;
944
- let parent_node_id = hir_map. get_parent_node ( ii. id ) ;
945
- let is_impl_generic = || match hir_map. expect_item ( parent_node_id) {
946
- & hir:: Item {
947
- node : hir:: ItemImpl ( _, _, _, ref generics, ..) ,
948
- ..
949
- } => {
950
- generics. is_type_parameterized ( )
951
- }
952
- _ => {
953
- bug ! ( )
954
- }
955
- } ;
956
-
957
- let is_const = match constness {
958
- hir:: Constness :: Const => true ,
959
- hir:: Constness :: NotConst => false ,
960
- } ;
961
-
962
- if ( !is_const || self . mode == TransItemCollectionMode :: Eager ) &&
963
- !generics. is_type_parameterized ( ) &&
964
- !is_impl_generic ( ) {
965
- let def_id = self . scx . tcx ( ) . hir . local_def_id ( ii. id ) ;
942
+ hir:: ImplItemKind :: Method ( hir:: MethodSig { .. } , _) => {
943
+ let tcx = self . scx . tcx ( ) ;
944
+ let def_id = tcx. hir . local_def_id ( ii. id ) ;
966
945
946
+ if ( self . mode == TransItemCollectionMode :: Eager ||
947
+ !tcx. is_const_fn ( def_id) ||
948
+ self . exported_symbols . local_exports ( ) . contains ( & ii. id ) ) &&
949
+ !item_has_type_parameters ( tcx, def_id) {
967
950
debug ! ( "RootCollector: MethodImplItem({})" ,
968
- def_id_to_string( self . scx . tcx( ) , def_id) ) ;
951
+ def_id_to_string( tcx, def_id) ) ;
969
952
970
- let instance = Instance :: mono ( self . scx . tcx ( ) , def_id) ;
953
+ let instance = Instance :: mono ( tcx, def_id) ;
971
954
self . output . push ( TransItem :: Fn ( instance) ) ;
972
955
}
973
956
}
@@ -976,6 +959,11 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
976
959
}
977
960
}
978
961
962
+ fn item_has_type_parameters < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> bool {
963
+ let generics = tcx. generics_of ( def_id) ;
964
+ generics. parent_types as usize + generics. types . len ( ) > 0
965
+ }
966
+
979
967
fn create_trans_items_for_default_impls < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > ,
980
968
item : & ' tcx hir:: Item ,
981
969
output : & mut Vec < TransItem < ' tcx > > ) {
0 commit comments