Skip to content

Commit 38bbc2c

Browse files
committed
Auto merge of #115657 - Zoxc:source-span-avoid-query, r=cjgillot
Avoid a `source_span` query when encoding Spans into query results This avoids a `source_span` query when encoding `Span`s into query results. It's not sound to execute queries here as the query caches can be locked and the dep graph is no longer writable. r? `@cjgillot`
2 parents 5ede940 + 2a5121b commit 38bbc2c

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

compiler/rustc_incremental/src/persist/save.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,6 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
4747
}
4848

4949
join(
50-
move || {
51-
sess.time("incr_comp_persist_result_cache", || {
52-
// Drop the memory map so that we can remove the file and write to it.
53-
if let Some(odc) = &tcx.query_system.on_disk_cache {
54-
odc.drop_serialized_data(tcx);
55-
}
56-
57-
file_format::save_in(sess, query_cache_path, "query cache", |e| {
58-
encode_query_cache(tcx, e)
59-
});
60-
});
61-
},
6250
move || {
6351
sess.time("incr_comp_persist_dep_graph", || {
6452
if let Err(err) = tcx.dep_graph.encode(&tcx.sess.prof) {
@@ -73,6 +61,20 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
7361
}
7462
});
7563
},
64+
move || {
65+
// We execute this after `incr_comp_persist_dep_graph` for the serial compiler
66+
// to catch any potential query execution writing to the dep graph.
67+
sess.time("incr_comp_persist_result_cache", || {
68+
// Drop the memory map so that we can remove the file and write to it.
69+
if let Some(odc) = &tcx.query_system.on_disk_cache {
70+
odc.drop_serialized_data(tcx);
71+
}
72+
73+
file_format::save_in(sess, query_cache_path, "query cache", |e| {
74+
encode_query_cache(tcx, e)
75+
});
76+
});
77+
},
7678
);
7779
})
7880
}

compiler/rustc_middle/src/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for Span {
896896
}
897897

898898
if let Some(parent) = span_data.parent {
899-
let enclosing = s.tcx.source_span(parent).data_untracked();
899+
let enclosing = s.tcx.source_span_untracked(parent).data_untracked();
900900
if enclosing.contains(span_data) {
901901
TAG_RELATIVE_SPAN.encode(s);
902902
(span_data.lo - enclosing.lo).to_u32().encode(s);

0 commit comments

Comments
 (0)