From 62afc43a84e64b18aff98067c0ea09adfc39b66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Wed, 24 Jan 2018 03:51:02 +0100 Subject: [PATCH] Make use of the implemented red/green algorithm for variance --- src/librustc_typeck/variance/constraints.rs | 45 +------------------ src/librustc_typeck/variance/mod.rs | 4 -- .../compile-fail/dep-graph-variance-alias.rs | 2 +- 3 files changed, 2 insertions(+), 49 deletions(-) diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 0ed9b14b9d1d4..f7e10a4a47d37 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -14,16 +14,12 @@ //! We walk the set of items and, for each member, generate new constraints. use hir::def_id::DefId; -use rustc::dep_graph::{DepGraphSafe, DepKind, DepNodeColor}; -use rustc::ich::StableHashingContext; use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TyCtxt}; use syntax::ast; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; -use rustc_data_structures::stable_hasher::StableHashingContextProvider; - use super::terms::*; use super::terms::VarianceTerm::*; @@ -132,50 +128,11 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { } } -impl<'a, 'tcx> StableHashingContextProvider for ConstraintContext<'a, 'tcx> { - type ContextType = StableHashingContext<'tcx>; - - fn create_stable_hashing_context(&self) -> Self::ContextType { - self.terms_cx.tcx.create_stable_hashing_context() - } -} - -impl<'a, 'tcx> DepGraphSafe for ConstraintContext<'a, 'tcx> {} - impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { fn visit_node_helper(&mut self, id: ast::NodeId) { let tcx = self.terms_cx.tcx; let def_id = tcx.hir.local_def_id(id); - - // Encapsulate constructing the constraints into a task we can - // reference later. This can go away once the red-green - // algorithm is in place. - // - // See README.md for a detailed discussion - // on dep-graph management. - let dep_node = def_id.to_dep_node(tcx, DepKind::ItemVarianceConstraints); - - if let Some(DepNodeColor::Green(_)) = tcx.dep_graph.node_color(&dep_node) { - // If the corresponding node has already been marked as green, the - // appropriate portion of the DepGraph has already been loaded from - // the previous graph, so we don't do any dep-tracking. Since we - // don't cache any values though, we still have to re-run the - // computation. - tcx.dep_graph.with_ignore(|| { - self.build_constraints_for_item(def_id); - }); - } else { - tcx.dep_graph.with_task(dep_node, - self, - def_id, - visit_item_task); - } - - fn visit_item_task<'a, 'tcx>(ccx: &mut ConstraintContext<'a, 'tcx>, - def_id: DefId) - { - ccx.build_constraints_for_item(def_id); - } + self.build_constraints_for_item(def_id); } fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index 418d2b9467096..003ee6f25995d 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -12,7 +12,6 @@ //! parameters. See README.md for details. use arena; -use rustc::dep_graph::DepKind; use rustc::hir; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::ty::{self, CrateVariancesMap, TyCtxt}; @@ -95,9 +94,6 @@ fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId) // Everything else must be inferred. let crate_map = tcx.crate_variances(LOCAL_CRATE); - let dep_node = item_def_id.to_dep_node(tcx, DepKind::ItemVarianceConstraints); - tcx.dep_graph.read(dep_node); - crate_map.variances.get(&item_def_id) .unwrap_or(&crate_map.empty_variance) .clone() diff --git a/src/test/compile-fail/dep-graph-variance-alias.rs b/src/test/compile-fail/dep-graph-variance-alias.rs index 9b621a13fc484..18cfd00180428 100644 --- a/src/test/compile-fail/dep-graph-variance-alias.rs +++ b/src/test/compile-fail/dep-graph-variance-alias.rs @@ -23,7 +23,7 @@ struct Foo { f: T } -#[rustc_if_this_changed] +#[rustc_if_this_changed(Krate)] type TypeAlias = Foo; #[rustc_then_this_would_need(ItemVariances)] //~ ERROR OK