Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ICE message for forbidden dep-graph reads. #124252

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ impl<D: Deps> DepGraph<D> {
}
TaskDepsRef::Ignore => return,
TaskDepsRef::Forbid => {
panic!("Illegal read of: {dep_node_index:?}")
// Reading is forbidden in this context. ICE with a useful error message.
panic_on_forbidden_read(data, dep_node_index)
}
};
let task_deps = &mut *task_deps;
Expand Down Expand Up @@ -1366,3 +1367,41 @@ pub(crate) fn print_markframe_trace<D: Deps>(graph: &DepGraph<D>, frame: Option<

eprintln!("end of try_mark_green dep node stack");
}

#[cold]
#[inline(never)]
fn panic_on_forbidden_read<D: Deps>(data: &DepGraphData<D>, dep_node_index: DepNodeIndex) -> ! {
// We have to do an expensive reverse-lookup of the DepNode that
// corresponds to `dep_node_index`, but that's OK since we are about
// to ICE anyway.
let mut dep_node = None;

// First try to find the dep node among those that already existed in the
// previous session
for (prev_index, index) in data.current.prev_index_to_index.lock().iter_enumerated() {
if index == &Some(dep_node_index) {
dep_node = Some(data.previous.index_to_node(prev_index));
break;
}
}

if dep_node.is_none() {
// Try to find it among the new nodes
for shard in data.current.new_node_to_index.lock_shards() {
if let Some((node, _)) = shard.iter().find(|(_, index)| **index == dep_node_index) {
dep_node = Some(*node);
break;
}
}
}

let dep_node = dep_node.map_or_else(
|| format!("with index {:?}", dep_node_index),
|dep_node| format!("`{:?}`", dep_node),
);

panic!(
"Error: trying to record dependency on DepNode {dep_node} in a \
context that does not allow it (e.g. during query deserialization)."
Copy link
Member

@RalfJung RalfJung Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, as someone who knows nothing about the query/incremental system, I still don't know that "record dependency" is the same as "invoke query". Or maybe it's not the same, but the explanation you gave me that I actually understood was "you invoked a query in a context that does not allow it". But maybe there are cases where saying "invoked a query" here would be wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Invoking a query is only of several ways of recording something in the dependency graph, but it is by far the most common. I'll update the error message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the new message better?

)
}
Loading