Remove 'tcx lifetime from OnDiskCache

This commit is contained in:
bjorn3 2024-11-03 20:50:46 +00:00
parent cdeddae4f6
commit 84873f8613
4 changed files with 16 additions and 21 deletions

View file

@ -182,7 +182,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
/// If we are not in incremental compilation mode, returns `None`.
/// Otherwise, tries to load the query result cache from disk,
/// creating an empty cache if it could not be loaded.
pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache> {
if sess.opts.incremental.is_none() {
return None;
}
@ -194,11 +194,11 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
LoadResult::Ok { data: (bytes, start_pos) } => {
let cache = OnDiskCache::new(sess, bytes, start_pos).unwrap_or_else(|()| {
sess.dcx().emit_warn(errors::CorruptFile { path: &path });
OnDiskCache::new_empty(sess.source_map())
OnDiskCache::new_empty()
});
Some(cache)
}
_ => Some(OnDiskCache::new_empty(sess.source_map())),
_ => Some(OnDiskCache::new_empty()),
}
}

View file

@ -23,7 +23,7 @@ use rustc_session::Session;
use rustc_span::hygiene::{
ExpnId, HygieneDecodeContext, HygieneEncodeContext, SyntaxContext, SyntaxContextData,
};
use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::source_map::Spanned;
use rustc_span::{
BytePos, CachingSourceMapView, ExpnData, ExpnHash, Pos, RelativeBytePos, SourceFile, Span,
SpanDecoder, SpanEncoder, StableSourceFileId, Symbol,
@ -49,7 +49,7 @@ const SYMBOL_PREINTERNED: u8 = 2;
/// previous compilation session. This data will eventually include the results
/// of a few selected queries (like `typeck` and `mir_optimized`) and
/// any side effects that have been emitted during a query.
pub struct OnDiskCache<'sess> {
pub struct OnDiskCache {
// The complete cache data in serialized form.
serialized_data: RwLock<Option<Mmap>>,
@ -57,7 +57,6 @@ pub struct OnDiskCache<'sess> {
// session.
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffects>>,
source_map: &'sess SourceMap,
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,
// Caches that are populated lazily during decoding.
@ -151,12 +150,12 @@ impl EncodedSourceFileId {
}
}
impl<'sess> OnDiskCache<'sess> {
impl OnDiskCache {
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
///
/// The serialized cache has some basic integrity checks, if those checks indicate that the
/// on-disk data is corrupt, an error is returned.
pub fn new(sess: &'sess Session, data: Mmap, start_pos: usize) -> Result<Self, ()> {
pub fn new(sess: &Session, data: Mmap, start_pos: usize) -> Result<Self, ()> {
assert!(sess.opts.incremental.is_some());
let mut decoder = MemDecoder::new(&data, start_pos)?;
@ -175,7 +174,6 @@ impl<'sess> OnDiskCache<'sess> {
serialized_data: RwLock::new(Some(data)),
file_index_to_stable_id: footer.file_index_to_stable_id,
file_index_to_file: Default::default(),
source_map: sess.source_map(),
current_side_effects: Default::default(),
query_result_index: footer.query_result_index.into_iter().collect(),
prev_side_effects_index: footer.side_effects_index.into_iter().collect(),
@ -187,12 +185,11 @@ impl<'sess> OnDiskCache<'sess> {
})
}
pub fn new_empty(source_map: &'sess SourceMap) -> Self {
pub fn new_empty() -> Self {
Self {
serialized_data: RwLock::new(None),
file_index_to_stable_id: Default::default(),
file_index_to_file: Default::default(),
source_map,
current_side_effects: Default::default(),
query_result_index: Default::default(),
prev_side_effects_index: Default::default(),
@ -423,7 +420,7 @@ impl<'sess> OnDiskCache<'sess> {
}
fn with_decoder<'a, 'tcx, T, F: for<'s> FnOnce(&mut CacheDecoder<'s, 'tcx>) -> T>(
&'sess self,
&self,
tcx: TyCtxt<'tcx>,
pos: AbsoluteBytePos,
f: F,
@ -436,7 +433,6 @@ impl<'sess> OnDiskCache<'sess> {
tcx,
opaque: MemDecoder::new(serialized_data.as_deref().unwrap_or(&[]), pos.to_usize())
.unwrap(),
source_map: self.source_map,
file_index_to_file: &self.file_index_to_file,
file_index_to_stable_id: &self.file_index_to_stable_id,
alloc_decoding_session: self.alloc_decoding_state.new_decoding_session(),
@ -457,7 +453,6 @@ impl<'sess> OnDiskCache<'sess> {
pub struct CacheDecoder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
opaque: MemDecoder<'a>,
source_map: &'a SourceMap,
file_index_to_file: &'a Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
file_index_to_stable_id: &'a FxHashMap<SourceFileIndex, EncodedSourceFileId>,
alloc_decoding_session: AllocDecodingSession<'a>,
@ -470,8 +465,7 @@ pub struct CacheDecoder<'a, 'tcx> {
impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
#[inline]
fn file_index_to_file(&self, index: SourceFileIndex) -> Lrc<SourceFile> {
let CacheDecoder { tcx, file_index_to_file, file_index_to_stable_id, source_map, .. } =
*self;
let CacheDecoder { tcx, file_index_to_file, file_index_to_stable_id, .. } = *self;
Lrc::clone(file_index_to_file.borrow_mut().entry(index).or_insert_with(|| {
let source_file_id = &file_index_to_stable_id[&index];
@ -490,7 +484,8 @@ impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
self.tcx.import_source_files(source_file_cnum);
}
source_map
tcx.sess
.source_map()
.source_file_by_stable_id(source_file_id.stable_source_file_id)
.expect("failed to lookup `SourceFile` in new context")
}))

View file

@ -66,7 +66,7 @@ pub struct QuerySystem<'tcx> {
/// Do not access this directly. It is only meant to be used by
/// `DepGraph::try_mark_green()` and the query infrastructure.
/// This is `None` if we are not incremental compilation mode
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
pub on_disk_cache: Option<OnDiskCache>,
pub fns: QuerySystemFns<'tcx>,

View file

@ -198,12 +198,12 @@ trait QueryConfigRestored<'tcx> {
-> Self::RestoredValue;
}
pub fn query_system<'tcx>(
pub fn query_system<'a>(
local_providers: Providers,
extern_providers: ExternProviders,
on_disk_cache: Option<OnDiskCache<'tcx>>,
on_disk_cache: Option<OnDiskCache>,
incremental: bool,
) -> QuerySystem<'tcx> {
) -> QuerySystem<'a> {
QuerySystem {
states: Default::default(),
arenas: Default::default(),