mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 11:37:39 +00:00
Rename QuerySideEffects
to QuerySideEffect
This commit is contained in:
parent
3ca5220114
commit
453b51a65a
@ -11,7 +11,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId, Stab
|
|||||||
use rustc_hir::definitions::DefPathHash;
|
use rustc_hir::definitions::DefPathHash;
|
||||||
use rustc_index::{Idx, IndexVec};
|
use rustc_index::{Idx, IndexVec};
|
||||||
use rustc_macros::{Decodable, Encodable};
|
use rustc_macros::{Decodable, Encodable};
|
||||||
use rustc_query_system::query::QuerySideEffects;
|
use rustc_query_system::query::QuerySideEffect;
|
||||||
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder};
|
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder};
|
||||||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
@ -55,9 +55,9 @@ pub struct OnDiskCache {
|
|||||||
// The complete cache data in serialized form.
|
// The complete cache data in serialized form.
|
||||||
serialized_data: RwLock<Option<Mmap>>,
|
serialized_data: RwLock<Option<Mmap>>,
|
||||||
|
|
||||||
// Collects all `QuerySideEffects` created during the current compilation
|
// Collects all `QuerySideEffect` created during the current compilation
|
||||||
// session.
|
// session.
|
||||||
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffects>>,
|
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffect>>,
|
||||||
|
|
||||||
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,
|
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ pub struct OnDiskCache {
|
|||||||
// `serialized_data`.
|
// `serialized_data`.
|
||||||
query_result_index: FxHashMap<SerializedDepNodeIndex, AbsoluteBytePos>,
|
query_result_index: FxHashMap<SerializedDepNodeIndex, AbsoluteBytePos>,
|
||||||
|
|
||||||
// A map from dep-node to the position of any associated `QuerySideEffects` in
|
// A map from dep-node to the position of any associated `QuerySideEffect` in
|
||||||
// `serialized_data`.
|
// `serialized_data`.
|
||||||
prev_side_effects_index: FxHashMap<SerializedDepNodeIndex, AbsoluteBytePos>,
|
prev_side_effects_index: FxHashMap<SerializedDepNodeIndex, AbsoluteBytePos>,
|
||||||
|
|
||||||
@ -270,10 +270,10 @@ impl OnDiskCache {
|
|||||||
.current_side_effects
|
.current_side_effects
|
||||||
.borrow()
|
.borrow()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(dep_node_index, side_effects)| {
|
.map(|(dep_node_index, side_effect)| {
|
||||||
let pos = AbsoluteBytePos::new(encoder.position());
|
let pos = AbsoluteBytePos::new(encoder.position());
|
||||||
let dep_node_index = SerializedDepNodeIndex::new(dep_node_index.index());
|
let dep_node_index = SerializedDepNodeIndex::new(dep_node_index.index());
|
||||||
encoder.encode_tagged(dep_node_index, side_effects);
|
encoder.encode_tagged(dep_node_index, side_effect);
|
||||||
|
|
||||||
(dep_node_index, pos)
|
(dep_node_index, pos)
|
||||||
})
|
})
|
||||||
@ -352,23 +352,23 @@ impl OnDiskCache {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads a `QuerySideEffects` created during the previous compilation session.
|
/// Loads a `QuerySideEffect` created during the previous compilation session.
|
||||||
pub fn load_side_effects(
|
pub fn load_side_effect(
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
dep_node_index: SerializedDepNodeIndex,
|
dep_node_index: SerializedDepNodeIndex,
|
||||||
) -> Option<QuerySideEffects> {
|
) -> Option<QuerySideEffect> {
|
||||||
let side_effects: Option<QuerySideEffects> =
|
let side_effect: Option<QuerySideEffect> =
|
||||||
self.load_indexed(tcx, dep_node_index, &self.prev_side_effects_index);
|
self.load_indexed(tcx, dep_node_index, &self.prev_side_effects_index);
|
||||||
side_effects
|
side_effect
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a `QuerySideEffects` emitted during the current compilation session.
|
/// Stores a `QuerySideEffect` emitted during the current compilation session.
|
||||||
/// Anything stored like this will be available via `load_side_effects` in
|
/// Anything stored like this will be available via `load_side_effect` in
|
||||||
/// the next compilation session.
|
/// the next compilation session.
|
||||||
pub fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects) {
|
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 mut current_side_effects = self.current_side_effects.borrow_mut();
|
||||||
let prev = current_side_effects.insert(dep_node_index, side_effects);
|
let prev = current_side_effects.insert(dep_node_index, side_effect);
|
||||||
debug_assert!(prev.is_none());
|
debug_assert!(prev.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ use rustc_middle::ty::{self, TyCtxt, TyEncoder};
|
|||||||
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
|
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_query_system::query::{
|
use rustc_query_system::query::{
|
||||||
QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame,
|
QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffect, QueryStackFrame,
|
||||||
force_query,
|
force_query,
|
||||||
};
|
};
|
||||||
use rustc_query_system::{QueryOverflow, QueryOverflowNote};
|
use rustc_query_system::{QueryOverflow, QueryOverflowNote};
|
||||||
@ -89,21 +89,21 @@ impl QueryContext for QueryCtxt<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Interactions with on_disk_cache
|
// Interactions with on_disk_cache
|
||||||
fn load_side_effects(
|
fn load_side_effect(
|
||||||
self,
|
self,
|
||||||
prev_dep_node_index: SerializedDepNodeIndex,
|
prev_dep_node_index: SerializedDepNodeIndex,
|
||||||
) -> Option<QuerySideEffects> {
|
) -> Option<QuerySideEffect> {
|
||||||
self.query_system
|
self.query_system
|
||||||
.on_disk_cache
|
.on_disk_cache
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|c| c.load_side_effects(self.tcx, prev_dep_node_index))
|
.and_then(|c| c.load_side_effect(self.tcx, prev_dep_node_index))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[cold]
|
#[cold]
|
||||||
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects) {
|
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect) {
|
||||||
if let Some(c) = self.query_system.on_disk_cache.as_ref() {
|
if let Some(c) = self.query_system.on_disk_cache.as_ref() {
|
||||||
c.store_side_effects(dep_node_index, side_effects)
|
c.store_side_effect(dep_node_index, side_effect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex
|
|||||||
use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId};
|
use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId};
|
||||||
use crate::dep_graph::edges::EdgesVec;
|
use crate::dep_graph::edges::EdgesVec;
|
||||||
use crate::ich::StableHashingContext;
|
use crate::ich::StableHashingContext;
|
||||||
use crate::query::{QueryContext, QuerySideEffects};
|
use crate::query::{QueryContext, QuerySideEffect};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DepGraph<D: Deps> {
|
pub struct DepGraph<D: Deps> {
|
||||||
@ -689,8 +689,8 @@ impl<D: Deps> DepGraphData<D> {
|
|||||||
// diagnostic.
|
// diagnostic.
|
||||||
std::iter::once(DepNodeIndex::FOREVER_RED_NODE).collect(),
|
std::iter::once(DepNodeIndex::FOREVER_RED_NODE).collect(),
|
||||||
);
|
);
|
||||||
let side_effects = QuerySideEffects { diagnostic: diagnostic.clone() };
|
let side_effect = QuerySideEffect::Diagnostic(diagnostic.clone());
|
||||||
qcx.store_side_effects(dep_node_index, side_effects);
|
qcx.store_side_effect(dep_node_index, side_effect);
|
||||||
dep_node_index
|
dep_node_index
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -701,14 +701,18 @@ impl<D: Deps> DepGraphData<D> {
|
|||||||
prev_index: SerializedDepNodeIndex,
|
prev_index: SerializedDepNodeIndex,
|
||||||
) {
|
) {
|
||||||
D::with_deps(TaskDepsRef::Ignore, || {
|
D::with_deps(TaskDepsRef::Ignore, || {
|
||||||
let side_effects = qcx.load_side_effects(prev_index).unwrap();
|
let side_effect = qcx.load_side_effect(prev_index).unwrap();
|
||||||
|
|
||||||
qcx.dep_context().sess().dcx().emit_diagnostic(side_effects.diagnostic.clone());
|
match &side_effect {
|
||||||
|
QuerySideEffect::Diagnostic(diagnostic) => {
|
||||||
|
qcx.dep_context().sess().dcx().emit_diagnostic(diagnostic.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Promote the previous diagnostics to the current session.
|
// Promote the previous diagnostics to the current session.
|
||||||
let index = self.current.promote_node_and_deps_to_current(&self.previous, prev_index);
|
let index = self.current.promote_node_and_deps_to_current(&self.previous, prev_index);
|
||||||
// FIXME: Can this race with a parallel compiler?
|
// FIXME: Can this race with a parallel compiler?
|
||||||
qcx.store_side_effects(index, side_effects);
|
qcx.store_side_effect(index, side_effect);
|
||||||
|
|
||||||
// Mark the node as green.
|
// Mark the node as green.
|
||||||
self.colors.insert(prev_index, DepNodeColor::Green(index));
|
self.colors.insert(prev_index, DepNodeColor::Green(index));
|
||||||
|
@ -62,18 +62,22 @@ impl QueryStackFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tracks 'side effects' for a particular query.
|
/// Track a 'side effects' for a particular query.
|
||||||
/// This struct is saved to disk along with the query result,
|
/// This struct is saved to disk along with the query result,
|
||||||
/// and loaded from disk if we mark the query as green.
|
/// and loaded from disk if we mark the query as green.
|
||||||
/// This allows us to 'replay' changes to global state
|
/// This allows us to 'replay' changes to global state
|
||||||
/// that would otherwise only occur if we actually
|
/// that would otherwise only occur if we actually
|
||||||
/// executed the query method.
|
/// executed the query method.
|
||||||
|
///
|
||||||
|
/// Each side effect gets an unique dep node index which is added
|
||||||
|
/// as a dependency of the query which had the effect.
|
||||||
#[derive(Debug, Encodable, Decodable)]
|
#[derive(Debug, Encodable, Decodable)]
|
||||||
pub struct QuerySideEffects {
|
pub enum QuerySideEffect {
|
||||||
/// Stores any diagnostics emitted during query execution.
|
/// Stores a diagnostic emitted during query execution.
|
||||||
/// These diagnostics will be re-emitted if we mark
|
/// This diagnostic will be re-emitted if we mark
|
||||||
/// the query as green.
|
/// the query as green, as that query will have the side
|
||||||
pub(super) diagnostic: DiagInner,
|
/// effect dep node as a dependency.
|
||||||
|
Diagnostic(DiagInner),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait QueryContext: HasDepContext {
|
pub trait QueryContext: HasDepContext {
|
||||||
@ -84,14 +88,14 @@ pub trait QueryContext: HasDepContext {
|
|||||||
|
|
||||||
fn collect_active_jobs(self) -> QueryMap;
|
fn collect_active_jobs(self) -> QueryMap;
|
||||||
|
|
||||||
/// Load side effects associated to the node in the previous session.
|
/// Load a side effect associated to the node in the previous session.
|
||||||
fn load_side_effects(
|
fn load_side_effect(
|
||||||
self,
|
self,
|
||||||
prev_dep_node_index: SerializedDepNodeIndex,
|
prev_dep_node_index: SerializedDepNodeIndex,
|
||||||
) -> Option<QuerySideEffects>;
|
) -> Option<QuerySideEffect>;
|
||||||
|
|
||||||
/// Register diagnostics for the given node, for use in next session.
|
/// Register a side effect for the given node, for use in next session.
|
||||||
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
|
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect);
|
||||||
|
|
||||||
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
||||||
/// new query job while it executes.
|
/// new query job while it executes.
|
||||||
|
@ -2525,7 +2525,7 @@ written to standard error output)"),
|
|||||||
"for every macro invocation, print its name and arguments (default: no)"),
|
"for every macro invocation, print its name and arguments (default: no)"),
|
||||||
track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
|
track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"tracks where in rustc a diagnostic was emitted"),
|
"tracks where in rustc a diagnostic was emitted"),
|
||||||
// Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
|
// Diagnostics are considered side-effects of a query (see `QuerySideEffect`) and are saved
|
||||||
// alongside query results and changes to translation options can affect diagnostics - so
|
// alongside query results and changes to translation options can affect diagnostics - so
|
||||||
// translation options should be tracked.
|
// translation options should be tracked.
|
||||||
translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
|
translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
|
||||||
|
Loading…
Reference in New Issue
Block a user