@@ -2432,11 +2432,8 @@ fn contains_null(s: &str) -> bool {
24322432 s. bytes ( ) . any ( |b| b == 0 )
24332433}
24342434
2435- pub fn write_metadata < ' a , ' tcx > ( cx : & SharedCrateContext < ' a , ' tcx > ,
2436- krate : & hir:: Crate ,
2437- reachable : & NodeSet ,
2438- mir_map : & MirMap < ' tcx > )
2439- -> Vec < u8 > {
2435+ fn write_metadata ( cx : & SharedCrateContext ,
2436+ reachable_ids : & NodeSet ) -> Vec < u8 > {
24402437 use flate;
24412438
24422439 let any_library = cx. sess ( )
@@ -2452,9 +2449,9 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
24522449 let metadata = cstore. encode_metadata ( cx. tcx ( ) ,
24532450 cx. export_map ( ) ,
24542451 cx. link_meta ( ) ,
2455- reachable ,
2456- mir_map,
2457- krate) ;
2452+ reachable_ids ,
2453+ cx . mir_map ( ) ,
2454+ cx . tcx ( ) . map . krate ( ) ) ;
24582455 let mut compressed = cstore. metadata_encoding_version ( ) . to_vec ( ) ;
24592456 compressed. extend_from_slice ( & flate:: deflate_bytes ( & metadata) ) ;
24602457
@@ -2639,10 +2636,12 @@ pub fn filter_reachable_ids(scx: &SharedCrateContext) -> NodeSet {
26392636 node : hir:: ItemStatic ( ..) , .. } ) |
26402637 hir_map:: NodeItem ( & hir:: Item {
26412638 node : hir:: ItemFn ( ..) , .. } ) |
2642- hir_map:: NodeTraitItem ( & hir:: TraitItem {
2643- node : hir:: MethodTraitItem ( _, Some ( _) ) , .. } ) |
26442639 hir_map:: NodeImplItem ( & hir:: ImplItem {
2645- node : hir:: ImplItemKind :: Method ( ..) , .. } ) => true ,
2640+ node : hir:: ImplItemKind :: Method ( ..) , .. } ) => {
2641+ let def_id = scx. tcx ( ) . map . local_def_id ( id) ;
2642+ let scheme = scx. tcx ( ) . lookup_item_type ( def_id) ;
2643+ scheme. generics . types . is_empty ( )
2644+ }
26462645
26472646 _ => false
26482647 }
@@ -2686,13 +2685,44 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26862685 check_overflow,
26872686 check_dropflag) ;
26882687
2688+ let reachable_symbol_ids = filter_reachable_ids ( & shared_ccx) ;
2689+
2690+ // Translate the metadata.
2691+ let metadata = time ( tcx. sess . time_passes ( ) , "write metadata" , || {
2692+ write_metadata ( & shared_ccx, & reachable_symbol_ids)
2693+ } ) ;
2694+
2695+ let metadata_module = ModuleTranslation {
2696+ llcx : shared_ccx. metadata_llcx ( ) ,
2697+ llmod : shared_ccx. metadata_llmod ( ) ,
2698+ } ;
2699+ let no_builtins = attr:: contains_name ( & krate. attrs , "no_builtins" ) ;
2700+
26892701 let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
26902702 let codegen_unit_count = codegen_units. len ( ) ;
26912703 assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
26922704 tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
26932705
26942706 let crate_context_list = CrateContextList :: new ( & shared_ccx, codegen_units) ;
26952707
2708+ let modules = crate_context_list. iter ( )
2709+ . map ( |ccx| ModuleTranslation { llcx : ccx. llcx ( ) , llmod : ccx. llmod ( ) } )
2710+ . collect ( ) ;
2711+
2712+ // Skip crate items and just output metadata in -Z no-trans mode.
2713+ if tcx. sess . opts . no_trans {
2714+ let linker_info = LinkerInfo :: new ( & shared_ccx, & [ ] ) ;
2715+ return CrateTranslation {
2716+ modules : modules,
2717+ metadata_module : metadata_module,
2718+ link : link_meta,
2719+ metadata : metadata,
2720+ reachable : vec ! [ ] ,
2721+ no_builtins : no_builtins,
2722+ linker_info : linker_info
2723+ } ;
2724+ }
2725+
26962726 {
26972727 let ccx = crate_context_list. get_ccx ( 0 ) ;
26982728
@@ -2722,13 +2752,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27222752 }
27232753 }
27242754
2725- let reachable_symbol_ids = filter_reachable_ids ( & shared_ccx) ;
2726-
2727- // Translate the metadata.
2728- let metadata = time ( tcx. sess . time_passes ( ) , "write metadata" , || {
2729- write_metadata ( & shared_ccx, krate, & reachable_symbol_ids, mir_map)
2730- } ) ;
2731-
27322755 if shared_ccx. sess ( ) . trans_stats ( ) {
27332756 let stats = shared_ccx. stats ( ) ;
27342757 println ! ( "--- trans stats ---" ) ;
@@ -2758,10 +2781,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27582781 }
27592782 }
27602783
2761- let modules = crate_context_list. iter ( )
2762- . map ( |ccx| ModuleTranslation { llcx : ccx. llcx ( ) , llmod : ccx. llmod ( ) } )
2763- . collect ( ) ;
2764-
27652784 let sess = shared_ccx. sess ( ) ;
27662785 let mut reachable_symbols = reachable_symbol_ids. iter ( ) . map ( |& id| {
27672786 let def_id = shared_ccx. tcx ( ) . map . local_def_id ( id) ;
@@ -2802,12 +2821,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
28022821 create_imps ( & crate_context_list) ;
28032822 }
28042823
2805- let metadata_module = ModuleTranslation {
2806- llcx : shared_ccx. metadata_llcx ( ) ,
2807- llmod : shared_ccx. metadata_llmod ( ) ,
2808- } ;
2809- let no_builtins = attr:: contains_name ( & krate. attrs , "no_builtins" ) ;
2810-
28112824 let linker_info = LinkerInfo :: new ( & shared_ccx, & reachable_symbols) ;
28122825 CrateTranslation {
28132826 modules : modules,
0 commit comments