Skip to content

Commit 92ff8ea

Browse files
committed
Auto merge of #21523 - nikomatsakis:issue-21245-japaric-ti-failure, r=eddyb
This also includes some miscellaneous cleanup. This is kind of a band-aid but it fixes the problems @japaric was encountering. r? @eddyb
2 parents 7774359 + 8d6786c commit 92ff8ea

19 files changed

+326
-125
lines changed

src/librustc/middle/infer/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,13 @@ pub struct InferCtxt<'a, 'tcx: 'a> {
7979
type_variables: RefCell<type_variable::TypeVariableTable<'tcx>>,
8080

8181
// Map from integral variable to the kind of integer it represents
82-
int_unification_table:
83-
RefCell<UnificationTable<ty::IntVid, Option<IntVarValue>>>,
82+
int_unification_table: RefCell<UnificationTable<ty::IntVid>>,
8483

8584
// Map from floating variable to the kind of float it represents
86-
float_unification_table:
87-
RefCell<UnificationTable<ty::FloatVid, Option<ast::FloatTy>>>,
85+
float_unification_table: RefCell<UnificationTable<ty::FloatVid>>,
8886

8987
// For region variables.
90-
region_vars:
91-
RegionVarBindings<'a, 'tcx>,
88+
region_vars: RegionVarBindings<'a, 'tcx>,
9289
}
9390

9491
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized

src/librustc/middle/infer/type_variable.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::u32;
1919
use util::snapshot_vec as sv;
2020

2121
pub struct TypeVariableTable<'tcx> {
22-
values: sv::SnapshotVec<TypeVariableData<'tcx>,UndoEntry,Delegate>,
22+
values: sv::SnapshotVec<Delegate<'tcx>>,
2323
}
2424

2525
struct TypeVariableData<'tcx> {
@@ -42,7 +42,7 @@ enum UndoEntry {
4242
Relate(ty::TyVid, ty::TyVid),
4343
}
4444

45-
struct Delegate;
45+
struct Delegate<'tcx>;
4646

4747
type Relation = (RelationDir, ty::TyVid);
4848

@@ -195,9 +195,12 @@ impl<'tcx> TypeVariableTable<'tcx> {
195195
}
196196
}
197197

198-
impl<'tcx> sv::SnapshotVecDelegate<TypeVariableData<'tcx>,UndoEntry> for Delegate {
198+
impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
199+
type Value = TypeVariableData<'tcx>;
200+
type Undo = UndoEntry;
201+
199202
fn reverse(&mut self,
200-
values: &mut Vec<TypeVariableData>,
203+
values: &mut Vec<TypeVariableData<'tcx>>,
201204
action: UndoEntry) {
202205
match action {
203206
SpecifyVar(vid, relations) => {

src/librustc/middle/infer/unify.rs

+60-61
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use middle::infer::InferCtxt;
1919
use std::cell::RefCell;
2020
use std::fmt::Debug;
2121
use syntax::ast;
22-
use util::ppaux::Repr;
2322
use util::snapshot_vec as sv;
2423

2524
/// This trait is implemented by any type that can serve as a type
@@ -32,15 +31,17 @@ use util::snapshot_vec as sv;
3231
/// (possibly not yet known) sort of integer.
3332
///
3433
/// Implementations of this trait are at the end of this file.
35-
pub trait UnifyKey<'tcx, V> : Clone + Debug + PartialEq + Repr<'tcx> {
34+
pub trait UnifyKey : Clone + Debug + PartialEq {
35+
type Value : UnifyValue;
36+
3637
fn index(&self) -> uint;
3738

3839
fn from_index(u: uint) -> Self;
3940

4041
// Given an inference context, returns the unification table
4142
// appropriate to this key type.
4243
fn unification_table<'v>(infcx: &'v InferCtxt)
43-
-> &'v RefCell<UnificationTable<Self,V>>;
44+
-> &'v RefCell<UnificationTable<Self>>;
4445

4546
fn tag(k: Option<Self>) -> &'static str;
4647
}
@@ -51,7 +52,7 @@ pub trait UnifyKey<'tcx, V> : Clone + Debug + PartialEq + Repr<'tcx> {
5152
/// whose value is not yet set).
5253
///
5354
/// Implementations of this trait are at the end of this file.
54-
pub trait UnifyValue<'tcx> : Clone + Repr<'tcx> + PartialEq {
55+
pub trait UnifyValue : Clone + PartialEq + Debug {
5556
}
5657

5758
/// Value of a unification key. We implement Tarjan's union-find
@@ -62,44 +63,44 @@ pub trait UnifyValue<'tcx> : Clone + Repr<'tcx> + PartialEq {
6263
/// to keep the DAG relatively balanced, which helps keep the running
6364
/// time of the algorithm under control. For more information, see
6465
/// <http://en.wikipedia.org/wiki/Disjoint-set_data_structure>.
65-
#[derive(PartialEq,Clone)]
66-
pub enum VarValue<K,V> {
66+
#[derive(PartialEq,Clone,Show)]
67+
pub enum VarValue<K:UnifyKey> {
6768
Redirect(K),
68-
Root(V, uint),
69+
Root(K::Value, uint),
6970
}
7071

7172
/// Table of unification keys and their values.
72-
pub struct UnificationTable<K,V> {
73+
pub struct UnificationTable<K:UnifyKey> {
7374
/// Indicates the current value of each key.
74-
values: sv::SnapshotVec<VarValue<K,V>,(),Delegate>,
75+
values: sv::SnapshotVec<Delegate<K>>,
7576
}
7677

7778
/// At any time, users may snapshot a unification table. The changes
7879
/// made during the snapshot may either be *committed* or *rolled back*.
79-
pub struct Snapshot<K> {
80+
pub struct Snapshot<K:UnifyKey> {
8081
// Link snapshot to the key type `K` of the table.
8182
marker: marker::CovariantType<K>,
8283
snapshot: sv::Snapshot,
8384
}
8485

8586
/// Internal type used to represent the result of a `get()` operation.
8687
/// Conveys the current root and value of the key.
87-
pub struct Node<K,V> {
88+
pub struct Node<K:UnifyKey> {
8889
pub key: K,
89-
pub value: V,
90+
pub value: K::Value,
9091
pub rank: uint,
9192
}
9293

9394
#[derive(Copy)]
94-
pub struct Delegate;
95+
pub struct Delegate<K>;
9596

9697
// We can't use V:LatticeValue, much as I would like to,
9798
// because frequently the pattern is that V=Option<U> for some
9899
// other type parameter U, and we have no way to say
99100
// Option<U>:LatticeValue.
100101

101-
impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K,V> {
102-
pub fn new() -> UnificationTable<K,V> {
102+
impl<K:UnifyKey> UnificationTable<K> {
103+
pub fn new() -> UnificationTable<K> {
103104
UnificationTable {
104105
values: sv::SnapshotVec::new(Delegate),
105106
}
@@ -126,7 +127,7 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
126127
self.values.commit(snapshot.snapshot);
127128
}
128129

129-
pub fn new_key(&mut self, value: V) -> K {
130+
pub fn new_key(&mut self, value: K::Value) -> K {
130131
let index = self.values.push(Root(value, 0));
131132
let k = UnifyKey::from_index(index);
132133
debug!("{}: created new key: {:?}",
@@ -137,12 +138,12 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
137138

138139
/// Find the root node for `vid`. This uses the standard union-find algorithm with path
139140
/// compression: http://en.wikipedia.org/wiki/Disjoint-set_data_structure
140-
pub fn get(&mut self, tcx: &ty::ctxt, vid: K) -> Node<K,V> {
141+
pub fn get(&mut self, tcx: &ty::ctxt, vid: K) -> Node<K> {
141142
let index = vid.index();
142143
let value = (*self.values.get(index)).clone();
143144
match value {
144145
Redirect(redirect) => {
145-
let node: Node<K,V> = self.get(tcx, redirect.clone());
146+
let node: Node<K> = self.get(tcx, redirect.clone());
146147
if node.key != redirect {
147148
// Path compression
148149
self.values.set(index, Redirect(node.key.clone()));
@@ -164,33 +165,32 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
164165

165166
/// Sets the value for `vid` to `new_value`. `vid` MUST be a root node! Also, we must be in the
166167
/// middle of a snapshot.
167-
pub fn set(&mut self,
168-
tcx: &ty::ctxt<'tcx>,
169-
key: K,
170-
new_value: VarValue<K,V>)
168+
pub fn set<'tcx>(&mut self,
169+
_tcx: &ty::ctxt<'tcx>,
170+
key: K,
171+
new_value: VarValue<K>)
171172
{
172173
assert!(self.is_root(&key));
173174

174-
debug!("Updating variable {} to {}",
175-
key.repr(tcx),
176-
new_value.repr(tcx));
175+
debug!("Updating variable {:?} to {:?}",
176+
key, new_value);
177177

178178
self.values.set(key.index(), new_value);
179179
}
180180

181181
/// Either redirects node_a to node_b or vice versa, depending on the relative rank. Returns
182182
/// the new root and rank. You should then update the value of the new root to something
183183
/// suitable.
184-
pub fn unify(&mut self,
185-
tcx: &ty::ctxt<'tcx>,
186-
node_a: &Node<K,V>,
187-
node_b: &Node<K,V>)
188-
-> (K, uint)
184+
pub fn unify<'tcx>(&mut self,
185+
tcx: &ty::ctxt<'tcx>,
186+
node_a: &Node<K>,
187+
node_b: &Node<K>)
188+
-> (K, uint)
189189
{
190-
debug!("unify(node_a(id={}, rank={}), node_b(id={}, rank={}))",
191-
node_a.key.repr(tcx),
190+
debug!("unify(node_a(id={:?}, rank={:?}), node_b(id={:?}, rank={:?}))",
191+
node_a.key,
192192
node_a.rank,
193-
node_b.key.repr(tcx),
193+
node_b.key,
194194
node_b.rank);
195195

196196
if node_a.rank > node_b.rank {
@@ -212,8 +212,11 @@ impl<'tcx, V:PartialEq+Clone+Repr<'tcx>, K:UnifyKey<'tcx, V>> UnificationTable<K
212212
}
213213
}
214214

215-
impl<K,V> sv::SnapshotVecDelegate<VarValue<K,V>,()> for Delegate {
216-
fn reverse(&mut self, _: &mut Vec<VarValue<K,V>>, _: ()) {
215+
impl<K> sv::SnapshotVecDelegate for Delegate<K> {
216+
type Value = VarValue<K>;
217+
type Undo = ();
218+
219+
fn reverse(&mut self, _: &mut Vec<VarValue<K>>, _: ()) {
217220
panic!("Nothing to reverse");
218221
}
219222
}
@@ -224,7 +227,7 @@ impl<K,V> sv::SnapshotVecDelegate<VarValue<K,V>,()> for Delegate {
224227

225228
/// Indicates a type that does not have any kind of subtyping
226229
/// relationship.
227-
pub trait SimplyUnifiable<'tcx> : Clone + PartialEq + Repr<'tcx> {
230+
pub trait SimplyUnifiable<'tcx> : Clone + PartialEq + Debug {
228231
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
229232
fn to_type_err(expected_found<Self>) -> ty::type_err<'tcx>;
230233
}
@@ -242,8 +245,11 @@ pub fn err<'tcx, V:SimplyUnifiable<'tcx>>(a_is_expected: bool,
242245
}
243246
}
244247

245-
pub trait InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V:SimplyUnifiable<'tcx>,
246-
K:UnifyKey<'tcx, Option<V>>> {
248+
pub trait InferCtxtMethodsForSimplyUnifiableTypes<'tcx,K,V>
249+
where K : UnifyKey<Value=Option<V>>,
250+
V : SimplyUnifiable<'tcx>,
251+
Option<V> : UnifyValue,
252+
{
247253
fn simple_vars(&self,
248254
a_is_expected: bool,
249255
a_id: K,
@@ -257,8 +263,10 @@ pub trait InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V:SimplyUnifiable<'tcx>,
257263
fn probe_var(&self, a_id: K) -> Option<Ty<'tcx>>;
258264
}
259265

260-
impl<'a,'tcx,V:SimplyUnifiable<'tcx>,K:UnifyKey<'tcx, Option<V>>>
261-
InferCtxtMethodsForSimplyUnifiableTypes<'tcx, V, K> for InferCtxt<'a, 'tcx>
266+
impl<'a,'tcx,V,K> InferCtxtMethodsForSimplyUnifiableTypes<'tcx,K,V> for InferCtxt<'a,'tcx>
267+
where K : UnifyKey<Value=Option<V>>,
268+
V : SimplyUnifiable<'tcx>,
269+
Option<V> : UnifyValue,
262270
{
263271
/// Unifies two simple keys. Because simple keys do not have any subtyping relationships, if
264272
/// both keys have already been associated with a value, then those two values must be the
@@ -271,8 +279,8 @@ impl<'a,'tcx,V:SimplyUnifiable<'tcx>,K:UnifyKey<'tcx, Option<V>>>
271279
{
272280
let tcx = self.tcx;
273281
let table = UnifyKey::unification_table(self);
274-
let node_a = table.borrow_mut().get(tcx, a_id);
275-
let node_b = table.borrow_mut().get(tcx, b_id);
282+
let node_a: Node<K> = table.borrow_mut().get(tcx, a_id);
283+
let node_b: Node<K> = table.borrow_mut().get(tcx, b_id);
276284
let a_id = node_a.key.clone();
277285
let b_id = node_b.key.clone();
278286

@@ -346,14 +354,14 @@ impl<'a,'tcx,V:SimplyUnifiable<'tcx>,K:UnifyKey<'tcx, Option<V>>>
346354

347355
// Integral type keys
348356

349-
impl<'tcx> UnifyKey<'tcx, Option<IntVarValue>> for ty::IntVid {
357+
impl UnifyKey for ty::IntVid {
358+
type Value = Option<IntVarValue>;
359+
350360
fn index(&self) -> uint { self.index as uint }
351361

352362
fn from_index(i: uint) -> ty::IntVid { ty::IntVid { index: i as u32 } }
353363

354-
fn unification_table<'v>(infcx: &'v InferCtxt)
355-
-> &'v RefCell<UnificationTable<ty::IntVid, Option<IntVarValue>>>
356-
{
364+
fn unification_table<'v>(infcx: &'v InferCtxt) -> &'v RefCell<UnificationTable<ty::IntVid>> {
357365
return &infcx.int_unification_table;
358366
}
359367

@@ -375,18 +383,18 @@ impl<'tcx> SimplyUnifiable<'tcx> for IntVarValue {
375383
}
376384
}
377385

378-
impl<'tcx> UnifyValue<'tcx> for Option<IntVarValue> { }
386+
impl UnifyValue for Option<IntVarValue> { }
379387

380388
// Floating point type keys
381389

382-
impl<'tcx> UnifyKey<'tcx, Option<ast::FloatTy>> for ty::FloatVid {
390+
impl UnifyKey for ty::FloatVid {
391+
type Value = Option<ast::FloatTy>;
392+
383393
fn index(&self) -> uint { self.index as uint }
384394

385395
fn from_index(i: uint) -> ty::FloatVid { ty::FloatVid { index: i as u32 } }
386396

387-
fn unification_table<'v>(infcx: &'v InferCtxt)
388-
-> &'v RefCell<UnificationTable<ty::FloatVid, Option<ast::FloatTy>>>
389-
{
397+
fn unification_table<'v>(infcx: &'v InferCtxt) -> &'v RefCell<UnificationTable<ty::FloatVid>> {
390398
return &infcx.float_unification_table;
391399
}
392400

@@ -395,7 +403,7 @@ impl<'tcx> UnifyKey<'tcx, Option<ast::FloatTy>> for ty::FloatVid {
395403
}
396404
}
397405

398-
impl<'tcx> UnifyValue<'tcx> for Option<ast::FloatTy> {
406+
impl UnifyValue for Option<ast::FloatTy> {
399407
}
400408

401409
impl<'tcx> SimplyUnifiable<'tcx> for ast::FloatTy {
@@ -407,12 +415,3 @@ impl<'tcx> SimplyUnifiable<'tcx> for ast::FloatTy {
407415
ty::terr_float_mismatch(err)
408416
}
409417
}
410-
411-
impl<'tcx, K:Repr<'tcx>, V:Repr<'tcx>> Repr<'tcx> for VarValue<K,V> {
412-
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
413-
match *self {
414-
Redirect(ref k) => format!("Redirect({})", k.repr(tcx)),
415-
Root(ref v, r) => format!("Root({}, {})", v.repr(tcx), r)
416-
}
417-
}
418-
}

src/librustc/middle/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
394394
ty::Predicate::Projection(ref data) => {
395395
let project_obligation = obligation.with(data.clone());
396396
let result = project::poly_project_and_unify_type(selcx, &project_obligation);
397-
debug!("poly_project_and_unify_type({}) = {}",
397+
debug!("process_predicate: poly_project_and_unify_type({}) returned {}",
398398
project_obligation.repr(tcx),
399399
result.repr(tcx));
400400
match result {

src/librustc/middle/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn poly_project_and_unify_type<'cx,'tcx>(
6565
obligation: &PolyProjectionObligation<'tcx>)
6666
-> Result<Option<Vec<PredicateObligation<'tcx>>>, MismatchedProjectionTypes<'tcx>>
6767
{
68-
debug!("poly_project(obligation={})",
68+
debug!("poly_project_and_unify_type(obligation={})",
6969
obligation.repr(selcx.tcx()));
7070

7171
let infcx = selcx.infcx();
@@ -109,7 +109,7 @@ fn project_and_unify_type<'cx,'tcx>(
109109
obligation: &ProjectionObligation<'tcx>)
110110
-> Result<Option<Vec<PredicateObligation<'tcx>>>, MismatchedProjectionTypes<'tcx>>
111111
{
112-
debug!("project_and_unify(obligation={})",
112+
debug!("project_and_unify_type(obligation={})",
113113
obligation.repr(selcx.tcx()));
114114

115115
let Normalized { value: normalized_ty, obligations } =

0 commit comments

Comments
 (0)