Skip to content

Commit 024e3aa

Browse files
committed
Rollup merge of rust-lang#47696 - Zoxc:variance-rg, r=nikomatsakis
Make use of the implemented red/green algorithm for variance r? @michaelwoerister
2 parents 0ee698e + 62afc43 commit 024e3aa

File tree

3 files changed

+2
-49
lines changed

3 files changed

+2
-49
lines changed

src/librustc_typeck/variance/constraints.rs

+1-44
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
1414
//! We walk the set of items and, for each member, generate new constraints.
1515
1616
use hir::def_id::DefId;
17-
use rustc::dep_graph::{DepGraphSafe, DepKind, DepNodeColor};
18-
use rustc::ich::StableHashingContext;
1917
use rustc::ty::subst::Substs;
2018
use rustc::ty::{self, Ty, TyCtxt};
2119
use syntax::ast;
2220
use rustc::hir;
2321
use rustc::hir::itemlikevisit::ItemLikeVisitor;
2422

25-
use rustc_data_structures::stable_hasher::StableHashingContextProvider;
26-
2723
use super::terms::*;
2824
use super::terms::VarianceTerm::*;
2925

@@ -132,50 +128,11 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
132128
}
133129
}
134130

135-
impl<'a, 'tcx> StableHashingContextProvider for ConstraintContext<'a, 'tcx> {
136-
type ContextType = StableHashingContext<'tcx>;
137-
138-
fn create_stable_hashing_context(&self) -> Self::ContextType {
139-
self.terms_cx.tcx.create_stable_hashing_context()
140-
}
141-
}
142-
143-
impl<'a, 'tcx> DepGraphSafe for ConstraintContext<'a, 'tcx> {}
144-
145131
impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
146132
fn visit_node_helper(&mut self, id: ast::NodeId) {
147133
let tcx = self.terms_cx.tcx;
148134
let def_id = tcx.hir.local_def_id(id);
149-
150-
// Encapsulate constructing the constraints into a task we can
151-
// reference later. This can go away once the red-green
152-
// algorithm is in place.
153-
//
154-
// See README.md for a detailed discussion
155-
// on dep-graph management.
156-
let dep_node = def_id.to_dep_node(tcx, DepKind::ItemVarianceConstraints);
157-
158-
if let Some(DepNodeColor::Green(_)) = tcx.dep_graph.node_color(&dep_node) {
159-
// If the corresponding node has already been marked as green, the
160-
// appropriate portion of the DepGraph has already been loaded from
161-
// the previous graph, so we don't do any dep-tracking. Since we
162-
// don't cache any values though, we still have to re-run the
163-
// computation.
164-
tcx.dep_graph.with_ignore(|| {
165-
self.build_constraints_for_item(def_id);
166-
});
167-
} else {
168-
tcx.dep_graph.with_task(dep_node,
169-
self,
170-
def_id,
171-
visit_item_task);
172-
}
173-
174-
fn visit_item_task<'a, 'tcx>(ccx: &mut ConstraintContext<'a, 'tcx>,
175-
def_id: DefId)
176-
{
177-
ccx.build_constraints_for_item(def_id);
178-
}
135+
self.build_constraints_for_item(def_id);
179136
}
180137

181138
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {

src/librustc_typeck/variance/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! parameters. See README.md for details.
1313
1414
use arena;
15-
use rustc::dep_graph::DepKind;
1615
use rustc::hir;
1716
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1817
use rustc::ty::{self, CrateVariancesMap, TyCtxt};
@@ -95,9 +94,6 @@ fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
9594
// Everything else must be inferred.
9695

9796
let crate_map = tcx.crate_variances(LOCAL_CRATE);
98-
let dep_node = item_def_id.to_dep_node(tcx, DepKind::ItemVarianceConstraints);
99-
tcx.dep_graph.read(dep_node);
100-
10197
crate_map.variances.get(&item_def_id)
10298
.unwrap_or(&crate_map.empty_variance)
10399
.clone()

src/test/compile-fail/dep-graph-variance-alias.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct Foo<T> {
2323
f: T
2424
}
2525

26-
#[rustc_if_this_changed]
26+
#[rustc_if_this_changed(Krate)]
2727
type TypeAlias<T> = Foo<T>;
2828

2929
#[rustc_then_this_would_need(ItemVariances)] //~ ERROR OK

0 commit comments

Comments
 (0)