@@ -2350,6 +2350,11 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
2350
2350
2351
2351
#[ instrument( level = "trace" , skip( tcx) ) ]
2352
2352
pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path , ref_path : Option < & Path > ) {
2353
+ // Since encoding metadata is not in a query, and nothing is cached,
2354
+ // there's no need to do dep-graph tracking for any of it.
2355
+ tcx. dep_graph . assert_ignored ( ) ;
2356
+
2357
+ // Generate the metadata stub manually, as that is a small file compared to full metadata.
2353
2358
if let Some ( ref_path) = ref_path {
2354
2359
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata_stub" ) ;
2355
2360
@@ -2362,11 +2367,14 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2362
2367
is_stub : true ,
2363
2368
} ) ;
2364
2369
header. position . get ( )
2365
- } ) ;
2370
+ } )
2366
2371
}
2367
2372
2373
+ let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2374
+
2368
2375
let dep_node = tcx. metadata_dep_node ( ) ;
2369
2376
2377
+ // If the metadata dep-node is green, try to reuse the saved work product.
2370
2378
if tcx. dep_graph . is_fully_enabled ( )
2371
2379
&& let work_product_id = WorkProductId :: from_cgu_name ( "metadata" )
2372
2380
&& let Some ( work_product) = tcx. dep_graph . previous_work_product ( & work_product_id)
@@ -2383,19 +2391,15 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2383
2391
return ;
2384
2392
} ;
2385
2393
2386
- let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2387
-
2388
- // Since encoding metadata is not in a query, and nothing is cached,
2389
- // there's no need to do dep-graph tracking for any of it.
2390
- tcx. dep_graph . assert_ignored ( ) ;
2391
-
2392
2394
if tcx. sess . threads ( ) != 1 {
2393
2395
// Prefetch some queries used by metadata encoding.
2394
2396
// This is not necessary for correctness, but is only done for performance reasons.
2395
2397
// It can be removed if it turns out to cause trouble or be detrimental to performance.
2396
2398
join ( || prefetch_mir ( tcx) , || tcx. exported_symbols ( LOCAL_CRATE ) ) ;
2397
2399
}
2398
2400
2401
+ // Perform metadata encoding inside a task, so the dep-graph can check if any encoded
2402
+ // information changes, and maybe reuse the work product.
2399
2403
tcx. dep_graph . with_task (
2400
2404
dep_node,
2401
2405
tcx,
@@ -2416,7 +2420,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2416
2420
) ;
2417
2421
2418
2422
root. position . get ( )
2419
- } ) ;
2423
+ } )
2420
2424
} ,
2421
2425
None ,
2422
2426
) ;
0 commit comments