Skip to content

Commit 453b51a

Browse files
committed
Rename QuerySideEffects to QuerySideEffect
1 parent 3ca5220 commit 453b51a

File tree

5 files changed

+47
-39
lines changed

5 files changed

+47
-39
lines changed

Diff for: compiler/rustc_middle/src/query/on_disk_cache.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId, Stab
1111
use rustc_hir::definitions::DefPathHash;
1212
use rustc_index::{Idx, IndexVec};
1313
use rustc_macros::{Decodable, Encodable};
14-
use rustc_query_system::query::QuerySideEffects;
14+
use rustc_query_system::query::QuerySideEffect;
1515
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder};
1616
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
1717
use rustc_session::Session;
@@ -55,9 +55,9 @@ pub struct OnDiskCache {
5555
// The complete cache data in serialized form.
5656
serialized_data: RwLock<Option<Mmap>>,
5757

58-
// Collects all `QuerySideEffects` created during the current compilation
58+
// Collects all `QuerySideEffect` created during the current compilation
5959
// session.
60-
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffects>>,
60+
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffect>>,
6161

6262
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,
6363

@@ -68,7 +68,7 @@ pub struct OnDiskCache {
6868
// `serialized_data`.
6969
query_result_index: FxHashMap<SerializedDepNodeIndex, AbsoluteBytePos>,
7070

71-
// A map from dep-node to the position of any associated `QuerySideEffects` in
71+
// A map from dep-node to the position of any associated `QuerySideEffect` in
7272
// `serialized_data`.
7373
prev_side_effects_index: FxHashMap<SerializedDepNodeIndex, AbsoluteBytePos>,
7474

@@ -270,10 +270,10 @@ impl OnDiskCache {
270270
.current_side_effects
271271
.borrow()
272272
.iter()
273-
.map(|(dep_node_index, side_effects)| {
273+
.map(|(dep_node_index, side_effect)| {
274274
let pos = AbsoluteBytePos::new(encoder.position());
275275
let dep_node_index = SerializedDepNodeIndex::new(dep_node_index.index());
276-
encoder.encode_tagged(dep_node_index, side_effects);
276+
encoder.encode_tagged(dep_node_index, side_effect);
277277

278278
(dep_node_index, pos)
279279
})
@@ -352,23 +352,23 @@ impl OnDiskCache {
352352
})
353353
}
354354

355-
/// Loads a `QuerySideEffects` created during the previous compilation session.
356-
pub fn load_side_effects(
355+
/// Loads a `QuerySideEffect` created during the previous compilation session.
356+
pub fn load_side_effect(
357357
&self,
358358
tcx: TyCtxt<'_>,
359359
dep_node_index: SerializedDepNodeIndex,
360-
) -> Option<QuerySideEffects> {
361-
let side_effects: Option<QuerySideEffects> =
360+
) -> Option<QuerySideEffect> {
361+
let side_effect: Option<QuerySideEffect> =
362362
self.load_indexed(tcx, dep_node_index, &self.prev_side_effects_index);
363-
side_effects
363+
side_effect
364364
}
365365

366-
/// Stores a `QuerySideEffects` emitted during the current compilation session.
367-
/// Anything stored like this will be available via `load_side_effects` in
366+
/// Stores a `QuerySideEffect` emitted during the current compilation session.
367+
/// Anything stored like this will be available via `load_side_effect` in
368368
/// the next compilation session.
369-
pub fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects) {
369+
pub fn store_side_effect(&self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect) {
370370
let mut current_side_effects = self.current_side_effects.borrow_mut();
371-
let prev = current_side_effects.insert(dep_node_index, side_effects);
371+
let prev = current_side_effects.insert(dep_node_index, side_effect);
372372
debug_assert!(prev.is_none());
373373
}
374374

Diff for: compiler/rustc_query_impl/src/plumbing.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_middle::ty::{self, TyCtxt, TyEncoder};
2323
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
2424
use rustc_query_system::ich::StableHashingContext;
2525
use rustc_query_system::query::{
26-
QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame,
26+
QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffect, QueryStackFrame,
2727
force_query,
2828
};
2929
use rustc_query_system::{QueryOverflow, QueryOverflowNote};
@@ -89,21 +89,21 @@ impl QueryContext for QueryCtxt<'_> {
8989
}
9090

9191
// Interactions with on_disk_cache
92-
fn load_side_effects(
92+
fn load_side_effect(
9393
self,
9494
prev_dep_node_index: SerializedDepNodeIndex,
95-
) -> Option<QuerySideEffects> {
95+
) -> Option<QuerySideEffect> {
9696
self.query_system
9797
.on_disk_cache
9898
.as_ref()
99-
.and_then(|c| c.load_side_effects(self.tcx, prev_dep_node_index))
99+
.and_then(|c| c.load_side_effect(self.tcx, prev_dep_node_index))
100100
}
101101

102102
#[inline(never)]
103103
#[cold]
104-
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects) {
104+
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect) {
105105
if let Some(c) = self.query_system.on_disk_cache.as_ref() {
106-
c.store_side_effects(dep_node_index, side_effects)
106+
c.store_side_effect(dep_node_index, side_effect)
107107
}
108108
}
109109

Diff for: compiler/rustc_query_system/src/dep_graph/graph.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex
2525
use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId};
2626
use crate::dep_graph::edges::EdgesVec;
2727
use crate::ich::StableHashingContext;
28-
use crate::query::{QueryContext, QuerySideEffects};
28+
use crate::query::{QueryContext, QuerySideEffect};
2929

3030
#[derive(Clone)]
3131
pub struct DepGraph<D: Deps> {
@@ -689,8 +689,8 @@ impl<D: Deps> DepGraphData<D> {
689689
// diagnostic.
690690
std::iter::once(DepNodeIndex::FOREVER_RED_NODE).collect(),
691691
);
692-
let side_effects = QuerySideEffects { diagnostic: diagnostic.clone() };
693-
qcx.store_side_effects(dep_node_index, side_effects);
692+
let side_effect = QuerySideEffect::Diagnostic(diagnostic.clone());
693+
qcx.store_side_effect(dep_node_index, side_effect);
694694
dep_node_index
695695
}
696696

@@ -701,14 +701,18 @@ impl<D: Deps> DepGraphData<D> {
701701
prev_index: SerializedDepNodeIndex,
702702
) {
703703
D::with_deps(TaskDepsRef::Ignore, || {
704-
let side_effects = qcx.load_side_effects(prev_index).unwrap();
704+
let side_effect = qcx.load_side_effect(prev_index).unwrap();
705705

706-
qcx.dep_context().sess().dcx().emit_diagnostic(side_effects.diagnostic.clone());
706+
match &side_effect {
707+
QuerySideEffect::Diagnostic(diagnostic) => {
708+
qcx.dep_context().sess().dcx().emit_diagnostic(diagnostic.clone());
709+
}
710+
}
707711

708712
// Promote the previous diagnostics to the current session.
709713
let index = self.current.promote_node_and_deps_to_current(&self.previous, prev_index);
710714
// FIXME: Can this race with a parallel compiler?
711-
qcx.store_side_effects(index, side_effects);
715+
qcx.store_side_effect(index, side_effect);
712716

713717
// Mark the node as green.
714718
self.colors.insert(prev_index, DepNodeColor::Green(index));

Diff for: compiler/rustc_query_system/src/query/mod.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,22 @@ impl QueryStackFrame {
6262
}
6363
}
6464

65-
/// Tracks 'side effects' for a particular query.
65+
/// Track a 'side effects' for a particular query.
6666
/// This struct is saved to disk along with the query result,
6767
/// and loaded from disk if we mark the query as green.
6868
/// This allows us to 'replay' changes to global state
6969
/// that would otherwise only occur if we actually
7070
/// executed the query method.
71+
///
72+
/// Each side effect gets an unique dep node index which is added
73+
/// as a dependency of the query which had the effect.
7174
#[derive(Debug, Encodable, Decodable)]
72-
pub struct QuerySideEffects {
73-
/// Stores any diagnostics emitted during query execution.
74-
/// These diagnostics will be re-emitted if we mark
75-
/// the query as green.
76-
pub(super) diagnostic: DiagInner,
75+
pub enum QuerySideEffect {
76+
/// Stores a diagnostic emitted during query execution.
77+
/// This diagnostic will be re-emitted if we mark
78+
/// the query as green, as that query will have the side
79+
/// effect dep node as a dependency.
80+
Diagnostic(DiagInner),
7781
}
7882

7983
pub trait QueryContext: HasDepContext {
@@ -84,14 +88,14 @@ pub trait QueryContext: HasDepContext {
8488

8589
fn collect_active_jobs(self) -> QueryMap;
8690

87-
/// Load side effects associated to the node in the previous session.
88-
fn load_side_effects(
91+
/// Load a side effect associated to the node in the previous session.
92+
fn load_side_effect(
8993
self,
9094
prev_dep_node_index: SerializedDepNodeIndex,
91-
) -> Option<QuerySideEffects>;
95+
) -> Option<QuerySideEffect>;
9296

93-
/// Register diagnostics for the given node, for use in next session.
94-
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
97+
/// Register a side effect for the given node, for use in next session.
98+
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect);
9599

96100
/// Executes a job by changing the `ImplicitCtxt` to point to the
97101
/// new query job while it executes.

Diff for: compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ written to standard error output)"),
25252525
"for every macro invocation, print its name and arguments (default: no)"),
25262526
track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
25272527
"tracks where in rustc a diagnostic was emitted"),
2528-
// Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
2528+
// Diagnostics are considered side-effects of a query (see `QuerySideEffect`) and are saved
25292529
// alongside query results and changes to translation options can affect diagnostics - so
25302530
// translation options should be tracked.
25312531
translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],

0 commit comments

Comments
 (0)