@@ -2389,6 +2389,11 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
2389
2389
2390
2390
#[ instrument( level = "trace" , skip( tcx) ) ]
2391
2391
pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path , ref_path : Option < & Path > ) {
2392
+ // Since encoding metadata is not in a query, and nothing is cached,
2393
+ // there's no need to do dep-graph tracking for any of it.
2394
+ tcx. dep_graph . assert_ignored ( ) ;
2395
+
2396
+ // Generate the metadata stub manually, as that is a small file compared to full metadata.
2392
2397
if let Some ( ref_path) = ref_path {
2393
2398
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata_stub" ) ;
2394
2399
@@ -2401,11 +2406,14 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2401
2406
is_stub : true ,
2402
2407
} ) ;
2403
2408
header. position . get ( )
2404
- } ) ;
2409
+ } )
2405
2410
}
2406
2411
2412
+ let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2413
+
2407
2414
let dep_node = tcx. metadata_dep_node ( ) ;
2408
2415
2416
+ // If the metadata dep-node is green, try to reuse the saved work product.
2409
2417
if tcx. dep_graph . is_fully_enabled ( )
2410
2418
&& let work_product_id = WorkProductId :: from_cgu_name ( "metadata" )
2411
2419
&& let Some ( work_product) = tcx. dep_graph . previous_work_product ( & work_product_id)
@@ -2422,12 +2430,6 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2422
2430
return ;
2423
2431
} ;
2424
2432
2425
- let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2426
-
2427
- // Since encoding metadata is not in a query, and nothing is cached,
2428
- // there's no need to do dep-graph tracking for any of it.
2429
- tcx. dep_graph . assert_ignored ( ) ;
2430
-
2431
2433
if tcx. sess . threads ( ) != 1 {
2432
2434
// Prefetch some queries used by metadata encoding.
2433
2435
// This is not necessary for correctness, but is only done for performance reasons.
@@ -2441,6 +2443,8 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2441
2443
) ;
2442
2444
}
2443
2445
2446
+ // Perform metadata encoding inside a task, so the dep-graph can check if any encoded
2447
+ // information changes, and maybe reuse the work product.
2444
2448
tcx. dep_graph . with_task (
2445
2449
dep_node,
2446
2450
tcx,
@@ -2461,7 +2465,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2461
2465
) ;
2462
2466
2463
2467
root. position . get ( )
2464
- } ) ;
2468
+ } )
2465
2469
} ,
2466
2470
None ,
2467
2471
) ;
0 commit comments