Skip to content

Commit 80a4257

Browse files
committed
Weaken assert_dep_node_not_yet_allocated_in_current_session for multiple threads
1 parent 55407b8 commit 80a4257

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

  • compiler

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ pub fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) ->
11111111
// know that later). If we are not doing LTO, there is only one optimized
11121112
// version of each module, so we re-use that.
11131113
let dep_node = cgu.codegen_dep_node(tcx);
1114-
tcx.dep_graph.assert_dep_node_not_yet_allocated_in_current_session(&dep_node, || {
1114+
tcx.dep_graph.assert_dep_node_not_yet_allocated_in_current_session(tcx.sess, &dep_node, || {
11151115
format!(
11161116
"CompileCodegenUnit dep-node for CGU `{}` already exists before marking.",
11171117
cgu.name()

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,17 @@ impl<D: Deps> DepGraphData<D> {
336336
// in `DepGraph::try_mark_green()`.
337337
// 2. Two distinct query keys get mapped to the same `DepNode`
338338
// (see for example #48923).
339-
self.assert_dep_node_not_yet_allocated_in_current_session(&key, || {
340-
format!(
341-
"forcing query with already existing `DepNode`\n\
339+
self.assert_dep_node_not_yet_allocated_in_current_session(
340+
cx.dep_context().sess(),
341+
&key,
342+
|| {
343+
format!(
344+
"forcing query with already existing `DepNode`\n\
342345
- query-key: {arg:?}\n\
343346
- dep-node: {key:?}"
344-
)
345-
});
347+
)
348+
},
349+
);
346350

347351
let with_deps = |task_deps| D::with_deps(task_deps, || task(cx, arg));
348352
let (result, edges) = if cx.dep_context().is_eval_always(key.kind) {
@@ -627,12 +631,20 @@ impl<D: Deps> DepGraph<D> {
627631
impl<D: Deps> DepGraphData<D> {
628632
fn assert_dep_node_not_yet_allocated_in_current_session<S: std::fmt::Display>(
629633
&self,
634+
sess: &Session,
630635
dep_node: &DepNode,
631636
msg: impl FnOnce() -> S,
632637
) {
633638
if let Some(prev_index) = self.previous.node_to_index_opt(dep_node) {
634-
let current = self.colors.get(prev_index);
635-
assert_matches!(current, DepNodeColor::Unknown, "{}", msg())
639+
let color = self.colors.get(prev_index);
640+
let ok = match color {
641+
DepNodeColor::Unknown => true,
642+
DepNodeColor::Red => false,
643+
DepNodeColor::Green(..) => sess.threads() > 1, // Other threads may mark this green
644+
};
645+
if !ok {
646+
panic!("{}", msg())
647+
}
636648
} else if let Some(nodes_in_current_session) = &self.current.nodes_in_current_session {
637649
outline(|| {
638650
let seen = nodes_in_current_session.lock().contains_key(dep_node);
@@ -1035,11 +1047,12 @@ impl<D: Deps> DepGraph<D> {
10351047

10361048
pub fn assert_dep_node_not_yet_allocated_in_current_session<S: std::fmt::Display>(
10371049
&self,
1050+
sess: &Session,
10381051
dep_node: &DepNode,
10391052
msg: impl FnOnce() -> S,
10401053
) {
10411054
if let Some(data) = &self.data {
1042-
data.assert_dep_node_not_yet_allocated_in_current_session(dep_node, msg)
1055+
data.assert_dep_node_not_yet_allocated_in_current_session(sess, dep_node, msg)
10431056
}
10441057
}
10451058

0 commit comments

Comments
 (0)