Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::fmt;

use rustc_errors::{DiagInner, TRACK_DIAGNOSTIC};
use rustc_middle::dep_graph::dep_node::default_dep_kind_debug;
use rustc_middle::dep_graph::{DepContext, DepKind, DepNode, TaskDepsRef};
use rustc_middle::dep_graph::{DepKind, DepNode, TaskDepsRef};
use rustc_middle::ty::tls;

fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
Expand Down
52 changes: 25 additions & 27 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use rustc_macros::{Decodable, Encodable};
use rustc_query_system::ich::StableHashingContext;
use rustc_span::Symbol;

use super::{DepContext, FingerprintStyle, SerializedDepNodeIndex};
use super::{FingerprintStyle, SerializedDepNodeIndex};
use crate::mir::mono::MonoItem;
use crate::ty::TyCtxt;

Expand Down Expand Up @@ -117,29 +117,25 @@ impl DepNode {
/// Creates a new, parameterless DepNode. This method will assert
/// that the DepNode corresponding to the given DepKind actually
/// does not require any parameters.
pub fn new_no_params<Tcx>(tcx: Tcx, kind: DepKind) -> DepNode
where
Tcx: super::DepContext,
{
pub fn new_no_params<'tcx>(tcx: TyCtxt<'tcx>, kind: DepKind) -> DepNode {
debug_assert_eq!(tcx.fingerprint_style(kind), FingerprintStyle::Unit);
DepNode { kind, hash: Fingerprint::ZERO.into() }
}

pub fn construct<Tcx, Key>(tcx: Tcx, kind: DepKind, arg: &Key) -> DepNode
pub fn construct<'tcx, Key>(tcx: TyCtxt<'tcx>, kind: DepKind, arg: &Key) -> DepNode
where
Tcx: super::DepContext,
Key: DepNodeKey<Tcx>,
Key: DepNodeKey<'tcx>,
{
let hash = arg.to_fingerprint(tcx);
let dep_node = DepNode { kind, hash: hash.into() };

#[cfg(debug_assertions)]
{
if !tcx.fingerprint_style(kind).reconstructible()
&& (tcx.sess().opts.unstable_opts.incremental_info
|| tcx.sess().opts.unstable_opts.query_dep_graph)
&& (tcx.sess.opts.unstable_opts.incremental_info
|| tcx.sess.opts.unstable_opts.query_dep_graph)
{
tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
tcx.dep_graph.register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
}
}

Expand All @@ -149,10 +145,11 @@ impl DepNode {
/// Construct a DepNode from the given DepKind and DefPathHash. This
/// method will assert that the given DepKind actually requires a
/// single DefId/DefPathHash parameter.
pub fn from_def_path_hash<Tcx>(tcx: Tcx, def_path_hash: DefPathHash, kind: DepKind) -> Self
where
Tcx: super::DepContext,
{
pub fn from_def_path_hash<'tcx>(
tcx: TyCtxt<'tcx>,
def_path_hash: DefPathHash,
kind: DepKind,
) -> Self {
debug_assert!(tcx.fingerprint_style(kind) == FingerprintStyle::DefPathHash);
DepNode { kind, hash: def_path_hash.0.into() }
}
Expand All @@ -172,26 +169,26 @@ impl fmt::Debug for DepNode {
}

/// Trait for query keys as seen by dependency-node tracking.
pub trait DepNodeKey<Tcx: DepContext>: fmt::Debug + Sized {
pub trait DepNodeKey<'tcx>: fmt::Debug + Sized {
fn fingerprint_style() -> FingerprintStyle;

/// This method turns a query key into an opaque `Fingerprint` to be used
/// in `DepNode`.
fn to_fingerprint(&self, _: Tcx) -> Fingerprint;
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint;

fn to_debug_str(&self, tcx: Tcx) -> String;
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String;

/// This method tries to recover the query key from the given `DepNode`,
/// something which is needed when forcing `DepNode`s during red-green
/// evaluation. The query system will only call this method if
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
/// It is always valid to return `None` here, in which case incremental
/// compilation will treat the query as having changed instead of forcing it.
fn recover(tcx: Tcx, dep_node: &DepNode) -> Option<Self>;
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self>;
}

// Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere.
impl<Tcx: DepContext, T> DepNodeKey<Tcx> for T
impl<'tcx, T> DepNodeKey<'tcx> for T
where
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
{
Expand All @@ -201,7 +198,7 @@ where
}

#[inline(always)]
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint {
default fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
tcx.with_stable_hashing_context(|mut hcx| {
let mut hasher = StableHasher::new();
self.hash_stable(&mut hcx, &mut hasher);
Expand All @@ -210,15 +207,15 @@ where
}

#[inline(always)]
default fn to_debug_str(&self, tcx: Tcx) -> String {
default fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
// Make sure to print dep node params with reduced queries since printing
// may themselves call queries, which may lead to (possibly untracked!)
// query cycles.
tcx.with_reduced_queries(|| format!("{self:?}"))
}

#[inline(always)]
default fn recover(_: Tcx, _: &DepNode) -> Option<Self> {
default fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
None
}
}
Expand All @@ -228,7 +225,7 @@ where
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
/// jump table instead of large matches.
pub struct DepKindVTable<Tcx: DepContext> {
pub struct DepKindVTable<'tcx> {
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
/// When their result is needed, it is recomputed. They are useful for fine-grained
/// dependency tracking, and caching within one compiler invocation.
Expand Down Expand Up @@ -279,11 +276,12 @@ pub struct DepKindVTable<Tcx: DepContext> {
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
/// `DefId` in `tcx.def_path_hash_to_def_id`.
pub force_from_dep_node:
Option<fn(tcx: Tcx, dep_node: DepNode, prev_index: SerializedDepNodeIndex) -> bool>,
pub force_from_dep_node: Option<
fn(tcx: TyCtxt<'tcx>, dep_node: DepNode, prev_index: SerializedDepNodeIndex) -> bool,
>,

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

/// The name of this dep kind.
pub name: &'static &'static str,
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_middle/src/dep_graph/dep_node_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId,
use rustc_hir::definitions::DefPathHash;
use rustc_hir::{HirId, ItemLocalId, OwnerId};

use crate::dep_graph::{DepContext, DepNode, DepNodeKey, FingerprintStyle};
use crate::dep_graph::{DepNode, DepNodeKey, FingerprintStyle};
use crate::ty::TyCtxt;

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for () {
impl<'tcx> DepNodeKey<'tcx> for () {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::Unit
Expand All @@ -23,7 +23,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for () {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for DefId {
impl<'tcx> DepNodeKey<'tcx> for DefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
Expand All @@ -45,7 +45,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for DefId {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalDefId {
impl<'tcx> DepNodeKey<'tcx> for LocalDefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
Expand All @@ -67,7 +67,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalDefId {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for OwnerId {
impl<'tcx> DepNodeKey<'tcx> for OwnerId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
Expand All @@ -89,7 +89,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for OwnerId {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for CrateNum {
impl<'tcx> DepNodeKey<'tcx> for CrateNum {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
Expand All @@ -112,7 +112,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for CrateNum {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for (DefId, DefId) {
impl<'tcx> DepNodeKey<'tcx> for (DefId, DefId) {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::Opaque
Expand All @@ -139,7 +139,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for (DefId, DefId) {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for HirId {
impl<'tcx> DepNodeKey<'tcx> for HirId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::HirId
Expand Down Expand Up @@ -182,7 +182,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for HirId {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for ModDefId {
impl<'tcx> DepNodeKey<'tcx> for ModDefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
Expand All @@ -204,7 +204,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for ModDefId {
}
}

impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalModDefId {
impl<'tcx> DepNodeKey<'tcx> for LocalModDefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
Expand Down
42 changes: 21 additions & 21 deletions compiler/rustc_middle/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use {super::debug::EdgeFilter, std::env};

use super::query::DepGraphQuery;
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
use super::{DepContext, DepKind, DepNode, DepsType, HasDepContext, WorkProductId};
use super::{DepKind, DepNode, DepsType, HasDepContext, WorkProductId};
use crate::dep_graph::edges::EdgesVec;
use crate::ty::TyCtxt;
use crate::verify_ich::incremental_verify_ich;
Expand Down Expand Up @@ -62,7 +62,7 @@ impl From<DepNodeIndex> for QueryInvocationId {
}
}

pub struct MarkFrame<'a> {
pub(crate) struct MarkFrame<'a> {
index: SerializedDepNodeIndex,
parent: Option<&'a MarkFrame<'a>>,
}
Expand Down Expand Up @@ -252,7 +252,7 @@ impl DepGraph {
}

#[inline(always)]
pub fn with_task<Ctxt: HasDepContext, A: Debug, R>(
pub fn with_task<'tcx, Ctxt: HasDepContext<'tcx>, A: Debug, R>(
&self,
key: DepNode,
cx: Ctxt,
Expand All @@ -266,9 +266,9 @@ impl DepGraph {
}
}

pub fn with_anon_task<Tcx: DepContext, OP, R>(
pub fn with_anon_task<'tcx, OP, R>(
&self,
cx: Tcx,
cx: TyCtxt<'tcx>,
dep_kind: DepKind,
op: OP,
) -> (R, DepNodeIndex)
Expand Down Expand Up @@ -315,7 +315,7 @@ impl DepGraphData {
///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
#[inline(always)]
pub fn with_task<Ctxt: HasDepContext, A: Debug, R>(
pub fn with_task<'tcx, Ctxt: HasDepContext<'tcx>, A: Debug, R>(
&self,
key: DepNode,
cx: Ctxt,
Expand All @@ -329,7 +329,7 @@ impl DepGraphData {
// 2. Two distinct query keys get mapped to the same `DepNode`
// (see for example #48923).
self.assert_dep_node_not_yet_allocated_in_current_session(
cx.dep_context().sess(),
cx.dep_context().sess,
&key,
|| {
format!(
Expand All @@ -352,8 +352,8 @@ impl DepGraphData {
(with_deps(TaskDepsRef::Allow(&task_deps)), task_deps.into_inner().reads)
};

let dcx = cx.dep_context();
let dep_node_index = self.hash_result_and_alloc_node(dcx, key, edges, &result, hash_result);
let dep_node_index =
self.hash_result_and_alloc_node(cx.dep_context(), key, edges, &result, hash_result);

(result, dep_node_index)
}
Expand All @@ -369,9 +369,9 @@ impl DepGraphData {
/// FIXME: This could perhaps return a `WithDepNode` to ensure that the
/// user of this function actually performs the read; we'll have to see
/// how to make that work with `anon` in `execute_job_incr`, though.
pub fn with_anon_task_inner<Tcx: DepContext, OP, R>(
pub fn with_anon_task_inner<'tcx, OP, R>(
&self,
cx: Tcx,
cx: TyCtxt<'tcx>,
dep_kind: DepKind,
op: OP,
) -> (R, DepNodeIndex)
Expand Down Expand Up @@ -438,17 +438,17 @@ impl DepGraphData {
}

/// Intern the new `DepNode` with the dependencies up-to-now.
fn hash_result_and_alloc_node<Ctxt: DepContext, R>(
fn hash_result_and_alloc_node<'tcx, R>(
&self,
cx: &Ctxt,
tcx: TyCtxt<'tcx>,
node: DepNode,
edges: EdgesVec,
result: &R,
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
) -> DepNodeIndex {
let hashing_timer = cx.profiler().incr_result_hashing();
let hashing_timer = tcx.prof.incr_result_hashing();
let current_fingerprint = hash_result.map(|hash_result| {
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
tcx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
});
let dep_node_index = self.alloc_and_color_node(node, edges, current_fingerprint);
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
Expand Down Expand Up @@ -553,10 +553,10 @@ impl DepGraph {
/// FIXME: If the code is changed enough for this node to be marked before requiring the
/// caller's node, we suppose that those changes will be enough to mark this node red and
/// force a recomputation using the "normal" way.
pub fn with_feed_task<Ctxt: DepContext, R>(
pub fn with_feed_task<'tcx, R>(
&self,
node: DepNode,
cx: Ctxt,
tcx: TyCtxt<'tcx>,
result: &R,
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
format_value_fn: fn(&R) -> String,
Expand All @@ -572,7 +572,7 @@ impl DepGraph {
let dep_node_index = data.colors.current(prev_index);
if let Some(dep_node_index) = dep_node_index {
incremental_verify_ich(
cx,
tcx,
data,
result,
prev_index,
Expand Down Expand Up @@ -605,7 +605,7 @@ impl DepGraph {
}
});

data.hash_result_and_alloc_node(&cx, node, edges, result, hash_result)
data.hash_result_and_alloc_node(tcx, node, edges, result, hash_result)
} else {
// Incremental compilation is turned off. We just execute the task
// without tracking. We still provide a dep-node index that uniquely
Expand Down Expand Up @@ -1051,8 +1051,8 @@ impl DepGraph {
///
/// This method will only load queries that will end up in the disk cache.
/// Other queries will not be executed.
pub fn exec_cache_promotions<Tcx: DepContext>(&self, tcx: Tcx) {
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
pub fn exec_cache_promotions<'tcx>(&self, tcx: TyCtxt<'tcx>) {
let _prof_timer = tcx.prof.generic_activity("incr_comp_query_cache_promotion");

let data = self.data.as_ref().unwrap();
for prev_index in data.colors.values.indices() {
Expand Down
Loading