@@ -2386,7 +2386,43 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
2386
2386
}
2387
2387
}
2388
2388
2389
+ #[ instrument( level = "trace" , skip( tcx) ) ]
2389
2390
pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path , ref_path : Option < & Path > ) {
2391
+ if let Some ( ref_path) = ref_path {
2392
+ let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata_stub" ) ;
2393
+
2394
+ with_encode_metadata_header ( tcx, ref_path, |ecx| {
2395
+ let header: LazyValue < CrateHeader > = ecx. lazy ( CrateHeader {
2396
+ name : tcx. crate_name ( LOCAL_CRATE ) ,
2397
+ triple : tcx. sess . opts . target_triple . clone ( ) ,
2398
+ hash : tcx. crate_hash ( LOCAL_CRATE ) ,
2399
+ is_proc_macro_crate : false ,
2400
+ is_stub : true ,
2401
+ } ) ;
2402
+ header. position . get ( )
2403
+ } ) ;
2404
+ }
2405
+
2406
+ let dep_node = tcx. metadata_dep_node ( ) ;
2407
+
2408
+ if tcx. dep_graph . is_fully_enabled ( )
2409
+ && let work_product_id = & rustc_middle:: dep_graph:: WorkProductId :: from_cgu_name ( "metadata" )
2410
+ && let Some ( work_product) = tcx. dep_graph . previous_work_product ( work_product_id)
2411
+ && tcx. try_mark_green ( & dep_node)
2412
+ {
2413
+ let saved_path = & work_product. saved_files [ "rmeta" ] ;
2414
+ let incr_comp_session_dir = tcx. sess . incr_comp_session_dir_opt ( ) . unwrap ( ) ;
2415
+ let source_file = rustc_incremental:: in_incr_comp_dir ( & incr_comp_session_dir, saved_path) ;
2416
+ debug ! ( "copying preexisting metadata from {source_file:?} to {path:?}" ) ;
2417
+ match rustc_fs_util:: link_or_copy ( & source_file, path) {
2418
+ Ok ( _) => { }
2419
+ Err ( err) => {
2420
+ tcx. dcx ( ) . emit_fatal ( FailCreateFileEncoder { err } ) ;
2421
+ }
2422
+ } ;
2423
+ return ;
2424
+ } ;
2425
+
2390
2426
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2391
2427
2392
2428
// Since encoding metadata is not in a query, and nothing is cached,
@@ -2406,35 +2442,30 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
2406
2442
) ;
2407
2443
}
2408
2444
2409
- with_encode_metadata_header ( tcx, path, |ecx| {
2410
- // Encode all the entries and extra information in the crate,
2411
- // culminating in the `CrateRoot` which points to all of it.
2412
- let root = ecx. encode_crate_root ( ) ;
2413
-
2414
- // Flush buffer to ensure backing file has the correct size.
2415
- ecx. opaque . flush ( ) ;
2416
- // Record metadata size for self-profiling
2417
- tcx. prof . artifact_size (
2418
- "crate_metadata" ,
2419
- "crate_metadata" ,
2420
- ecx. opaque . file ( ) . metadata ( ) . unwrap ( ) . len ( ) ,
2421
- ) ;
2422
-
2423
- root. position . get ( )
2424
- } ) ;
2445
+ tcx. dep_graph . with_task (
2446
+ dep_node,
2447
+ tcx,
2448
+ path,
2449
+ |tcx, path| {
2450
+ with_encode_metadata_header ( tcx, path, |ecx| {
2451
+ // Encode all the entries and extra information in the crate,
2452
+ // culminating in the `CrateRoot` which points to all of it.
2453
+ let root = ecx. encode_crate_root ( ) ;
2454
+
2455
+ // Flush buffer to ensure backing file has the correct size.
2456
+ ecx. opaque . flush ( ) ;
2457
+ // Record metadata size for self-profiling
2458
+ tcx. prof . artifact_size (
2459
+ "crate_metadata" ,
2460
+ "crate_metadata" ,
2461
+ ecx. opaque . file ( ) . metadata ( ) . unwrap ( ) . len ( ) ,
2462
+ ) ;
2425
2463
2426
- if let Some ( ref_path) = ref_path {
2427
- with_encode_metadata_header ( tcx, ref_path, |ecx| {
2428
- let header: LazyValue < CrateHeader > = ecx. lazy ( CrateHeader {
2429
- name : tcx. crate_name ( LOCAL_CRATE ) ,
2430
- triple : tcx. sess . opts . target_triple . clone ( ) ,
2431
- hash : tcx. crate_hash ( LOCAL_CRATE ) ,
2432
- is_proc_macro_crate : false ,
2433
- is_stub : true ,
2464
+ root. position . get ( )
2434
2465
} ) ;
2435
- header . position . get ( )
2436
- } ) ;
2437
- }
2466
+ } ,
2467
+ None ,
2468
+ ) ;
2438
2469
}
2439
2470
2440
2471
fn with_encode_metadata_header (
0 commit comments