Skip to content

Commit d692a91

Browse files
committed
Auto merge of #43590 - michaelwoerister:no-reopening-1, r=nikomatsakis
incr.comp.: Assert that no DepNode is re-opened (see issue #42298). This PR removes the last occurrence of DepNode re-opening and adds an assertion that prevents our doing so in the future too. The DepGraph should no be guaranteed to be cycle free. r? @nikomatsakis EDIT: Closes #42298
2 parents ff1135b + b34c5a2 commit d692a91

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

src/librustc/dep_graph/dep_node.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ use hir::map::DefPathHash;
6666
use ich::Fingerprint;
6767
use ty::{TyCtxt, Instance, InstanceDef};
6868
use ty::fast_reject::SimplifiedType;
69-
use ty::subst::Substs;
7069
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
7170
use ich::StableHashingContext;
7271
use std::fmt;
@@ -104,6 +103,8 @@ macro_rules! define_dep_nodes {
104103
match *self {
105104
$(
106105
DepKind :: $variant => {
106+
$(return !anon_attr_to_bool!($anon);)*
107+
107108
// tuple args
108109
$({
109110
return <( $($tuple_arg,)* ) as DepNodeParams>
@@ -112,6 +113,7 @@ macro_rules! define_dep_nodes {
112113

113114
// struct args
114115
$({
116+
115117
return <( $($struct_arg_ty,)* ) as DepNodeParams>
116118
::CAN_RECONSTRUCT_QUERY_KEY;
117119
})*
@@ -394,6 +396,7 @@ define_dep_nodes!( <'tcx>
394396
// Represents different phases in the compiler.
395397
[] RegionMaps(DefId),
396398
[] Coherence,
399+
[] CoherenceInherentImplOverlapCheck,
397400
[] Resolve,
398401
[] CoherenceCheckTrait(DefId),
399402
[] PrivacyAccessLevels(CrateNum),
@@ -444,17 +447,17 @@ define_dep_nodes!( <'tcx>
444447
[] TypeckBodiesKrate,
445448
[] TypeckTables(DefId),
446449
[] HasTypeckTables(DefId),
447-
[] ConstEval { def_id: DefId, substs: &'tcx Substs<'tcx> },
450+
[anon] ConstEval,
448451
[] SymbolName(DefId),
449452
[] InstanceSymbolName { instance: Instance<'tcx> },
450453
[] SpecializationGraph(DefId),
451454
[] ObjectSafety(DefId),
452455

453-
[anon] IsCopy(DefId),
454-
[anon] IsSized(DefId),
455-
[anon] IsFreeze(DefId),
456-
[anon] NeedsDrop(DefId),
457-
[anon] Layout(DefId),
456+
[anon] IsCopy,
457+
[anon] IsSized,
458+
[anon] IsFreeze,
459+
[anon] NeedsDrop,
460+
[anon] Layout,
458461

459462
// The set of impls for a given trait.
460463
[] TraitImpls(DefId),

src/librustc/dep_graph/edges.rs

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ pub struct DepGraphEdges {
2323
edges: FxHashSet<(DepNodeIndex, DepNodeIndex)>,
2424
task_stack: Vec<OpenTask>,
2525
forbidden_edge: Option<EdgeFilter>,
26+
27+
// A set to help assert that no two tasks use the same DepNode. This is a
28+
// temporary measure. Once we load the previous dep-graph as readonly, this
29+
// check will fall out of the graph implementation naturally.
30+
opened_once: FxHashSet<DepNode>,
2631
}
2732

2833
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
@@ -80,6 +85,7 @@ impl DepGraphEdges {
8085
edges: FxHashSet(),
8186
task_stack: Vec::new(),
8287
forbidden_edge,
88+
opened_once: FxHashSet(),
8389
}
8490
}
8591

@@ -97,6 +103,10 @@ impl DepGraphEdges {
97103
}
98104

99105
pub fn push_task(&mut self, key: DepNode) {
106+
if !self.opened_once.insert(key) {
107+
bug!("Re-opened node {:?}", key)
108+
}
109+
100110
self.task_stack.push(OpenTask::Regular {
101111
node: key,
102112
reads: Vec::new(),

src/librustc/ty/maps.rs

+18-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use dep_graph::{DepConstructor, DepNode, DepNodeIndex};
12-
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
12+
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1313
use hir::def::Def;
1414
use hir;
1515
use middle::const_val;
@@ -931,7 +931,7 @@ define_maps! { <'tcx>
931931
/// Checks all types in the krate for overlap in their inherent impls. Reports errors.
932932
/// Not meant to be used directly outside of coherence.
933933
/// (Defined only for LOCAL_CRATE)
934-
[] crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node(CrateNum) -> (),
934+
[] crate_inherent_impls_overlap_check: inherent_impls_overlap_check_dep_node(CrateNum) -> (),
935935

936936
/// Results of evaluating const items or constants embedded in
937937
/// other items (such as enum variant explicit discriminants).
@@ -1014,6 +1014,10 @@ fn crate_inherent_impls_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
10141014
DepConstructor::Coherence
10151015
}
10161016

1017+
fn inherent_impls_overlap_check_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
1018+
DepConstructor::CoherenceInherentImplOverlapCheck
1019+
}
1020+
10171021
fn reachability_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
10181022
DepConstructor::Reachability
10191023
}
@@ -1032,10 +1036,9 @@ fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
10321036
DepConstructor::TypeckBodiesKrate
10331037
}
10341038

1035-
fn const_eval_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
1039+
fn const_eval_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
10361040
-> DepConstructor<'tcx> {
1037-
let (def_id, substs) = key.value;
1038-
DepConstructor::ConstEval { def_id, substs }
1041+
DepConstructor::ConstEval
10391042
}
10401043

10411044
fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
@@ -1050,32 +1053,22 @@ fn relevant_trait_impls_for<'tcx>((def_id, t): (DefId, SimplifiedType)) -> DepCo
10501053
DepConstructor::RelevantTraitImpls(def_id, t)
10511054
}
10521055

1053-
fn is_copy_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1054-
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1055-
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
1056-
DepConstructor::IsCopy(def_id)
1056+
fn is_copy_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1057+
DepConstructor::IsCopy
10571058
}
10581059

1059-
fn is_sized_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1060-
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1061-
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
1062-
DepConstructor::IsSized(def_id)
1060+
fn is_sized_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1061+
DepConstructor::IsSized
10631062
}
10641063

1065-
fn is_freeze_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1066-
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1067-
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
1068-
DepConstructor::IsFreeze(def_id)
1064+
fn is_freeze_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1065+
DepConstructor::IsFreeze
10691066
}
10701067

1071-
fn needs_drop_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1072-
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1073-
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
1074-
DepConstructor::NeedsDrop(def_id)
1068+
fn needs_drop_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1069+
DepConstructor::NeedsDrop
10751070
}
10761071

1077-
fn layout_dep_node<'tcx>(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1078-
let def_id = ty::item_path::characteristic_def_id_of_type(key.value)
1079-
.unwrap_or(DefId::local(CRATE_DEF_INDEX));
1080-
DepConstructor::Layout(def_id)
1072+
fn layout_dep_node<'tcx>(_: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConstructor<'tcx> {
1073+
DepConstructor::Layout
10811074
}

0 commit comments

Comments
 (0)