Skip to content

Commit 0b6923b

Browse files
committed
Allow green-red query coloring race and mark no_hash queries green if deps are green too
1 parent 52fda2e commit 0b6923b

File tree

8 files changed

+254
-155
lines changed

8 files changed

+254
-155
lines changed

compiler/rustc_data_structures/src/steal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<T> Steal<T> {
5555

5656
#[track_caller]
5757
pub fn steal(&self) -> T {
58-
let value_ref = &mut *self.value.try_write().expect("stealing value which is locked");
58+
let mut value_ref = self.value.write();
5959
let value = value_ref.take();
6060
value.expect("attempt to steal from stolen value")
6161
}

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub use dep_node::{DepKind, DepNode, DepNodeExt, dep_kinds, label_strs};
1212
pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item, make_metadata};
1313
pub use rustc_query_system::dep_graph::debug::{DepNodeFilter, EdgeFilter};
1414
pub use rustc_query_system::dep_graph::{
15-
DepContext, DepGraphQuery, DepNodeIndex, Deps, SerializedDepGraph, SerializedDepNodeIndex,
16-
TaskDepsRef, WorkProduct, WorkProductId, WorkProductMap, hash_result,
15+
DepContext, DepGraphQuery, DepNodeIndex, Deps, MarkFrame, SerializedDepGraph,
16+
SerializedDepNodeIndex, TaskDepsRef, WorkProduct, WorkProductId, WorkProductMap, hash_result,
1717
};
1818

1919
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use rustc_hir::limit::Limit;
1313
use rustc_index::Idx;
1414
use rustc_middle::bug;
1515
use rustc_middle::dep_graph::{
16-
self, DepContext, DepKind, DepKindStruct, DepNode, DepNodeIndex, SerializedDepNodeIndex,
17-
dep_kinds,
16+
self, DepContext, DepKind, DepKindStruct, DepNode, DepNodeIndex, MarkFrame,
17+
SerializedDepNodeIndex, dep_kinds,
1818
};
1919
use rustc_middle::query::Key;
2020
use rustc_middle::query::on_disk_cache::{
@@ -489,7 +489,12 @@ where
489489
value
490490
}
491491

492-
fn force_from_dep_node<'tcx, Q>(query: Q, tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool
492+
fn force_from_dep_node<'tcx, Q>(
493+
query: Q,
494+
tcx: TyCtxt<'tcx>,
495+
dep_node: DepNode,
496+
frame: &MarkFrame<'_>,
497+
) -> bool
493498
where
494499
Q: QueryConfig<QueryCtxt<'tcx>>,
495500
{
@@ -512,7 +517,7 @@ where
512517
);
513518

514519
if let Some(key) = Q::Key::recover(tcx, &dep_node) {
515-
force_query(query, QueryCtxt::new(tcx), key, dep_node);
520+
force_query(query, QueryCtxt::new(tcx), key, dep_node, frame);
516521
true
517522
} else {
518523
false
@@ -540,8 +545,8 @@ where
540545
is_anon,
541546
is_eval_always,
542547
fingerprint_style,
543-
force_from_dep_node: Some(|tcx, dep_node, _| {
544-
force_from_dep_node(Q::config(tcx), tcx, dep_node)
548+
force_from_dep_node: Some(|tcx, dep_node, _, frame| {
549+
force_from_dep_node(Q::config(tcx), tcx, dep_node, frame)
545550
}),
546551
try_load_from_on_disk_cache: Some(|tcx, dep_node| {
547552
try_load_from_on_disk_cache(Q::config(tcx), tcx, dep_node)
@@ -853,7 +858,7 @@ macro_rules! define_queries {
853858
is_anon: false,
854859
is_eval_always: false,
855860
fingerprint_style: FingerprintStyle::Unit,
856-
force_from_dep_node: Some(|_, dep_node, _| bug!("force_from_dep_node: encountered {:?}", dep_node)),
861+
force_from_dep_node: Some(|_, dep_node, _, _| bug!("force_from_dep_node: encountered {:?}", dep_node)),
857862
try_load_from_on_disk_cache: None,
858863
name: &"Null",
859864
}
@@ -865,7 +870,7 @@ macro_rules! define_queries {
865870
is_anon: false,
866871
is_eval_always: false,
867872
fingerprint_style: FingerprintStyle::Unit,
868-
force_from_dep_node: Some(|_, dep_node, _| bug!("force_from_dep_node: encountered {:?}", dep_node)),
873+
force_from_dep_node: Some(|_, dep_node, _, _| bug!("force_from_dep_node: encountered {:?}", dep_node)),
869874
try_load_from_on_disk_cache: None,
870875
name: &"Red",
871876
}
@@ -876,7 +881,7 @@ macro_rules! define_queries {
876881
is_anon: false,
877882
is_eval_always: false,
878883
fingerprint_style: FingerprintStyle::Unit,
879-
force_from_dep_node: Some(|tcx, _, prev_index| {
884+
force_from_dep_node: Some(|tcx, _, prev_index, _| {
880885
tcx.dep_graph.force_diagnostic_node(QueryCtxt::new(tcx), prev_index);
881886
true
882887
}),
@@ -890,7 +895,7 @@ macro_rules! define_queries {
890895
is_anon: true,
891896
is_eval_always: false,
892897
fingerprint_style: FingerprintStyle::Opaque,
893-
force_from_dep_node: Some(|_, _, _| bug!("cannot force an anon node")),
898+
force_from_dep_node: Some(|_, _, _, _| bug!("cannot force an anon node")),
894899
try_load_from_on_disk_cache: None,
895900
name: &"AnonZeroDeps",
896901
}

compiler/rustc_query_system/src/dep_graph/dep_node.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use rustc_hir::definitions::DefPathHash;
6565
use rustc_macros::{Decodable, Encodable};
6666

6767
use super::{DepContext, FingerprintStyle, SerializedDepNodeIndex};
68+
use crate::dep_graph::graph::MarkFrame;
6869
use crate::ich::StableHashingContext;
6970

7071
/// This serves as an index into arrays built by `make_dep_kind_array`.
@@ -276,8 +277,14 @@ pub struct DepKindStruct<Tcx: DepContext> {
276277
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
277278
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
278279
/// `DefId` in `tcx.def_path_hash_to_def_id`.
279-
pub force_from_dep_node:
280-
Option<fn(tcx: Tcx, dep_node: DepNode, prev_index: SerializedDepNodeIndex) -> bool>,
280+
pub force_from_dep_node: Option<
281+
fn(
282+
tcx: Tcx,
283+
dep_node: DepNode,
284+
prev_index: SerializedDepNodeIndex,
285+
frame: &MarkFrame<'_>,
286+
) -> bool,
287+
>,
281288

282289
/// Invoke a query to put the on-disk cached value in memory.
283290
pub try_load_from_on_disk_cache: Option<fn(Tcx, DepNode)>,

0 commit comments

Comments
 (0)