Skip to content

Commit 2b830dc

Browse files
committed
Remove 'tcx lifetime from OnDiskCache
1 parent 9b4d7c6 commit 2b830dc

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

compiler/rustc_incremental/src/persist/load.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
182182
/// If we are not in incremental compilation mode, returns `None`.
183183
/// Otherwise, tries to load the query result cache from disk,
184184
/// creating an empty cache if it could not be loaded.
185-
pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
185+
pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache> {
186186
if sess.opts.incremental.is_none() {
187187
return None;
188188
}
@@ -194,11 +194,11 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
194194
LoadResult::Ok { data: (bytes, start_pos) } => {
195195
let cache = OnDiskCache::new(sess, bytes, start_pos).unwrap_or_else(|()| {
196196
sess.dcx().emit_warn(errors::CorruptFile { path: &path });
197-
OnDiskCache::new_empty(sess.source_map())
197+
OnDiskCache::new_empty()
198198
});
199199
Some(cache)
200200
}
201-
_ => Some(OnDiskCache::new_empty(sess.source_map())),
201+
_ => Some(OnDiskCache::new_empty()),
202202
}
203203
}
204204

compiler/rustc_middle/src/query/on_disk_cache.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_session::Session;
2323
use rustc_span::hygiene::{
2424
ExpnId, HygieneDecodeContext, HygieneEncodeContext, SyntaxContext, SyntaxContextData,
2525
};
26-
use rustc_span::source_map::{SourceMap, Spanned};
26+
use rustc_span::source_map::Spanned;
2727
use rustc_span::{
2828
BytePos, CachingSourceMapView, ExpnData, ExpnHash, Pos, RelativeBytePos, SourceFile, Span,
2929
SpanDecoder, SpanEncoder, StableSourceFileId, Symbol,
@@ -49,15 +49,14 @@ const SYMBOL_PREINTERNED: u8 = 2;
4949
/// previous compilation session. This data will eventually include the results
5050
/// of a few selected queries (like `typeck` and `mir_optimized`) and
5151
/// any side effects that have been emitted during a query.
52-
pub struct OnDiskCache<'sess> {
52+
pub struct OnDiskCache {
5353
// The complete cache data in serialized form.
5454
serialized_data: RwLock<Option<Mmap>>,
5555

5656
// Collects all `QuerySideEffects` created during the current compilation
5757
// session.
5858
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffects>>,
5959

60-
source_map: &'sess SourceMap,
6160
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,
6261

6362
// Caches that are populated lazily during decoding.
@@ -151,12 +150,12 @@ impl EncodedSourceFileId {
151150
}
152151
}
153152

154-
impl<'sess> OnDiskCache<'sess> {
153+
impl OnDiskCache {
155154
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
156155
///
157156
/// The serialized cache has some basic integrity checks, if those checks indicate that the
158157
/// on-disk data is corrupt, an error is returned.
159-
pub fn new(sess: &'sess Session, data: Mmap, start_pos: usize) -> Result<Self, ()> {
158+
pub fn new(sess: &Session, data: Mmap, start_pos: usize) -> Result<Self, ()> {
160159
assert!(sess.opts.incremental.is_some());
161160

162161
let mut decoder = MemDecoder::new(&data, start_pos)?;
@@ -175,7 +174,6 @@ impl<'sess> OnDiskCache<'sess> {
175174
serialized_data: RwLock::new(Some(data)),
176175
file_index_to_stable_id: footer.file_index_to_stable_id,
177176
file_index_to_file: Default::default(),
178-
source_map: sess.source_map(),
179177
current_side_effects: Default::default(),
180178
query_result_index: footer.query_result_index.into_iter().collect(),
181179
prev_side_effects_index: footer.side_effects_index.into_iter().collect(),
@@ -187,12 +185,11 @@ impl<'sess> OnDiskCache<'sess> {
187185
})
188186
}
189187

190-
pub fn new_empty(source_map: &'sess SourceMap) -> Self {
188+
pub fn new_empty() -> Self {
191189
Self {
192190
serialized_data: RwLock::new(None),
193191
file_index_to_stable_id: Default::default(),
194192
file_index_to_file: Default::default(),
195-
source_map,
196193
current_side_effects: Default::default(),
197194
query_result_index: Default::default(),
198195
prev_side_effects_index: Default::default(),
@@ -423,7 +420,7 @@ impl<'sess> OnDiskCache<'sess> {
423420
}
424421

425422
fn with_decoder<'a, 'tcx, T, F: for<'s> FnOnce(&mut CacheDecoder<'s, 'tcx>) -> T>(
426-
&'sess self,
423+
&self,
427424
tcx: TyCtxt<'tcx>,
428425
pos: AbsoluteBytePos,
429426
f: F,
@@ -436,7 +433,6 @@ impl<'sess> OnDiskCache<'sess> {
436433
tcx,
437434
opaque: MemDecoder::new(serialized_data.as_deref().unwrap_or(&[]), pos.to_usize())
438435
.unwrap(),
439-
source_map: self.source_map,
440436
file_index_to_file: &self.file_index_to_file,
441437
file_index_to_stable_id: &self.file_index_to_stable_id,
442438
alloc_decoding_session: self.alloc_decoding_state.new_decoding_session(),
@@ -457,7 +453,6 @@ impl<'sess> OnDiskCache<'sess> {
457453
pub struct CacheDecoder<'a, 'tcx> {
458454
tcx: TyCtxt<'tcx>,
459455
opaque: MemDecoder<'a>,
460-
source_map: &'a SourceMap,
461456
file_index_to_file: &'a Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
462457
file_index_to_stable_id: &'a FxHashMap<SourceFileIndex, EncodedSourceFileId>,
463458
alloc_decoding_session: AllocDecodingSession<'a>,
@@ -470,8 +465,7 @@ pub struct CacheDecoder<'a, 'tcx> {
470465
impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
471466
#[inline]
472467
fn file_index_to_file(&self, index: SourceFileIndex) -> Lrc<SourceFile> {
473-
let CacheDecoder { tcx, file_index_to_file, file_index_to_stable_id, source_map, .. } =
474-
*self;
468+
let CacheDecoder { tcx, file_index_to_file, file_index_to_stable_id, .. } = *self;
475469

476470
Lrc::clone(file_index_to_file.borrow_mut().entry(index).or_insert_with(|| {
477471
let source_file_id = &file_index_to_stable_id[&index];
@@ -490,7 +484,8 @@ impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
490484
self.tcx.import_source_files(source_file_cnum);
491485
}
492486

493-
source_map
487+
tcx.sess
488+
.source_map()
494489
.source_file_by_stable_id(source_file_id.stable_source_file_id)
495490
.expect("failed to lookup `SourceFile` in new context")
496491
}))

compiler/rustc_middle/src/query/plumbing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct QuerySystem<'tcx> {
6666
/// Do not access this directly. It is only meant to be used by
6767
/// `DepGraph::try_mark_green()` and the query infrastructure.
6868
/// This is `None` if we are not incremental compilation mode
69-
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
69+
pub on_disk_cache: Option<OnDiskCache>,
7070

7171
pub fns: QuerySystemFns<'tcx>,
7272

compiler/rustc_query_impl/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ trait QueryConfigRestored<'tcx> {
198198
-> Self::RestoredValue;
199199
}
200200

201-
pub fn query_system<'tcx>(
201+
pub fn query_system<'a>(
202202
local_providers: Providers,
203203
extern_providers: ExternProviders,
204-
on_disk_cache: Option<OnDiskCache<'tcx>>,
204+
on_disk_cache: Option<OnDiskCache>,
205205
incremental: bool,
206-
) -> QuerySystem<'tcx> {
206+
) -> QuerySystem<'a> {
207207
QuerySystem {
208208
states: Default::default(),
209209
arenas: Default::default(),

0 commit comments

Comments
 (0)