@@ -209,6 +209,7 @@ use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
209209use trans_item:: { TransItem , DefPathBasedNames , InstantiationMode } ;
210210
211211use rustc_data_structures:: bitvec:: BitVector ;
212+ use back:: symbol_export:: ExportedSymbols ;
212213
213214#[ derive( PartialEq , Eq , Hash , Clone , Copy , Debug ) ]
214215pub enum TransItemCollectionMode {
@@ -293,13 +294,14 @@ impl<'tcx> InliningMap<'tcx> {
293294}
294295
295296pub fn collect_crate_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > ,
297+ exported_symbols : & ExportedSymbols ,
296298 mode : TransItemCollectionMode )
297299 -> ( FxHashSet < TransItem < ' tcx > > ,
298300 InliningMap < ' tcx > ) {
299301 // We are not tracking dependencies of this pass as it has to be re-executed
300302 // every time no matter what.
301303 scx. tcx ( ) . dep_graph . with_ignore ( || {
302- let roots = collect_roots ( scx, mode) ;
304+ let roots = collect_roots ( scx, exported_symbols , mode) ;
303305
304306 debug ! ( "Building translation item graph, beginning at roots" ) ;
305307 let mut visited = FxHashSet ( ) ;
@@ -321,6 +323,7 @@ pub fn collect_crate_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
321323// Find all non-generic items by walking the HIR. These items serve as roots to
322324// start monomorphizing from.
323325fn collect_roots < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > ,
326+ exported_symbols : & ExportedSymbols ,
324327 mode : TransItemCollectionMode )
325328 -> Vec < TransItem < ' tcx > > {
326329 debug ! ( "Collecting roots" ) ;
@@ -330,6 +333,7 @@ fn collect_roots<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
330333 let mut visitor = RootCollector {
331334 scx : scx,
332335 mode : mode,
336+ exported_symbols,
333337 output : & mut roots,
334338 } ;
335339
@@ -853,6 +857,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
853857
854858struct RootCollector < ' b , ' a : ' b , ' tcx : ' a + ' b > {
855859 scx : & ' b SharedCrateContext < ' a , ' tcx > ,
860+ exported_symbols : & ' b ExportedSymbols ,
856861 mode : TransItemCollectionMode ,
857862 output : & ' b mut Vec < TransItem < ' tcx > > ,
858863}
@@ -908,20 +913,19 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
908913 // const items only generate translation items if they are
909914 // actually used somewhere. Just declaring them is insufficient.
910915 }
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 ) ;
916919
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) {
920924
921925 debug ! ( "RootCollector: ItemFn({})" ,
922- def_id_to_string( self . scx . tcx( ) , def_id) ) ;
926+ def_id_to_string( tcx, def_id) ) ;
923927
924- let instance = Instance :: mono ( self . scx . tcx ( ) , def_id) ;
928+ let instance = Instance :: mono ( tcx, def_id) ;
925929 self . output . push ( TransItem :: Fn ( instance) ) ;
926930 }
927931 }
@@ -935,39 +939,18 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
935939
936940 fn visit_impl_item ( & mut self , ii : & ' v hir:: ImplItem ) {
937941 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 ) ;
966945
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) {
967950 debug ! ( "RootCollector: MethodImplItem({})" ,
968- def_id_to_string( self . scx . tcx( ) , def_id) ) ;
951+ def_id_to_string( tcx, def_id) ) ;
969952
970- let instance = Instance :: mono ( self . scx . tcx ( ) , def_id) ;
953+ let instance = Instance :: mono ( tcx, def_id) ;
971954 self . output . push ( TransItem :: Fn ( instance) ) ;
972955 }
973956 }
@@ -976,6 +959,11 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
976959 }
977960}
978961
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+
979967fn create_trans_items_for_default_impls < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > ,
980968 item : & ' tcx hir:: Item ,
981969 output : & mut Vec < TransItem < ' tcx > > ) {
0 commit comments