From 2557800fd6bcb529a604b422b8fc8166e19f9977 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 22 Jun 2017 10:54:26 +0200 Subject: [PATCH] Split DepNode::ItemSignature into non-overlapping variants. --- src/librustc/dep_graph/README.md | 4 +-- src/librustc/dep_graph/dep_node.rs | 18 +++++++--- src/librustc/ty/maps.rs | 24 ++++++------- .../dep-graph-struct-signature.rs | 36 ++++++++++++------- src/test/compile-fail/dep-graph-type-alias.rs | 22 ++++++------ 5 files changed, 63 insertions(+), 41 deletions(-) diff --git a/src/librustc/dep_graph/README.md b/src/librustc/dep_graph/README.md index c747c443b3a..c8d0362f17c 100644 --- a/src/librustc/dep_graph/README.md +++ b/src/librustc/dep_graph/README.md @@ -16,7 +16,7 @@ The nodes of the graph are defined by the enum `DepNode`. They represent one of three things: 1. HIR nodes (like `Hir(DefId)`) represent the HIR input itself. -2. Data nodes (like `ItemSignature(DefId)`) represent some computed +2. Data nodes (like `TypeOfItem(DefId)`) represent some computed information about a particular item. 3. Procedure nodes (like `CoherenceCheckTrait(DefId)`) represent some procedure that is executing. Usually this procedure is @@ -289,7 +289,7 @@ to see something like: Hir(foo) -> Collect(bar) Collect(bar) -> TypeckTables(bar) - + That first edge looks suspicious to you. So you set `RUST_FORBID_DEP_GRAPH_EDGE` to `Hir&foo -> Collect&bar`, re-run, and then observe the backtrace. Voila, bug fixed! diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 92efeb7fd86..887a7a4fe04 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -387,11 +387,21 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode { // Nodes representing bits of computed IR in the tcx. Each shared // table in the tcx (or elsewhere) maps to one of these - // nodes. Often we map multiple tables to the same node if there - // is no point in distinguishing them (e.g., both the type and - // predicates for an item wind up in `ItemSignature`). + // nodes. AssociatedItems(DefId), - ItemSignature(DefId), + TypeOfItem(DefId), + GenericsOfItem(DefId), + PredicatesOfItem(DefId), + SuperPredicatesOfItem(DefId), + TraitDefOfItem(DefId), + AdtDefOfItem(DefId), + IsDefaultImpl(DefId), + ImplTraitRef(DefId), + ImplPolarity(DefId), + ClosureKind(DefId), + FnSignature(DefId), + CoerceUnsizedInfo(DefId), + ItemVarianceConstraints(DefId), ItemVariances(DefId), IsConstFn(DefId), diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index f4e333228c9..b584143c527 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -796,12 +796,12 @@ fn default() -> Self { // the driver creates (using several `rustc_*` crates). define_maps! { <'tcx> /// Records the type of every item. - [] type_of: ItemSignature(DefId) -> Ty<'tcx>, + [] type_of: TypeOfItem(DefId) -> Ty<'tcx>, /// Maps from the def-id of an item (trait/struct/enum/fn) to its /// associated generics and predicates. - [] generics_of: ItemSignature(DefId) -> &'tcx ty::Generics, - [] predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, + [] generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics, + [] predicates_of: PredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>, /// Maps from the def-id of a trait to the list of /// super-predicates. This is a subset of the full list of @@ -809,15 +809,15 @@ fn default() -> Self { /// evaluate them even during type conversion, often before the /// full predicates are available (note that supertraits have /// additional acyclicity requirements). - [] super_predicates_of: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, + [] super_predicates_of: SuperPredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>, /// To avoid cycles within the predicates of a single item we compute /// per-type-parameter predicates for resolving `T::AssocTy`. [] type_param_predicates: type_param_predicates((DefId, DefId)) -> ty::GenericPredicates<'tcx>, - [] trait_def: ItemSignature(DefId) -> &'tcx ty::TraitDef, - [] adt_def: ItemSignature(DefId) -> &'tcx ty::AdtDef, + [] trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef, + [] adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef, [] adt_destructor: AdtDestructor(DefId) -> Option, [] adt_sized_constraint: SizedConstraint(DefId) -> &'tcx [Ty<'tcx>], [] adt_dtorck_constraint: DtorckConstraint(DefId) -> ty::DtorckConstraint<'tcx>, @@ -829,7 +829,7 @@ fn default() -> Self { [] is_foreign_item: IsForeignItem(DefId) -> bool, /// True if this is a default impl (aka impl Foo for ..) - [] is_default_impl: ItemSignature(DefId) -> bool, + [] is_default_impl: IsDefaultImpl(DefId) -> bool, /// Get a map with the variance of every item; use `item_variance` /// instead. @@ -845,8 +845,8 @@ fn default() -> Self { /// Maps from a trait item to the trait item "descriptor" [] associated_item: AssociatedItems(DefId) -> ty::AssociatedItem, - [] impl_trait_ref: ItemSignature(DefId) -> Option>, - [] impl_polarity: ItemSignature(DefId) -> hir::ImplPolarity, + [] impl_trait_ref: ImplTraitRef(DefId) -> Option>, + [] impl_polarity: ImplPolarity(DefId) -> hir::ImplPolarity, /// Maps a DefId of a type to a list of its inherent impls. /// Contains implementations of methods that are inherent to a type. @@ -877,13 +877,13 @@ fn default() -> Self { /// Type of each closure. The def ID is the ID of the /// expression defining the closure. - [] closure_kind: ItemSignature(DefId) -> ty::ClosureKind, + [] closure_kind: ClosureKind(DefId) -> ty::ClosureKind, /// The signature of functions and closures. - [] fn_sig: ItemSignature(DefId) -> ty::PolyFnSig<'tcx>, + [] fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>, /// Caches CoerceUnsized kinds for impls on custom types. - [] coerce_unsized_info: ItemSignature(DefId) + [] coerce_unsized_info: CoerceUnsizedInfo(DefId) -> ty::adjustment::CoerceUnsizedInfo, [] typeck_item_bodies: typeck_item_bodies_dep_node(CrateNum) -> CompileResult, diff --git a/src/test/compile-fail/dep-graph-struct-signature.rs b/src/test/compile-fail/dep-graph-struct-signature.rs index 3f568194e23..647605ae438 100644 --- a/src/test/compile-fail/dep-graph-struct-signature.rs +++ b/src/test/compile-fail/dep-graph-struct-signature.rs @@ -34,54 +34,64 @@ struct WontChange { mod signatures { use WillChange; - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path + #[rustc_then_this_would_need(AssociatedItems)] //~ ERROR no path + #[rustc_then_this_would_need(TraitDefOfItem)] //~ ERROR no path trait Bar { - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK fn do_something(x: WillChange); } - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn some_fn(x: WillChange) { } - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn new_foo(x: u32, y: u32) -> WillChange { WillChange { x: x, y: y } } - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK impl WillChange { + #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn new(x: u32, y: u32) -> WillChange { loop { } } } - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK impl WillChange { + #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn method(&self, x: u32) { } } struct WillChanges { - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK x: WillChange, - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK y: WillChange } // The fields change, not the type itself. - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path fn indirect(x: WillChanges) { } } mod invalid_signatures { use WontChange; - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path trait A { + #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path fn do_something_else_twice(x: WontChange); } - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path + #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path + #[rustc_then_this_would_need(TypeckTables)] //~ ERROR no path fn b(x: WontChange) { } - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path from `WillChange` + #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path from `WillChange` + #[rustc_then_this_would_need(TypeckTables)] //~ ERROR no path from `WillChange` fn c(x: u32) { } } - diff --git a/src/test/compile-fail/dep-graph-type-alias.rs b/src/test/compile-fail/dep-graph-type-alias.rs index 56636a00a31..dca1fa4d98f 100644 --- a/src/test/compile-fail/dep-graph-type-alias.rs +++ b/src/test/compile-fail/dep-graph-type-alias.rs @@ -25,40 +25,42 @@ fn main() { } // The type alias directly affects the type of the field, // not the enclosing struct: -#[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path struct Struct { - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK x: TypeAlias, y: u32 } -#[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path enum Enum { Variant1 { - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK t: TypeAlias }, Variant2(i32) } -#[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path trait Trait { - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK fn method(&self, _: TypeAlias); } struct SomeType; -#[rustc_then_this_would_need(ItemSignature)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path impl SomeType { - #[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK + #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK + #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn method(&self, _: TypeAlias) {} } -#[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK +#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK type TypeAlias2 = TypeAlias; -#[rustc_then_this_would_need(ItemSignature)] //~ ERROR OK +#[rustc_then_this_would_need(FnSignature)] //~ ERROR OK +#[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn function(_: TypeAlias) { } -- 2.44.0