Skip to content

Commit 416f388

Browse files
committed
Port to use the new Unify code, which has no UnifyValue trait
but is otherwise mostly the same.
1 parent 7ab0d1a commit 416f388

File tree

6 files changed

+363
-125
lines changed

6 files changed

+363
-125
lines changed

src/librustc/middle/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use middle::ty_fold::TypeFolder;
3737
use std::collections::hash_map::{self, Entry};
3838

3939
use super::InferCtxt;
40-
use super::unify::ToType;
40+
use super::unify_key::ToType;
4141

4242
pub struct TypeFreshener<'a, 'tcx:'a> {
4343
infcx: &'a InferCtxt<'a, 'tcx>,

src/librustc/middle/infer/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use middle::ty::replace_late_bound_regions;
2929
use middle::ty::{self, Ty};
3030
use middle::ty_fold::{TypeFolder, TypeFoldable};
3131
use middle::ty_relate::{Relate, RelateResult, TypeRelation};
32+
use rustc_data_structures::unify::{self, UnificationTable};
3233
use std::cell::{RefCell};
3334
use std::fmt;
3435
use std::rc::Rc;
@@ -41,8 +42,8 @@ use util::ppaux::{Repr, UserString};
4142

4243
use self::combine::CombineFields;
4344
use self::region_inference::{RegionVarBindings, RegionSnapshot};
44-
use self::unify::{ToType, UnificationTable};
4545
use self::error_reporting::ErrorReporting;
46+
use self::unify_key::ToType;
4647

4748
pub mod bivariate;
4849
pub mod combine;
@@ -57,7 +58,7 @@ pub mod resolve;
5758
mod freshen;
5859
pub mod sub;
5960
pub mod type_variable;
60-
pub mod unify;
61+
pub mod unify_key;
6162

6263
pub type Bound<T> = Option<T>;
6364
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use middle::ty::{self, IntVarValue, Ty};
12+
use rustc_data_structures::unify::UnifyKey;
13+
use syntax::ast;
14+
15+
pub trait ToType<'tcx> {
16+
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
17+
}
18+
19+
impl UnifyKey for ty::IntVid {
20+
type Value = Option<IntVarValue>;
21+
fn index(&self) -> u32 { self.index }
22+
fn from_index(i: u32) -> ty::IntVid { ty::IntVid { index: i } }
23+
fn tag(_: Option<ty::IntVid>) -> &'static str { "IntVid" }
24+
}
25+
26+
impl<'tcx> ToType<'tcx> for IntVarValue {
27+
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
28+
match *self {
29+
ty::IntType(i) => ty::mk_mach_int(tcx, i),
30+
ty::UintType(i) => ty::mk_mach_uint(tcx, i),
31+
}
32+
}
33+
}
34+
35+
// Floating point type keys
36+
37+
impl UnifyKey for ty::FloatVid {
38+
type Value = Option<ast::FloatTy>;
39+
fn index(&self) -> u32 { self.index }
40+
fn from_index(i: u32) -> ty::FloatVid { ty::FloatVid { index: i } }
41+
fn tag(_: Option<ty::FloatVid>) -> &'static str { "FloatVid" }
42+
}
43+
44+
impl<'tcx> ToType<'tcx> for ast::FloatTy {
45+
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
46+
ty::mk_mach_float(tcx, *self)
47+
}
48+
}

src/librustc_data_structures/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ extern crate serialize as rustc_serialize; // used by deriving
3535
pub mod snapshot_vec;
3636
pub mod graph;
3737
pub mod bitvec;
38+
pub mod unify;

0 commit comments

Comments
 (0)