Skip to content

Commit

Permalink
Make use of the implemented red/green algorithm for variance
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jan 24, 2018
1 parent fdecb05 commit 62afc43
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 49 deletions.
45 changes: 1 addition & 44 deletions src/librustc_typeck/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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> {
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_typeck/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/dep-graph-variance-alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Foo<T> {
f: T
}

#[rustc_if_this_changed]
#[rustc_if_this_changed(Krate)]
type TypeAlias<T> = Foo<T>;

#[rustc_then_this_would_need(ItemVariances)] //~ ERROR OK
Expand Down

0 comments on commit 62afc43

Please sign in to comment.