Skip to content

Commit 51456a6

Browse files
committed
Auto merge of #45353 - wesleywiser:untracked_queries, r=michaelwoerister
[incremental] Add support for eval always queries Part of #45238
2 parents 1855aff + 8281e88 commit 51456a6

File tree

4 files changed

+94
-17
lines changed

4 files changed

+94
-17
lines changed

src/librustc/dep_graph/dep_node.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ macro_rules! is_input_attr {
9090
($attr:ident) => (false);
9191
}
9292

93+
macro_rules! is_eval_always_attr {
94+
(eval_always) => (true);
95+
($attr:ident) => (false);
96+
}
97+
9398
macro_rules! contains_anon_attr {
9499
($($attr:ident),*) => ({$(is_anon_attr!($attr) | )* false});
95100
}
@@ -98,6 +103,10 @@ macro_rules! contains_input_attr {
98103
($($attr:ident),*) => ({$(is_input_attr!($attr) | )* false});
99104
}
100105

106+
macro_rules! contains_eval_always_attr {
107+
($($attr:ident),*) => ({$(is_eval_always_attr!($attr) | )* false});
108+
}
109+
101110
macro_rules! define_dep_nodes {
102111
(<$tcx:tt>
103112
$(
@@ -160,6 +169,15 @@ macro_rules! define_dep_nodes {
160169
}
161170
}
162171

172+
#[inline]
173+
pub fn is_eval_always(&self) -> bool {
174+
match *self {
175+
$(
176+
DepKind :: $variant => { contains_eval_always_attr!($($attr), *) }
177+
)*
178+
}
179+
}
180+
163181
#[allow(unreachable_code)]
164182
#[inline]
165183
pub fn has_params(&self) -> bool {
@@ -447,10 +465,10 @@ define_dep_nodes!( <'tcx>
447465

448466
// Represents different phases in the compiler.
449467
[] RegionScopeTree(DefId),
450-
[] Coherence,
451-
[] CoherenceInherentImplOverlapCheck,
468+
[eval_always] Coherence,
469+
[eval_always] CoherenceInherentImplOverlapCheck,
452470
[] CoherenceCheckTrait(DefId),
453-
[] PrivacyAccessLevels(CrateNum),
471+
[eval_always] PrivacyAccessLevels(CrateNum),
454472

455473
// Represents the MIR for a fn; also used as the task node for
456474
// things read/modify that MIR.
@@ -467,7 +485,7 @@ define_dep_nodes!( <'tcx>
467485

468486
[] Reachability,
469487
[] MirKeys,
470-
[] CrateVariances,
488+
[eval_always] CrateVariances,
471489

472490
// Nodes representing bits of computed IR in the tcx. Each shared
473491
// table in the tcx (or elsewhere) maps to one of these
@@ -497,7 +515,7 @@ define_dep_nodes!( <'tcx>
497515
[] DtorckConstraint(DefId),
498516
[] AdtDestructor(DefId),
499517
[] AssociatedItemDefIds(DefId),
500-
[] InherentImpls(DefId),
518+
[eval_always] InherentImpls(DefId),
501519
[] TypeckBodiesKrate,
502520
[] TypeckTables(DefId),
503521
[] UsedTraitImports(DefId),
@@ -567,7 +585,7 @@ define_dep_nodes!( <'tcx>
567585
[] IsCompilerBuiltins(CrateNum),
568586
[] HasGlobalAllocator(CrateNum),
569587
[] ExternCrate(DefId),
570-
[] LintLevels,
588+
[eval_always] LintLevels,
571589
[] Specializes { impl1: DefId, impl2: DefId },
572590
[input] InScopeTraits(DefIndex),
573591
[] ModuleExports(DefId),
@@ -626,7 +644,7 @@ define_dep_nodes!( <'tcx>
626644
[] StabilityIndex,
627645
[] AllCrateNums,
628646
[] ExportedSymbols(CrateNum),
629-
[] CollectAndPartitionTranslationItems,
647+
[eval_always] CollectAndPartitionTranslationItems,
630648
[] ExportName(DefId),
631649
[] ContainsExternIndicator(DefId),
632650
[] IsTranslatedFunction(DefId),

src/librustc/dep_graph/graph.rs

+57-3
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,27 @@ impl DepGraph {
199199
-> (R, DepNodeIndex)
200200
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
201201
R: HashStable<HCX>,
202+
{
203+
self.with_task_impl(key, cx, arg, task,
204+
|data, key| data.borrow_mut().push_task(key),
205+
|data, key| data.borrow_mut().pop_task(key))
206+
}
207+
208+
fn with_task_impl<C, A, R, HCX>(&self,
209+
key: DepNode,
210+
cx: C,
211+
arg: A,
212+
task: fn(C, A) -> R,
213+
push: fn(&RefCell<CurrentDepGraph>, DepNode),
214+
pop: fn(&RefCell<CurrentDepGraph>, DepNode) -> DepNodeIndex)
215+
-> (R, DepNodeIndex)
216+
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
217+
R: HashStable<HCX>,
202218
{
203219
if let Some(ref data) = self.data {
204220
debug_assert!(!data.colors.borrow().contains_key(&key));
205221

206-
data.current.borrow_mut().push_task(key);
222+
push(&data.current, key);
207223
if cfg!(debug_assertions) {
208224
profq_msg(ProfileQueriesMsg::TaskBegin(key.clone()))
209225
};
@@ -220,7 +236,7 @@ impl DepGraph {
220236
profq_msg(ProfileQueriesMsg::TaskEnd)
221237
};
222238

223-
let dep_node_index = data.current.borrow_mut().pop_task(key);
239+
let dep_node_index = pop(&data.current, key);
224240

225241
let mut stable_hasher = StableHasher::new();
226242
result.hash_stable(&mut hcx, &mut stable_hasher);
@@ -290,6 +306,22 @@ impl DepGraph {
290306
}
291307
}
292308

309+
/// Execute something within an "eval-always" task which is a task
310+
// that runs whenever anything changes.
311+
pub fn with_eval_always_task<C, A, R, HCX>(&self,
312+
key: DepNode,
313+
cx: C,
314+
arg: A,
315+
task: fn(C, A) -> R)
316+
-> (R, DepNodeIndex)
317+
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
318+
R: HashStable<HCX>,
319+
{
320+
self.with_task_impl(key, cx, arg, task,
321+
|data, key| data.borrow_mut().push_eval_always_task(key),
322+
|data, key| data.borrow_mut().pop_eval_always_task(key))
323+
}
324+
293325
#[inline]
294326
pub fn read(&self, v: DepNode) {
295327
if let Some(ref data) = self.data {
@@ -788,6 +820,24 @@ impl CurrentDepGraph {
788820
}
789821
}
790822

823+
fn push_eval_always_task(&mut self, key: DepNode) {
824+
self.task_stack.push(OpenTask::EvalAlways { node: key });
825+
}
826+
827+
fn pop_eval_always_task(&mut self, key: DepNode) -> DepNodeIndex {
828+
let popped_node = self.task_stack.pop().unwrap();
829+
830+
if let OpenTask::EvalAlways {
831+
node,
832+
} = popped_node {
833+
debug_assert_eq!(node, key);
834+
let krate_idx = self.node_to_node_index[&DepNode::new_no_params(DepKind::Krate)];
835+
self.alloc_node(node, vec![krate_idx])
836+
} else {
837+
bug!("pop_eval_always_task() - Expected eval always task to be popped");
838+
}
839+
}
840+
791841
fn read_index(&mut self, source: DepNodeIndex) {
792842
match self.task_stack.last_mut() {
793843
Some(&mut OpenTask::Regular {
@@ -818,7 +868,8 @@ impl CurrentDepGraph {
818868
reads.push(source);
819869
}
820870
}
821-
Some(&mut OpenTask::Ignore) | None => {
871+
Some(&mut OpenTask::Ignore) |
872+
Some(&mut OpenTask::EvalAlways { .. }) | None => {
822873
// ignore
823874
}
824875
}
@@ -851,4 +902,7 @@ enum OpenTask {
851902
read_set: FxHashSet<DepNodeIndex>,
852903
},
853904
Ignore,
905+
EvalAlways {
906+
node: DepNode,
907+
},
854908
}

src/librustc/ty/maps/plumbing.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,17 @@ macro_rules! define_maps {
433433
profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);
434434
let res = tcx.cycle_check(span, Query::$name(key), || {
435435
tcx.sess.diagnostic().track_diagnostics(|| {
436-
tcx.dep_graph.with_task(dep_node,
437-
tcx,
438-
key,
439-
Self::compute_result)
436+
if dep_node.kind.is_eval_always() {
437+
tcx.dep_graph.with_eval_always_task(dep_node,
438+
tcx,
439+
key,
440+
Self::compute_result)
441+
} else {
442+
tcx.dep_graph.with_task(dep_node,
443+
tcx,
444+
key,
445+
Self::compute_result)
446+
}
440447
})
441448
})?;
442449
profq_msg!(tcx, ProfileQueriesMsg::ProviderEnd);

src/librustc_privacy/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1563,9 +1563,7 @@ pub fn provide(providers: &mut Providers) {
15631563
}
15641564

15651565
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Rc<AccessLevels> {
1566-
tcx.dep_graph.with_ignore(|| { // FIXME
1567-
tcx.privacy_access_levels(LOCAL_CRATE)
1568-
})
1566+
tcx.privacy_access_levels(LOCAL_CRATE)
15691567
}
15701568

15711569
fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

0 commit comments

Comments
 (0)