@@ -2181,15 +2181,36 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
2181
2181
}
2182
2182
}
2183
2183
2184
+ #[ instrument( level = "trace" , skip( tcx) ) ]
2184
2185
pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path ) {
2186
+ let dep_node = tcx. metadata_dep_node ( ) ;
2187
+
2188
+ if tcx. dep_graph . is_fully_enabled ( )
2189
+ && let work_product_id = & rustc_middle:: dep_graph:: WorkProductId :: from_cgu_name ( "metadata" )
2190
+ && let Some ( work_product) = tcx. dep_graph . previous_work_product ( work_product_id)
2191
+ && tcx. try_mark_green ( & dep_node)
2192
+ {
2193
+ let saved_path = & work_product. saved_files [ "rmeta" ] ;
2194
+ let incr_comp_session_dir = tcx. sess . incr_comp_session_dir_opt ( ) . unwrap ( ) ;
2195
+ let source_file = rustc_incremental:: in_incr_comp_dir ( & incr_comp_session_dir, saved_path) ;
2196
+ debug ! ( "copying preexisting metadata from {source_file:?} to {path:?}" ) ;
2197
+ match rustc_fs_util:: link_or_copy ( & source_file, path) {
2198
+ Ok ( _) => { }
2199
+ Err ( err) => {
2200
+ tcx. sess . emit_fatal ( FailCreateFileEncoder { err } ) ;
2201
+ }
2202
+ } ;
2203
+ return ;
2204
+ } ;
2205
+
2185
2206
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2186
2207
2187
2208
// Since encoding metadata is not in a query, and nothing is cached,
2188
2209
// there's no need to do dep-graph tracking for any of it.
2189
2210
tcx. dep_graph . assert_ignored ( ) ;
2190
2211
2191
2212
join (
2192
- || encode_metadata_impl ( tcx, path) ,
2213
+ || tcx . dep_graph . with_task ( dep_node , tcx, path, encode_metadata_impl , None ) ,
2193
2214
|| {
2194
2215
if tcx. sess . threads ( ) == 1 {
2195
2216
return ;
0 commit comments