Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4500,7 +4500,6 @@ dependencies = [
"rustc_index",
"rustc_macros",
"rustc_middle",
"rustc_query_system",
"rustc_serialize",
"rustc_session",
"rustc_span",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor};
use rustc_middle::bug;
use rustc_middle::dep_graph::{
DepGraphQuery, DepKind, DepNode, DepNodeExt, DepNodeFilter, EdgeFilter, dep_kinds,
DepGraphQuery, DepKind, DepNode, DepNodeFilter, EdgeFilter, dep_kinds,
};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustc_hir::{
Attribute, ImplItemKind, ItemKind as HirItem, Node as HirNode, TraitItemKind, find_attr,
intravisit,
};
use rustc_middle::dep_graph::{DepNode, DepNodeExt, dep_kind_from_label, label_strs};
use rustc_middle::dep_graph::{DepNode, dep_kind_from_label, label_strs};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;
use rustc_span::{Span, Symbol};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::unord::UnordMap;
use rustc_hashes::Hash64;
use rustc_middle::dep_graph::{DepGraph, DepsType, SerializedDepGraph, WorkProductMap};
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProductMap};
use rustc_middle::query::on_disk_cache::OnDiskCache;
use rustc_serialize::Decodable;
use rustc_serialize::opaque::MemDecoder;
Expand Down Expand Up @@ -171,7 +171,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
return LoadResult::DataOutOfDate;
}

let dep_graph = SerializedDepGraph::decode::<DepsType>(&mut decoder);
let dep_graph = SerializedDepGraph::decode(&mut decoder);

LoadResult::Ok { data: (dep_graph, prev_work_products) }
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_interface/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ 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, DepNodeExt, TaskDepsRef};
use rustc_middle::dep_graph::{DepKind, DepNode, TaskDepsRef};
use rustc_middle::ty::tls;
use rustc_query_impl::QueryCtxt;

fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
tls::with_context_opt(|icx| {
Expand All @@ -41,7 +40,7 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
fn track_diagnostic<R>(diagnostic: DiagInner, f: &mut dyn FnMut(DiagInner) -> R) -> R {
tls::with_context_opt(|icx| {
if let Some(icx) = icx {
icx.tcx.dep_graph.record_diagnostic(QueryCtxt::new(icx.tcx), &diagnostic);
icx.tcx.dep_graph.record_diagnostic(icx.tcx, &diagnostic);

// Diagnostics are tracked, we can ignore the dependency.
let icx = tls::ImplicitCtxt { task_deps: TaskDepsRef::Ignore, ..icx.clone() };
Expand Down
74 changes: 29 additions & 45 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 Expand Up @@ -434,19 +432,7 @@ pub(crate) fn make_metadata(tcx: TyCtxt<'_>) -> DepNode {
DepNode::construct(tcx, dep_kinds::Metadata, &())
}

pub trait DepNodeExt: Sized {
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;

fn from_label_string(
tcx: TyCtxt<'_>,
label: &str,
def_path_hash: DefPathHash,
) -> Result<Self, ()>;

fn has_label_string(label: &str) -> bool;
}

impl DepNodeExt for DepNode {
impl DepNode {
/// Extracts the DefId corresponding to this DepNode. This will work
/// if two conditions are met:
///
Expand All @@ -457,16 +443,15 @@ impl DepNodeExt for DepNode {
/// DepNode. Condition (2) might not be fulfilled if a DepNode
/// refers to something from the previous compilation session that
/// has been removed.
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
pub fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
if tcx.fingerprint_style(self.kind) == FingerprintStyle::DefPathHash {
tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into()))
} else {
None
}
}

/// Used in testing
fn from_label_string(
pub fn from_label_string(
tcx: TyCtxt<'_>,
label: &str,
def_path_hash: DefPathHash,
Expand All @@ -482,8 +467,7 @@ impl DepNodeExt for DepNode {
}
}

/// Used in testing
fn has_label_string(label: &str) -> bool {
pub fn has_label_string(label: &str) -> bool {
dep_kind_from_label_string(label).is_ok()
}
}
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, DepNodeExt, 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
Loading