Skip to content

Commit 490e6ad

Browse files
committed
Add comment and move assertion.
1 parent 8cadc54 commit 490e6ad

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,11 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
23892389

23902390
#[instrument(level = "trace", skip(tcx))]
23912391
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.
23922397
if let Some(ref_path) = ref_path {
23932398
let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata_stub");
23942399

@@ -2401,11 +2406,14 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
24012406
is_stub: true,
24022407
});
24032408
header.position.get()
2404-
});
2409+
})
24052410
}
24062411

2412+
let _prof_timer = tcx.prof.verbose_generic_activity("generate_crate_metadata");
2413+
24072414
let dep_node = tcx.metadata_dep_node();
24082415

2416+
// If the metadata dep-node is green, try to reuse the saved work product.
24092417
if tcx.dep_graph.is_fully_enabled()
24102418
&& let work_product_id = WorkProductId::from_cgu_name("metadata")
24112419
&& 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>) {
24222430
return;
24232431
};
24242432

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-
24312433
if tcx.sess.threads() != 1 {
24322434
// Prefetch some queries used by metadata encoding.
24332435
// 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>) {
24412443
);
24422444
}
24432445

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.
24442448
tcx.dep_graph.with_task(
24452449
dep_node,
24462450
tcx,
@@ -2461,7 +2465,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
24612465
);
24622466

24632467
root.position.get()
2464-
});
2468+
})
24652469
},
24662470
None,
24672471
);

0 commit comments

Comments
 (0)