Rollup merge of #133567 - bjorn3:various_cleanups, r=cjgillot
A bunch of cleanups These are all extracted from a branch I have to get rid of driver queries. Most of the commits are not directly necessary for this, but were found in the process of implementing the removal of driver queries. Previous PR: https://github.com/rust-lang/rust/pull/132410
This commit is contained in:
commit
d2881e4eb5
36 changed files with 309 additions and 335 deletions
|
@ -276,7 +276,7 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
/// The root query triggering all analysis passes like typeck or borrowck.
|
||||
query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
|
||||
query analysis(key: ()) {
|
||||
eval_always
|
||||
desc { "running analysis passes on this crate" }
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}))
|
||||
|
|
|
@ -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>,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue