rust/compiler/rustc_middle/src/dep_graph/mod.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
3.4 KiB
Rust
Raw Normal View History

2020-03-18 09:32:58 +00:00
use crate::ty::{self, TyCtxt};
use rustc_data_structures::profiling::SelfProfilerRef;
2020-11-14 15:48:54 +00:00
use rustc_query_system::ich::StableHashingContext;
use rustc_session::Session;
2020-03-18 09:32:58 +00:00
2021-01-19 18:07:06 +00:00
#[macro_use]
2020-03-18 09:32:58 +00:00
mod dep_node;
pub use rustc_query_system::dep_graph::{
2021-03-02 21:38:49 +00:00
debug::DepNodeFilter, hash_result, DepContext, DepNodeColor, DepNodeIndex,
SerializedDepNodeIndex, WorkProduct, WorkProductId, WorkProductMap,
2020-03-18 09:32:58 +00:00
};
pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
2020-03-18 09:32:58 +00:00
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
2020-03-18 09:32:58 +00:00
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
pub type TaskDepsRef<'a> = rustc_query_system::dep_graph::TaskDepsRef<'a, DepKind>;
2020-03-18 09:32:58 +00:00
pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
2021-03-02 21:38:49 +00:00
pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;
pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>;
2020-03-18 09:32:58 +00:00
impl rustc_query_system::dep_graph::DepKind for DepKind {
2020-03-18 20:02:02 +00:00
const NULL: Self = DepKind::Null;
const RED: Self = DepKind::Red;
const MAX: u16 = DepKind::VARIANTS - 1;
2020-03-18 20:02:02 +00:00
2020-03-18 09:32:58 +00:00
fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2021-10-16 19:24:10 +00:00
write!(f, "{:?}(", node.kind)?;
2020-03-18 09:32:58 +00:00
ty::tls::with_opt(|opt_tcx| {
if let Some(tcx) = opt_tcx {
2020-03-21 08:28:37 +00:00
if let Some(def_id) = node.extract_def_id(tcx) {
2020-03-18 09:32:58 +00:00
write!(f, "{}", tcx.def_path_debug_str(def_id))?;
} else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*node) {
write!(f, "{s}")?;
2020-03-18 09:32:58 +00:00
} else {
write!(f, "{}", node.hash)?;
}
} else {
write!(f, "{}", node.hash)?;
}
Ok(())
})?;
write!(f, ")")
}
fn with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R
2020-03-18 09:32:58 +00:00
where
OP: FnOnce() -> R,
{
ty::tls::with_context(|icx| {
let icx = ty::tls::ImplicitCtxt { task_deps, ..icx.clone() };
2023-02-07 05:11:40 +00:00
ty::tls::enter_context(&icx, op)
2020-03-18 09:32:58 +00:00
})
}
fn read_deps<OP>(op: OP)
2020-03-18 09:32:58 +00:00
where
OP: for<'a> FnOnce(TaskDepsRef<'a>),
2020-03-18 09:32:58 +00:00
{
ty::tls::with_context_opt(|icx| {
2022-02-15 04:58:25 +00:00
let Some(icx) = icx else { return };
2020-03-18 09:32:58 +00:00
op(icx.task_deps)
})
}
#[track_caller]
#[inline]
fn from_u16(u: u16) -> Self {
if u > Self::MAX {
panic!("Invalid DepKind {u}");
}
// SAFETY: See comment on DepKind::VARIANTS
unsafe { std::mem::transmute(u) }
}
#[inline]
fn to_u16(self) -> u16 {
self as u16
}
2020-03-18 09:32:58 +00:00
}
impl<'tcx> DepContext for TyCtxt<'tcx> {
type DepKind = DepKind;
#[inline]
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
TyCtxt::with_stable_hashing_context(self, f)
2020-03-18 09:32:58 +00:00
}
#[inline]
fn dep_graph(&self) -> &DepGraph {
&self.dep_graph
}
#[inline(always)]
2020-03-18 09:32:58 +00:00
fn profiler(&self) -> &SelfProfilerRef {
&self.prof
}
#[inline(always)]
fn sess(&self) -> &Session {
self.sess
}
2021-10-16 18:10:23 +00:00
#[inline]
2023-02-27 18:12:16 +00:00
fn dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx> {
&self.query_kinds[dk as usize]
2021-10-16 18:24:08 +00:00
}
2020-03-18 09:32:58 +00:00
}