Fallout: add phantom data to the type inferencer

This commit is contained in:
Niko Matsakis 2015-02-12 12:41:31 -05:00
parent 199b992e63
commit 62b517772a
2 changed files with 8 additions and 6 deletions

View File

@ -14,6 +14,7 @@ use self::UndoEntry::*;
use middle::ty::{self, Ty};
use std::cmp::min;
use std::marker::PhantomData;
use std::mem;
use std::u32;
use util::snapshot_vec as sv;
@ -42,7 +43,7 @@ enum UndoEntry {
Relate(ty::TyVid, ty::TyVid),
}
struct Delegate<'tcx>;
struct Delegate<'tcx>(PhantomData<&'tcx ()>);
type Relation = (RelationDir, ty::TyVid);
@ -64,7 +65,7 @@ impl RelationDir {
impl<'tcx> TypeVariableTable<'tcx> {
pub fn new() -> TypeVariableTable<'tcx> {
TypeVariableTable { values: sv::SnapshotVec::new(Delegate) }
TypeVariableTable { values: sv::SnapshotVec::new(Delegate(PhantomData)) }
}
fn relations<'a>(&'a mut self, a: ty::TyVid) -> &'a mut Vec<Relation> {

View File

@ -18,6 +18,7 @@ use middle::infer::{uok, ures};
use middle::infer::InferCtxt;
use std::cell::RefCell;
use std::fmt::Debug;
use std::marker::PhantomData;
use syntax::ast;
use util::snapshot_vec as sv;
@ -79,7 +80,7 @@ pub struct UnificationTable<K:UnifyKey> {
/// made during the snapshot may either be *committed* or *rolled back*.
pub struct Snapshot<K:UnifyKey> {
// Link snapshot to the key type `K` of the table.
marker: marker::CovariantType<K>,
marker: marker::PhantomData<K>,
snapshot: sv::Snapshot,
}
@ -92,7 +93,7 @@ pub struct Node<K:UnifyKey> {
}
#[derive(Copy)]
pub struct Delegate<K>;
pub struct Delegate<K>(PhantomData<K>);
// We can't use V:LatticeValue, much as I would like to,
// because frequently the pattern is that V=Option<U> for some
@ -102,14 +103,14 @@ pub struct Delegate<K>;
impl<K:UnifyKey> UnificationTable<K> {
pub fn new() -> UnificationTable<K> {
UnificationTable {
values: sv::SnapshotVec::new(Delegate),
values: sv::SnapshotVec::new(Delegate(PhantomData)),
}
}
/// Starts a new snapshot. Each snapshot must be either
/// rolled back or committed in a "LIFO" (stack) order.
pub fn snapshot(&mut self) -> Snapshot<K> {
Snapshot { marker: marker::CovariantType::<K>,
Snapshot { marker: marker::PhantomData::<K>,
snapshot: self.values.start_snapshot() }
}