@@ -2432,11 +2432,8 @@ fn contains_null(s: &str) -> bool {
2432
2432
s. bytes ( ) . any ( |b| b == 0 )
2433
2433
}
2434
2434
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 > {
2440
2437
use flate;
2441
2438
2442
2439
let any_library = cx. sess ( )
@@ -2452,9 +2449,9 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
2452
2449
let metadata = cstore. encode_metadata ( cx. tcx ( ) ,
2453
2450
cx. export_map ( ) ,
2454
2451
cx. link_meta ( ) ,
2455
- reachable ,
2456
- mir_map,
2457
- krate) ;
2452
+ reachable_ids ,
2453
+ cx . mir_map ( ) ,
2454
+ cx . tcx ( ) . map . krate ( ) ) ;
2458
2455
let mut compressed = cstore. metadata_encoding_version ( ) . to_vec ( ) ;
2459
2456
compressed. extend_from_slice ( & flate:: deflate_bytes ( & metadata) ) ;
2460
2457
@@ -2639,10 +2636,12 @@ pub fn filter_reachable_ids(scx: &SharedCrateContext) -> NodeSet {
2639
2636
node : hir:: ItemStatic ( ..) , .. } ) |
2640
2637
hir_map:: NodeItem ( & hir:: Item {
2641
2638
node : hir:: ItemFn ( ..) , .. } ) |
2642
- hir_map:: NodeTraitItem ( & hir:: TraitItem {
2643
- node : hir:: MethodTraitItem ( _, Some ( _) ) , .. } ) |
2644
2639
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
+ }
2646
2645
2647
2646
_ => false
2648
2647
}
@@ -2686,13 +2685,44 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2686
2685
check_overflow,
2687
2686
check_dropflag) ;
2688
2687
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
+
2689
2701
let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
2690
2702
let codegen_unit_count = codegen_units. len ( ) ;
2691
2703
assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
2692
2704
tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
2693
2705
2694
2706
let crate_context_list = CrateContextList :: new ( & shared_ccx, codegen_units) ;
2695
2707
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
+
2696
2726
{
2697
2727
let ccx = crate_context_list. get_ccx ( 0 ) ;
2698
2728
@@ -2722,13 +2752,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2722
2752
}
2723
2753
}
2724
2754
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
-
2732
2755
if shared_ccx. sess ( ) . trans_stats ( ) {
2733
2756
let stats = shared_ccx. stats ( ) ;
2734
2757
println ! ( "--- trans stats ---" ) ;
@@ -2758,10 +2781,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2758
2781
}
2759
2782
}
2760
2783
2761
- let modules = crate_context_list. iter ( )
2762
- . map ( |ccx| ModuleTranslation { llcx : ccx. llcx ( ) , llmod : ccx. llmod ( ) } )
2763
- . collect ( ) ;
2764
-
2765
2784
let sess = shared_ccx. sess ( ) ;
2766
2785
let mut reachable_symbols = reachable_symbol_ids. iter ( ) . map ( |& id| {
2767
2786
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>,
2802
2821
create_imps ( & crate_context_list) ;
2803
2822
}
2804
2823
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
-
2811
2824
let linker_info = LinkerInfo :: new ( & shared_ccx, & reachable_symbols) ;
2812
2825
CrateTranslation {
2813
2826
modules : modules,
0 commit comments