@@ -2250,7 +2250,28 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
2250
2250
}
2251
2251
}
2252
2252
2253
+ #[ instrument( level = "trace" , skip( tcx) ) ]
2253
2254
pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path ) {
2255
+ let dep_node = tcx. metadata_dep_node ( ) ;
2256
+
2257
+ if tcx. dep_graph . is_fully_enabled ( )
2258
+ && let work_product_id = & rustc_middle:: dep_graph:: WorkProductId :: from_cgu_name ( "metadata" )
2259
+ && let Some ( work_product) = tcx. dep_graph . previous_work_product ( work_product_id)
2260
+ && tcx. try_mark_green ( & dep_node)
2261
+ {
2262
+ let saved_path = & work_product. saved_files [ "rmeta" ] ;
2263
+ let incr_comp_session_dir = tcx. sess . incr_comp_session_dir_opt ( ) . unwrap ( ) ;
2264
+ let source_file = rustc_incremental:: in_incr_comp_dir ( & incr_comp_session_dir, saved_path) ;
2265
+ debug ! ( "copying preexisting metadata from {source_file:?} to {path:?}" ) ;
2266
+ match rustc_fs_util:: link_or_copy ( & source_file, path) {
2267
+ Ok ( _) => { }
2268
+ Err ( err) => {
2269
+ tcx. dcx ( ) . emit_fatal ( FailCreateFileEncoder { err } ) ;
2270
+ }
2271
+ } ;
2272
+ return ;
2273
+ } ;
2274
+
2254
2275
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2255
2276
2256
2277
// Since encoding metadata is not in a query, and nothing is cached,
@@ -2264,6 +2285,10 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) {
2264
2285
join ( || prefetch_mir ( tcx) , || tcx. exported_symbols ( LOCAL_CRATE ) ) ;
2265
2286
}
2266
2287
2288
+ tcx. dep_graph . with_task ( dep_node, tcx, path, encode_metadata_impl, None ) ;
2289
+ }
2290
+
2291
+ fn encode_metadata_impl ( tcx : TyCtxt < ' _ > , path : & Path ) {
2267
2292
let mut encoder = opaque:: FileEncoder :: new ( path)
2268
2293
. unwrap_or_else ( |err| tcx. dcx ( ) . emit_fatal ( FailCreateFileEncoder { err } ) ) ;
2269
2294
encoder. emit_raw_bytes ( METADATA_HEADER ) ;
0 commit comments