@@ -2424,11 +2424,7 @@ fn contains_null(s: &str) -> bool {
24242424 s. bytes ( ) . any ( |b| b == 0 )
24252425}
24262426
2427- pub fn write_metadata < ' a , ' tcx > ( cx : & SharedCrateContext < ' a , ' tcx > ,
2428- krate : & hir:: Crate ,
2429- reachable : & NodeSet ,
2430- mir_map : & MirMap < ' tcx > )
2431- -> Vec < u8 > {
2427+ pub fn write_metadata < ' a , ' tcx > ( cx : & SharedCrateContext < ' a , ' tcx > ) -> Vec < u8 > {
24322428 use flate;
24332429
24342430 let any_library = cx. sess ( )
@@ -2444,9 +2440,9 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
24442440 let metadata = cstore. encode_metadata ( cx. tcx ( ) ,
24452441 cx. export_map ( ) ,
24462442 cx. link_meta ( ) ,
2447- reachable,
2448- mir_map,
2449- krate) ;
2443+ cx . reachable ( ) ,
2444+ cx . mir_map ( ) ,
2445+ cx . tcx ( ) . map . krate ( ) ) ;
24502446 let mut compressed = cstore. metadata_encoding_version ( ) . to_vec ( ) ;
24512447 compressed. extend_from_slice ( & flate:: deflate_bytes ( & metadata) ) ;
24522448
@@ -2679,6 +2675,16 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26792675 reachable,
26802676 check_overflow,
26812677 check_dropflag) ;
2678+ // Translate the metadata.
2679+ let metadata = time ( tcx. sess . time_passes ( ) , "write metadata" , || {
2680+ write_metadata ( & shared_ccx)
2681+ } ) ;
2682+
2683+ let metadata_module = ModuleTranslation {
2684+ llcx : shared_ccx. metadata_llcx ( ) ,
2685+ llmod : shared_ccx. metadata_llmod ( ) ,
2686+ } ;
2687+ let no_builtins = attr:: contains_name ( & krate. attrs , "no_builtins" ) ;
26822688
26832689 let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
26842690 let codegen_unit_count = codegen_units. len ( ) ;
@@ -2687,6 +2693,24 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26872693
26882694 let crate_context_list = CrateContextList :: new ( & shared_ccx, codegen_units) ;
26892695
2696+ let modules = crate_context_list. iter ( )
2697+ . map ( |ccx| ModuleTranslation { llcx : ccx. llcx ( ) , llmod : ccx. llmod ( ) } )
2698+ . collect ( ) ;
2699+
2700+ // Skip crate items and just output metadata in -Z no-trans mode.
2701+ if tcx. sess . opts . no_trans {
2702+ let linker_info = LinkerInfo :: new ( & shared_ccx, & [ ] ) ;
2703+ return CrateTranslation {
2704+ modules : modules,
2705+ metadata_module : metadata_module,
2706+ link : link_meta,
2707+ metadata : metadata,
2708+ reachable : vec ! [ ] ,
2709+ no_builtins : no_builtins,
2710+ linker_info : linker_info
2711+ } ;
2712+ }
2713+
26902714 {
26912715 let ccx = crate_context_list. get_ccx ( 0 ) ;
26922716
@@ -2718,10 +2742,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27182742
27192743 let reachable_symbol_ids = filter_reachable_ids ( & shared_ccx) ;
27202744
2721- // Translate the metadata.
2722- let metadata = time ( tcx. sess . time_passes ( ) , "write metadata" , || {
2723- write_metadata ( & shared_ccx, krate, & reachable_symbol_ids, mir_map)
2724- } ) ;
27252745
27262746 if shared_ccx. sess ( ) . trans_stats ( ) {
27272747 let stats = shared_ccx. stats ( ) ;
@@ -2752,10 +2772,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27522772 }
27532773 }
27542774
2755- let modules = crate_context_list. iter ( )
2756- . map ( |ccx| ModuleTranslation { llcx : ccx. llcx ( ) , llmod : ccx. llmod ( ) } )
2757- . collect ( ) ;
2758-
27592775 let sess = shared_ccx. sess ( ) ;
27602776 let mut reachable_symbols = reachable_symbol_ids. iter ( ) . map ( |& id| {
27612777 let def_id = shared_ccx. tcx ( ) . map . local_def_id ( id) ;
@@ -2789,12 +2805,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27892805 create_imps ( & crate_context_list) ;
27902806 }
27912807
2792- let metadata_module = ModuleTranslation {
2793- llcx : shared_ccx. metadata_llcx ( ) ,
2794- llmod : shared_ccx. metadata_llmod ( ) ,
2795- } ;
2796- let no_builtins = attr:: contains_name ( & krate. attrs , "no_builtins" ) ;
2797-
27982808 let linker_info = LinkerInfo :: new ( & shared_ccx, & reachable_symbols) ;
27992809 CrateTranslation {
28002810 modules : modules,
0 commit comments