Skip to content

Commit 057eced

Browse files
committed
Remove generics from DepGraph
1 parent 92ea9b2 commit 057eced

File tree

20 files changed

+240
-198
lines changed

20 files changed

+240
-198
lines changed

compiler/rustc_codegen_ssa/src/assert_module_sources.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet};
3030
use rustc_errors::{DiagArgValue, IntoDiagArg};
3131
use rustc_hir as hir;
3232
use rustc_hir::def_id::LOCAL_CRATE;
33+
use rustc_middle::dep_graph::DepContext;
3334
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
3435
use rustc_middle::ty::TyCtxt;
3536
use rustc_session::Session;
@@ -41,7 +42,7 @@ use crate::errors;
4142

4243
#[allow(missing_docs)]
4344
pub fn assert_module_sources(tcx: TyCtxt<'_>, set_reuse: &dyn Fn(&mut CguReuseTracker)) {
44-
tcx.dep_graph.with_ignore(|| {
45+
tcx.with_ignore(|| {
4546
if tcx.sess.opts.incremental.is_none() {
4647
return;
4748
}

compiler/rustc_driver_impl/src/pretty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fmt::Write;
55

66
use rustc_ast_pretty::pprust as pprust_ast;
77
use rustc_middle::bug;
8+
use rustc_middle::dep_graph::DepContext;
89
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
910
use rustc_middle::ty::{self, TyCtxt};
1011
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
@@ -286,7 +287,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
286287
}
287288
PpHirMode::Typed => {
288289
let annotation = HirTypedAnn { tcx, maybe_typeck_results: Cell::new(None) };
289-
tcx.dep_graph.with_ignore(|| f(&annotation))
290+
tcx.with_ignore(|| f(&annotation))
290291
}
291292
}
292293
}

compiler/rustc_incremental/src/assert_dep_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_data_structures::graph::linked_graph::{Direction, INCOMING, NodeIndex,
4242
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
4343
use rustc_hir::intravisit::{self, Visitor};
4444
use rustc_middle::dep_graph::{
45-
DepGraphQuery, DepKind, DepNode, DepNodeExt, DepNodeFilter, EdgeFilter, dep_kinds,
45+
DepContext, DepGraphQuery, DepKind, DepNode, DepNodeExt, DepNodeFilter, EdgeFilter, dep_kinds,
4646
};
4747
use rustc_middle::hir::nested_filter;
4848
use rustc_middle::ty::TyCtxt;
@@ -55,7 +55,7 @@ use crate::errors;
5555

5656
#[allow(missing_docs)]
5757
pub(crate) fn assert_dep_graph(tcx: TyCtxt<'_>) {
58-
tcx.dep_graph.with_ignore(|| {
58+
tcx.with_ignore(|| {
5959
if tcx.sess.opts.unstable_opts.dump_dep_graph {
6060
tcx.dep_graph.with_query(dump_graph);
6161
}

compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_hir::def_id::LocalDefId;
2626
use rustc_hir::{
2727
Attribute, ImplItemKind, ItemKind as HirItem, Node as HirNode, TraitItemKind, intravisit,
2828
};
29-
use rustc_middle::dep_graph::{DepNode, DepNodeExt, dep_kind_from_label, label_strs};
29+
use rustc_middle::dep_graph::{DepContext, DepNode, DepNodeExt, dep_kind_from_label, label_strs};
3030
use rustc_middle::hir::nested_filter;
3131
use rustc_middle::ty::TyCtxt;
3232
use rustc_span::{Span, Symbol, sym};
@@ -144,7 +144,7 @@ pub(crate) fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
144144
return;
145145
}
146146

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

150150
let crate_items = tcx.hir_crate_items(());

compiler/rustc_incremental/src/persist/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66
use rustc_data_structures::memmap::Mmap;
77
use rustc_data_structures::unord::UnordMap;
88
use rustc_hashes::Hash64;
9-
use rustc_middle::dep_graph::{DepGraph, DepsType, SerializedDepGraph, WorkProductMap};
9+
use rustc_middle::dep_graph::{DEP_KIND_NAMES, DepGraph, SerializedDepGraph, WorkProductMap};
1010
use rustc_middle::query::on_disk_cache::OnDiskCache;
1111
use rustc_serialize::Decodable;
1212
use rustc_serialize::opaque::MemDecoder;
@@ -171,7 +171,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
171171
return LoadResult::DataOutOfDate;
172172
}
173173

174-
let dep_graph = SerializedDepGraph::decode::<DepsType>(&mut decoder);
174+
let dep_graph = SerializedDepGraph::decode(&mut decoder, DEP_KIND_NAMES);
175175

176176
LoadResult::Ok { data: (dep_graph, prev_work_products) }
177177
}

compiler/rustc_incremental/src/persist/save.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use std::sync::Arc;
44
use rustc_data_structures::fx::FxIndexMap;
55
use rustc_data_structures::sync::join;
66
use rustc_middle::dep_graph::{
7-
DepGraph, SerializedDepGraph, WorkProduct, WorkProductId, WorkProductMap,
7+
DEP_KIND_VARIANTS, DepContext, DepGraph, DepsType, SerializedDepGraph, WorkProduct,
8+
WorkProductId, WorkProductMap,
89
};
910
use rustc_middle::ty::TyCtxt;
1011
use rustc_serialize::Encodable as RustcEncodable;
@@ -27,7 +28,7 @@ use crate::errors;
2728
/// Trying to execute a query afterwards would attempt to read the result cache we just dropped.
2829
pub(crate) fn save_dep_graph(tcx: TyCtxt<'_>) {
2930
debug!("save_dep_graph()");
30-
tcx.dep_graph.with_ignore(|| {
31+
tcx.with_ignore(|| {
3132
let sess = tcx.sess;
3233
if sess.opts.incremental.is_none() {
3334
return;
@@ -89,7 +90,7 @@ pub fn save_work_product_index(
8990
}
9091

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

171-
Some(DepGraph::new(sess, prev_graph, prev_work_products, encoder))
172+
Some(DepGraph::new(sess, prev_graph, prev_work_products, encoder, DEP_KIND_VARIANTS as usize))
172173
}

compiler/rustc_interface/src/passes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_sto
2828
use rustc_metadata::EncodedMetadata;
2929
use rustc_metadata::creader::CStore;
3030
use rustc_middle::arena::Arena;
31+
use rustc_middle::dep_graph::DepsType;
3132
use rustc_middle::ty::{self, CurrentGcx, GlobalCtxt, RegisteredTools, TyCtxt};
3233
use rustc_middle::util::Providers;
3334
use rustc_parse::lexer::StripTokens;
@@ -951,7 +952,7 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
951952
// We're constructing the HIR here; we don't care what we will
952953
// read, since we haven't even constructed the *input* to
953954
// incr. comp. yet.
954-
dep_graph.assert_ignored();
955+
dep_graph.assert_ignored::<DepsType>();
955956

956957
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);
957958

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId,
1717
use rustc_hir::definitions::DefPathData;
1818
use rustc_hir::find_attr;
1919
use rustc_hir_pretty::id_to_string;
20-
use rustc_middle::dep_graph::WorkProductId;
20+
use rustc_middle::dep_graph::{DepContext, WorkProductId};
2121
use rustc_middle::middle::dependency_format::Linkage;
2222
use rustc_middle::mir::interpret;
2323
use rustc_middle::query::Providers;
@@ -2420,7 +2420,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
24202420
pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) {
24212421
// Since encoding metadata is not in a query, and nothing is cached,
24222422
// there's no need to do dep-graph tracking for any of it.
2423-
tcx.dep_graph.assert_ignored();
2423+
tcx.assert_ignored();
24242424

24252425
// Generate the metadata stub manually, as that is a small file compared to full metadata.
24262426
if let Some(ref_path) = ref_path {

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use rustc_hir::{HirId, ItemLocalId, OwnerId};
55
pub use rustc_query_system::dep_graph::DepNode;
66
use rustc_query_system::dep_graph::FingerprintStyle;
77
pub use rustc_query_system::dep_graph::dep_node::DepKind;
8+
use rustc_query_system::dep_graph::dep_node::{
9+
DEP_KIND_ANON_ZERO_DEPS, DEP_KIND_NULL, DEP_KIND_RED, DEP_KIND_SIDE_EFFECT,
10+
};
811
pub(crate) use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
912
use rustc_span::Symbol;
1013

@@ -47,7 +50,7 @@ macro_rules! define_dep_nodes {
4750

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

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

@@ -84,18 +87,25 @@ macro_rules! define_dep_nodes {
8487
// Create various data structures for each query, and also for a few things
8588
// that aren't queries.
8689
rustc_with_all_queries!(define_dep_nodes![
87-
/// We use this for most things when incr. comp. is turned off.
90+
// Make sure this list matches the BuiltinDepKinds enum.
8891
[] fn Null() -> (),
89-
/// We use this to create a forever-red node.
9092
[] fn Red() -> (),
9193
[] fn SideEffect() -> (),
9294
[] fn AnonZeroDeps() -> (),
95+
// End of list.
96+
9397
[] fn TraitSelect() -> (),
9498
[] fn CompileCodegenUnit() -> (),
9599
[] fn CompileMonoItem() -> (),
96100
[] fn Metadata() -> (),
97101
]);
98102

103+
// Test that the list matches.
104+
const _: () = assert!(dep_kinds::Null.as_inner() == DEP_KIND_NULL.as_inner());
105+
const _: () = assert!(dep_kinds::Red.as_inner() == DEP_KIND_RED.as_inner());
106+
const _: () = assert!(dep_kinds::SideEffect.as_inner() == DEP_KIND_SIDE_EFFECT.as_inner());
107+
const _: () = assert!(dep_kinds::AnonZeroDeps.as_inner() == DEP_KIND_ANON_ZERO_DEPS.as_inner());
108+
99109
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
100110
// Be very careful changing this type signature!
101111
pub(crate) fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_data_structures::profiling::SelfProfilerRef;
2+
use rustc_query_system::dep_graph::DEP_KIND_UNUSED_BITS;
23
use rustc_query_system::ich::StableHashingContext;
34
use rustc_session::Session;
45

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

11-
pub use dep_node::{DepKind, DepNode, DepNodeExt, dep_kind_from_label, dep_kinds, label_strs};
12+
pub use dep_node::{
13+
DEP_KIND_NAMES, DEP_KIND_VARIANTS, DepKind, DepNode, DepNodeExt, dep_kind_from_label,
14+
dep_kinds, label_strs,
15+
};
1216
pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item, make_metadata};
1317
pub use rustc_query_system::dep_graph::debug::{DepNodeFilter, EdgeFilter};
1418
pub use rustc_query_system::dep_graph::{
1519
DepContext, DepGraphQuery, DepNodeIndex, Deps, SerializedDepGraph, SerializedDepNodeIndex,
1620
TaskDepsRef, WorkProduct, WorkProductId, WorkProductMap, hash_result,
1721
};
1822

19-
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;
23+
pub type DepGraph = rustc_query_system::dep_graph::DepGraph;
2024

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

@@ -43,18 +47,12 @@ impl Deps for DepsType {
4347
op(icx.task_deps)
4448
})
4549
}
46-
47-
fn name(dep_kind: DepKind) -> &'static str {
48-
dep_node::DEP_KIND_NAMES[dep_kind.as_usize()]
49-
}
50-
51-
const DEP_KIND_NULL: DepKind = dep_kinds::Null;
52-
const DEP_KIND_RED: DepKind = dep_kinds::Red;
53-
const DEP_KIND_SIDE_EFFECT: DepKind = dep_kinds::SideEffect;
54-
const DEP_KIND_ANON_ZERO_DEPS: DepKind = dep_kinds::AnonZeroDeps;
55-
const DEP_KIND_MAX: u16 = dep_node::DEP_KIND_VARIANTS - 1;
5650
}
5751

52+
/// Verify that the unused bits for the dep kind matches the hardcoded value in `rustc_query_system`.
53+
const _: [(); (dep_node::DEP_KIND_VARIANTS - 1).leading_zeros() as usize] =
54+
[(); DEP_KIND_UNUSED_BITS];
55+
5856
impl<'tcx> DepContext for TyCtxt<'tcx> {
5957
type Deps = DepsType;
6058

0 commit comments

Comments
 (0)