@@ -2163,15 +2163,36 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
2163
2163
}
2164
2164
}
2165
2165
2166
+ #[ instrument( level = "trace" , skip( tcx) ) ]
2166
2167
pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path ) {
2168
+ let dep_node = tcx. metadata_dep_node ( ) ;
2169
+
2170
+ if tcx. dep_graph . is_fully_enabled ( )
2171
+ && let work_product_id = & rustc_middle:: dep_graph:: WorkProductId :: from_cgu_name ( "metadata" )
2172
+ && let Some ( work_product) = tcx. dep_graph . previous_work_product ( work_product_id)
2173
+ && tcx. try_mark_green ( & dep_node)
2174
+ {
2175
+ let saved_path = & work_product. saved_files [ "rmeta" ] ;
2176
+ let incr_comp_session_dir = tcx. sess . incr_comp_session_dir_opt ( ) . unwrap ( ) ;
2177
+ let source_file = rustc_incremental:: in_incr_comp_dir ( & incr_comp_session_dir, saved_path) ;
2178
+ debug ! ( "copying preexisting metadata from {source_file:?} to {path:?}" ) ;
2179
+ match rustc_fs_util:: link_or_copy ( & source_file, path) {
2180
+ Ok ( _) => { }
2181
+ Err ( err) => {
2182
+ tcx. sess . emit_fatal ( FailCreateFileEncoder { err } ) ;
2183
+ }
2184
+ } ;
2185
+ return ;
2186
+ } ;
2187
+
2167
2188
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2168
2189
2169
2190
// Since encoding metadata is not in a query, and nothing is cached,
2170
2191
// there's no need to do dep-graph tracking for any of it.
2171
2192
tcx. dep_graph . assert_ignored ( ) ;
2172
2193
2173
2194
join (
2174
- || encode_metadata_impl ( tcx, path) ,
2195
+ || tcx . dep_graph . with_task ( dep_node , tcx, path, encode_metadata_impl , None ) ,
2175
2196
|| {
2176
2197
if tcx. sess . threads ( ) == 1 {
2177
2198
return ;
0 commit comments