Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::dep_graph::DepContext;
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
Expand All @@ -41,7 +42,7 @@ use crate::errors;

#[allow(missing_docs)]
pub fn assert_module_sources(tcx: TyCtxt<'_>, set_reuse: &dyn Fn(&mut CguReuseTracker)) {
tcx.dep_graph.with_ignore(|| {
tcx.with_ignore(|| {
if tcx.sess.opts.incremental.is_none() {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_driver_impl/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fmt::Write;

use rustc_ast_pretty::pprust as pprust_ast;
use rustc_middle::bug;
use rustc_middle::dep_graph::DepContext;
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
Expand Down Expand Up @@ -286,7 +287,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
}
PpHirMode::Typed => {
let annotation = HirTypedAnn { tcx, maybe_typeck_results: Cell::new(None) };
tcx.dep_graph.with_ignore(|| f(&annotation))
tcx.with_ignore(|| f(&annotation))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_incremental/src/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use rustc_data_structures::graph::linked_graph::{Direction, INCOMING, NodeIndex,
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor};
use rustc_middle::dep_graph::{
DepGraphQuery, DepKind, DepNode, DepNodeExt, DepNodeFilter, EdgeFilter, dep_kinds,
DepContext, DepGraphQuery, DepKind, DepNode, DepNodeExt, DepNodeFilter, EdgeFilter, dep_kinds,
};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;
Expand All @@ -55,7 +55,7 @@ use crate::errors;

#[allow(missing_docs)]
pub(crate) fn assert_dep_graph(tcx: TyCtxt<'_>) {
tcx.dep_graph.with_ignore(|| {
tcx.with_ignore(|| {
if tcx.sess.opts.unstable_opts.dump_dep_graph {
tcx.dep_graph.with_query(dump_graph);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_incremental/src/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_hir::def_id::LocalDefId;
use rustc_hir::{
Attribute, ImplItemKind, ItemKind as HirItem, Node as HirNode, TraitItemKind, intravisit,
};
use rustc_middle::dep_graph::{DepNode, DepNodeExt, dep_kind_from_label, label_strs};
use rustc_middle::dep_graph::{DepContext, DepNode, DepNodeExt, dep_kind_from_label, label_strs};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;
use rustc_span::{Span, Symbol, sym};
Expand Down Expand Up @@ -144,7 +144,7 @@ pub(crate) fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
return;
}

tcx.dep_graph.with_ignore(|| {
tcx.with_ignore(|| {
let mut dirty_clean_visitor = DirtyCleanVisitor { tcx, checked_attrs: Default::default() };

let crate_items = tcx.hir_crate_items(());
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::{DEP_KIND_NAMES, 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, DEP_KIND_NAMES);

LoadResult::Ok { data: (dep_graph, prev_work_products) }
}
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_incremental/src/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::sync::Arc;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::join;
use rustc_middle::dep_graph::{
DepGraph, SerializedDepGraph, WorkProduct, WorkProductId, WorkProductMap,
DEP_KIND_VARIANTS, DepContext, DepGraph, DepsType, SerializedDepGraph, WorkProduct,
WorkProductId, WorkProductMap,
};
use rustc_middle::ty::TyCtxt;
use rustc_serialize::Encodable as RustcEncodable;
Expand All @@ -27,7 +28,7 @@ use crate::errors;
/// Trying to execute a query afterwards would attempt to read the result cache we just dropped.
pub(crate) fn save_dep_graph(tcx: TyCtxt<'_>) {
debug!("save_dep_graph()");
tcx.dep_graph.with_ignore(|| {
tcx.with_ignore(|| {
let sess = tcx.sess;
if sess.opts.incremental.is_none() {
return;
Expand Down Expand Up @@ -89,7 +90,7 @@ pub fn save_work_product_index(
}

debug!("save_work_product_index()");
dep_graph.assert_ignored();
dep_graph.assert_ignored::<DepsType>();
let path = work_products_path(sess);
file_format::save_in(sess, path, "work product index", |mut e| {
encode_work_product_index(&new_work_products, &mut e);
Expand Down Expand Up @@ -168,5 +169,5 @@ pub(crate) fn build_dep_graph(
// First encode the commandline arguments hash
sess.opts.dep_tracking_hash(false).encode(&mut encoder);

Some(DepGraph::new(sess, prev_graph, prev_work_products, encoder))
Some(DepGraph::new(sess, prev_graph, prev_work_products, encoder, DEP_KIND_VARIANTS as usize))
}
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_sto
use rustc_metadata::EncodedMetadata;
use rustc_metadata::creader::CStore;
use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::DepsType;
use rustc_middle::ty::{self, CurrentGcx, GlobalCtxt, RegisteredTools, TyCtxt};
use rustc_middle::util::Providers;
use rustc_parse::lexer::StripTokens;
Expand Down Expand Up @@ -951,7 +952,7 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
// We're constructing the HIR here; we don't care what we will
// read, since we haven't even constructed the *input* to
// incr. comp. yet.
dep_graph.assert_ignored();
dep_graph.assert_ignored::<DepsType>();

let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId,
use rustc_hir::definitions::DefPathData;
use rustc_hir::find_attr;
use rustc_hir_pretty::id_to_string;
use rustc_middle::dep_graph::WorkProductId;
use rustc_middle::dep_graph::{DepContext, WorkProductId};
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::mir::interpret;
use rustc_middle::query::Providers;
Expand Down Expand Up @@ -2420,7 +2420,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
// Since encoding metadata is not in a query, and nothing is cached,
// there's no need to do dep-graph tracking for any of it.
tcx.dep_graph.assert_ignored();
tcx.assert_ignored();

// Generate the metadata stub manually, as that is a small file compared to full metadata.
if let Some(ref_path) = ref_path {
Expand Down
20 changes: 16 additions & 4 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use rustc_hir::{HirId, ItemLocalId, OwnerId};
pub use rustc_query_system::dep_graph::DepNode;
use rustc_query_system::dep_graph::FingerprintStyle;
pub use rustc_query_system::dep_graph::dep_node::DepKind;
use rustc_query_system::dep_graph::dep_node::{
DEP_KIND_ANON_ZERO_DEPS, DEP_KIND_NULL, DEP_KIND_RED, DEP_KIND_SIDE_EFFECT,
};
pub(crate) use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
use rustc_span::Symbol;

Expand Down Expand Up @@ -47,7 +50,7 @@ macro_rules! define_dep_nodes {

// This checks that the discriminants of the variants have been assigned consecutively
// from 0 so that they can be used as a dense index.
pub(crate) const DEP_KIND_VARIANTS: u16 = {
pub const DEP_KIND_VARIANTS: u16 = {
let deps = &[$(dep_kinds::$variant,)*];
let mut i = 0;
while i < deps.len() {
Expand All @@ -61,7 +64,7 @@ macro_rules! define_dep_nodes {

/// List containing the name of each dep kind as a static string,
/// indexable by `DepKind`.
pub(crate) const DEP_KIND_NAMES: &[&str] = &[
pub const DEP_KIND_NAMES: &[&str] = &[
$( self::label_strs::$variant, )*
];

Expand All @@ -84,18 +87,27 @@ macro_rules! define_dep_nodes {
// Create various data structures for each query, and also for a few things
// that aren't queries.
rustc_with_all_queries!(define_dep_nodes![
/// We use this for most things when incr. comp. is turned off.
// Make sure this list matches the BuiltinDepKinds enum.
[] fn Null() -> (),
/// We use this to create a forever-red node.
[] fn Red() -> (),
[] fn SideEffect() -> (),
[] fn AnonZeroDeps() -> (),
// End of list.

[] fn TraitSelect() -> (),
[] fn CompileCodegenUnit() -> (),
[] fn CompileMonoItem() -> (),
[] fn Metadata() -> (),
]);

const _: () = {
// Test that the list matches.
assert!(dep_kinds::Null.as_inner() == DEP_KIND_NULL.as_inner());
assert!(dep_kinds::Red.as_inner() == DEP_KIND_RED.as_inner());
assert!(dep_kinds::SideEffect.as_inner() == DEP_KIND_SIDE_EFFECT.as_inner());
assert!(dep_kinds::AnonZeroDeps.as_inner() == DEP_KIND_ANON_ZERO_DEPS.as_inner());
};

// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
// Be very careful changing this type signature!
pub(crate) fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {
Expand Down
21 changes: 9 additions & 12 deletions compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_query_system::dep_graph::{DEP_KIND_UNUSED_BITS, unused_dep_kind_bits};
use rustc_query_system::ich::StableHashingContext;
use rustc_session::Session;

Expand All @@ -8,15 +9,18 @@ use crate::ty::{self, TyCtxt};
#[macro_use]
mod dep_node;

pub use dep_node::{DepKind, DepNode, DepNodeExt, dep_kind_from_label, dep_kinds, label_strs};
pub use dep_node::{
DEP_KIND_NAMES, DEP_KIND_VARIANTS, DepKind, DepNode, DepNodeExt, dep_kind_from_label,
dep_kinds, label_strs,
};
pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item, make_metadata};
pub use rustc_query_system::dep_graph::debug::{DepNodeFilter, EdgeFilter};
pub use rustc_query_system::dep_graph::{
DepContext, DepGraphQuery, DepNodeIndex, Deps, SerializedDepGraph, SerializedDepNodeIndex,
TaskDepsRef, WorkProduct, WorkProductId, WorkProductMap, hash_result,
};

pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;
pub type DepGraph = rustc_query_system::dep_graph::DepGraph;

pub type DepKindVTable<'tcx> = rustc_query_system::dep_graph::DepKindVTable<TyCtxt<'tcx>>;

Expand All @@ -43,18 +47,11 @@ impl Deps for DepsType {
op(icx.task_deps)
})
}

fn name(dep_kind: DepKind) -> &'static str {
dep_node::DEP_KIND_NAMES[dep_kind.as_usize()]
}

const DEP_KIND_NULL: DepKind = dep_kinds::Null;
const DEP_KIND_RED: DepKind = dep_kinds::Red;
const DEP_KIND_SIDE_EFFECT: DepKind = dep_kinds::SideEffect;
const DEP_KIND_ANON_ZERO_DEPS: DepKind = dep_kinds::AnonZeroDeps;
const DEP_KIND_MAX: u16 = dep_node::DEP_KIND_VARIANTS - 1;
}

/// Verify that the unused bits for the dep kind matches the hardcoded value in `rustc_query_system`.
const _: [(); unused_dep_kind_bits(dep_node::DEP_KIND_VARIANTS)] = [(); DEP_KIND_UNUSED_BITS];

impl<'tcx> DepContext for TyCtxt<'tcx> {
type Deps = DepsType;

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId, Stab
use rustc_hir::definitions::DefPathHash;
use rustc_index::{Idx, IndexVec};
use rustc_macros::{Decodable, Encodable};
use rustc_query_system::dep_graph::DepContext;
use rustc_query_system::query::QuerySideEffect;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
Expand Down Expand Up @@ -222,7 +223,7 @@ impl OnDiskCache {

pub fn serialize(&self, tcx: TyCtxt<'_>, encoder: FileEncoder) -> FileEncodeResult {
// Serializing the `DepGraph` should not modify it.
tcx.dep_graph.with_ignore(|| {
tcx.with_ignore(|| {
// Allocate `SourceFileIndex`es.
let (file_to_file_index, file_index_to_stable_id) = {
let files = tcx.sess.source_map().files();
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use rustc_hir::limit::Limit;
use rustc_hir::{self as hir, HirId, Node, TraitCandidate, find_attr};
use rustc_index::IndexVec;
use rustc_query_system::cache::WithDepNode;
use rustc_query_system::dep_graph::DepNodeIndex;
use rustc_query_system::dep_graph::{DepContext, DepNodeIndex};
use rustc_query_system::ich::StableHashingContext;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_session::Session;
Expand Down Expand Up @@ -1423,7 +1423,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Can only be fed before queries are run, and is thus exempt from any
/// incremental issues. Do not use except for the initial query feeding.
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
self.dep_graph.assert_ignored();
self.assert_ignored();
TyCtxtFeed { tcx: self, key: () }
}

Expand Down Expand Up @@ -2161,7 +2161,7 @@ impl<'tcx> TyCtxt<'tcx> {
// We need to ensure that these side effects are re-run by the incr. comp. engine.
// Depending on the forever-red node will tell the graph that the calling query
// needs to be re-evaluated.
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
self.read_index(DepNodeIndex::FOREVER_RED_NODE);

let feed = TyCtxtFeed { tcx: self, key: def_id };
feed.def_kind(def_kind);
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use rustc_hir::limit::Limit;
use rustc_index::Idx;
use rustc_middle::bug;
use rustc_middle::dep_graph::{
self, DepContext, DepKind, DepKindVTable, DepNode, DepNodeIndex, SerializedDepNodeIndex,
dep_kinds,
self, DepContext, DepKind, DepKindVTable, DepNode, DepNodeIndex, DepsType,
SerializedDepNodeIndex, dep_kinds,
};
use rustc_middle::query::Key;
use rustc_middle::query::on_disk_cache::{
Expand Down Expand Up @@ -468,9 +468,9 @@ where
// The call to `with_query_deserialization` enforces that no new `DepNodes`
// are created during deserialization. See the docs of that method for more
// details.
let value = tcx
.dep_graph
.with_query_deserialization(|| on_disk_cache.try_load_query_result(tcx, prev_index));
let value = tcx.dep_graph.with_query_deserialization::<DepsType, _, _>(|| {
on_disk_cache.try_load_query_result(tcx, prev_index)
});

prof_timer.finish_with_query_invocation_id(index.into());

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<T: Clone> WithDepNode<T> {
}

pub fn get<Tcx: DepContext>(&self, tcx: Tcx) -> T {
tcx.dep_graph().read_index(self.dep_node);
tcx.read_index(self.dep_node);
self.cached_value.clone()
}
}
24 changes: 23 additions & 1 deletion compiler/rustc_query_system/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ impl DepKind {
}
}

/// This must match the use of the define_dep_nodes! macro.
#[repr(u16)]
enum BuiltinDepKinds {
/// We use this for most things when incr. comp. is turned off.
Null,

/// We use this to create a forever-red node.
Red,

/// We use this to create a side effect node.
SideEffect,

/// We use this to create the anon node with zero dependencies.
AnonZeroDeps,
}

pub const DEP_KIND_NULL: DepKind = DepKind::new(BuiltinDepKinds::Null as u16);
pub const DEP_KIND_RED: DepKind = DepKind::new(BuiltinDepKinds::Red as u16);
pub const DEP_KIND_SIDE_EFFECT: DepKind = DepKind::new(BuiltinDepKinds::SideEffect as u16);
pub const DEP_KIND_ANON_ZERO_DEPS: DepKind = DepKind::new(BuiltinDepKinds::AnonZeroDeps as u16);

pub fn default_dep_kind_debug(kind: DepKind, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("DepKind").field("variant", &kind.variant).finish()
}
Expand Down Expand Up @@ -135,7 +156,8 @@ impl DepNode {
&& (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(tcx, dep_node, || arg.to_debug_str(tcx));
}
}

Expand Down
Loading
Loading