mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Don't store current-session side effects in OnDiskCache
Every other part of `OnDiskCache` deals with loading information from the _previous_ session, except for this one field. Moving it out to `QuerySystem` makes more sense, because that's also where query return values are stored (inside the caches in their vtables).
This commit is contained in:
@@ -6,6 +6,7 @@ use rustc_data_structures::sync::par_join;
|
||||
use rustc_middle::dep_graph::{
|
||||
DepGraph, SerializedDepGraph, WorkProduct, WorkProductId, WorkProductMap,
|
||||
};
|
||||
use rustc_middle::query::on_disk_cache;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_serialize::Encodable as RustcEncodable;
|
||||
use rustc_serialize::opaque::FileEncoder;
|
||||
@@ -82,7 +83,7 @@ pub(crate) fn save_dep_graph(tcx: TyCtxt<'_>) {
|
||||
|
||||
file_format::save_in(sess, query_cache_path, "query cache", |encoder| {
|
||||
tcx.sess.time("incr_comp_serialize_result_cache", || {
|
||||
on_disk_cache.serialize(tcx, encoder)
|
||||
on_disk_cache::OnDiskCache::serialize(tcx, encoder)
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -709,7 +709,7 @@ impl DepGraphData {
|
||||
// side effect.
|
||||
std::iter::once(DepNodeIndex::FOREVER_RED_NODE).collect(),
|
||||
);
|
||||
tcx.store_side_effect(dep_node_index, side_effect);
|
||||
tcx.query_system.side_effects.borrow_mut().insert(dep_node_index, side_effect);
|
||||
dep_node_index
|
||||
}
|
||||
|
||||
@@ -745,7 +745,7 @@ impl DepGraphData {
|
||||
}
|
||||
|
||||
// This will just overwrite the same value for concurrent calls.
|
||||
tcx.store_side_effect(dep_node_index, side_effect);
|
||||
tcx.query_system.side_effects.borrow_mut().insert(dep_node_index, side_effect);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1560,12 +1560,4 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
.as_ref()
|
||||
.and_then(|c| c.load_side_effect(self, prev_dep_node_index))
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[cold]
|
||||
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect) {
|
||||
if let Some(c) = self.query_system.on_disk_cache.as_ref() {
|
||||
c.store_side_effect(dep_node_index, side_effect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::collections::hash_map::Entry;
|
||||
use std::sync::Arc;
|
||||
use std::{fmt, mem};
|
||||
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_data_structures::sync::{HashMapExt, Lock, RwLock};
|
||||
use rustc_data_structures::unhash::UnhashMap;
|
||||
@@ -53,10 +53,6 @@ pub struct OnDiskCache {
|
||||
// The complete cache data in serialized form.
|
||||
serialized_data: RwLock<Option<Mmap>>,
|
||||
|
||||
// Collects all `QuerySideEffect` created during the current compilation
|
||||
// session.
|
||||
current_side_effects: Lock<FxIndexMap<DepNodeIndex, QuerySideEffect>>,
|
||||
|
||||
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,
|
||||
|
||||
// Caches that are populated lazily during decoding.
|
||||
@@ -172,7 +168,6 @@ impl OnDiskCache {
|
||||
serialized_data: RwLock::new(Some(data)),
|
||||
file_index_to_stable_id: footer.file_index_to_stable_id,
|
||||
file_index_to_file: Default::default(),
|
||||
current_side_effects: Default::default(),
|
||||
query_values_index: footer.query_values_index.into_iter().collect(),
|
||||
side_effects_index: footer.side_effects_index.into_iter().collect(),
|
||||
alloc_decoding_state: AllocDecodingState::new(footer.interpret_alloc_index),
|
||||
@@ -188,7 +183,6 @@ impl OnDiskCache {
|
||||
serialized_data: RwLock::new(None),
|
||||
file_index_to_stable_id: Default::default(),
|
||||
file_index_to_file: Default::default(),
|
||||
current_side_effects: Default::default(),
|
||||
query_values_index: Default::default(),
|
||||
side_effects_index: Default::default(),
|
||||
alloc_decoding_state: AllocDecodingState::new(Vec::new()),
|
||||
@@ -205,7 +199,9 @@ impl OnDiskCache {
|
||||
*self.serialized_data.write() = None;
|
||||
}
|
||||
|
||||
pub fn serialize(&self, tcx: TyCtxt<'_>, encoder: FileEncoder) -> FileEncodeResult {
|
||||
/// Serialize the current-session data that will be loaded by [`OnDiskCache`]
|
||||
/// in a subsequent incremental compilation session.
|
||||
pub fn serialize(tcx: TyCtxt<'_>, encoder: FileEncoder) -> FileEncodeResult {
|
||||
// Serializing the `DepGraph` should not modify it.
|
||||
tcx.dep_graph.with_ignore(|| {
|
||||
// Allocate `SourceFileIndex`es.
|
||||
@@ -249,7 +245,7 @@ impl OnDiskCache {
|
||||
});
|
||||
|
||||
// Encode side effects.
|
||||
for (&dep_node_index, side_effect) in self.current_side_effects.borrow().iter() {
|
||||
for (&dep_node_index, side_effect) in tcx.query_system.side_effects.borrow().iter() {
|
||||
encoder.encode_side_effect(dep_node_index, side_effect);
|
||||
}
|
||||
|
||||
@@ -339,15 +335,6 @@ impl OnDiskCache {
|
||||
side_effect
|
||||
}
|
||||
|
||||
/// Stores a `QuerySideEffect` emitted during the current compilation session.
|
||||
/// Anything stored like this will be available via `load_side_effect` in
|
||||
/// the next compilation session.
|
||||
pub fn store_side_effect(&self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect) {
|
||||
let mut current_side_effects = self.current_side_effects.borrow_mut();
|
||||
let prev = current_side_effects.insert(dep_node_index, side_effect);
|
||||
debug_assert!(prev.is_none());
|
||||
}
|
||||
|
||||
/// Returns true if there is a disk-cached query return value for the given node.
|
||||
#[inline]
|
||||
pub fn loadable_from_disk(&self, dep_node_index: SerializedDepNodeIndex) -> bool {
|
||||
|
||||
@@ -2,13 +2,14 @@ use std::fmt;
|
||||
use std::ops::Deref;
|
||||
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::hash_table::HashTable;
|
||||
use rustc_data_structures::sharded::Sharded;
|
||||
use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
|
||||
use rustc_data_structures::sync::{AtomicU64, Lock, WorkerLocal};
|
||||
use rustc_errors::Diag;
|
||||
use rustc_span::Span;
|
||||
|
||||
use crate::dep_graph::{DepKind, DepNodeIndex, SerializedDepNodeIndex};
|
||||
use crate::dep_graph::{DepKind, DepNodeIndex, QuerySideEffect, SerializedDepNodeIndex};
|
||||
use crate::ich::StableHashingContext;
|
||||
use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables, TaggedQueryKey};
|
||||
use crate::query::on_disk_cache::OnDiskCache;
|
||||
@@ -151,6 +152,13 @@ pub struct QuerySystem<'tcx> {
|
||||
pub arenas: WorkerLocal<QueryArenas<'tcx>>,
|
||||
pub query_vtables: QueryVTables<'tcx>,
|
||||
|
||||
/// Side-effect associated with each [`DepKind::SideEffect`] node in the
|
||||
/// current incremental-compilation session. Side effects will be written
|
||||
/// to disk, and loaded by [`OnDiskCache`] in the next session.
|
||||
///
|
||||
/// Always empty if incremental compilation is off.
|
||||
pub side_effects: Lock<FxIndexMap<DepNodeIndex, QuerySideEffect>>,
|
||||
|
||||
/// This provides access to the incremental compilation on-disk cache for query results.
|
||||
/// Do not access this directly. It is only meant to be used by
|
||||
/// `DepGraph::try_mark_green()` and the query infrastructure.
|
||||
|
||||
@@ -53,6 +53,7 @@ pub fn query_system<'tcx>(
|
||||
QuerySystem {
|
||||
arenas: Default::default(),
|
||||
query_vtables,
|
||||
side_effects: Default::default(),
|
||||
on_disk_cache,
|
||||
local_providers,
|
||||
extern_providers,
|
||||
|
||||
Reference in New Issue
Block a user