Skip to content

Commit

Permalink
Port to use the new Unify code, which has no UnifyValue trait
Browse files Browse the repository at this point in the history
but is otherwise mostly the same.
  • Loading branch information
nikomatsakis committed Apr 17, 2015
1 parent 7ab0d1a commit 416f388
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/freshen.rs
Expand Up @@ -37,7 +37,7 @@ use middle::ty_fold::TypeFolder;
use std::collections::hash_map::{self, Entry};

use super::InferCtxt;
use super::unify::ToType;
use super::unify_key::ToType;

pub struct TypeFreshener<'a, 'tcx:'a> {
infcx: &'a InferCtxt<'a, 'tcx>,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/infer/mod.rs
Expand Up @@ -29,6 +29,7 @@ use middle::ty::replace_late_bound_regions;
use middle::ty::{self, Ty};
use middle::ty_fold::{TypeFolder, TypeFoldable};
use middle::ty_relate::{Relate, RelateResult, TypeRelation};
use rustc_data_structures::unify::{self, UnificationTable};
use std::cell::{RefCell};
use std::fmt;
use std::rc::Rc;
Expand All @@ -41,8 +42,8 @@ use util::ppaux::{Repr, UserString};

use self::combine::CombineFields;
use self::region_inference::{RegionVarBindings, RegionSnapshot};
use self::unify::{ToType, UnificationTable};
use self::error_reporting::ErrorReporting;
use self::unify_key::ToType;

pub mod bivariate;
pub mod combine;
Expand All @@ -57,7 +58,7 @@ pub mod resolve;
mod freshen;
pub mod sub;
pub mod type_variable;
pub mod unify;
pub mod unify_key;

pub type Bound<T> = Option<T>;
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
Expand Down
48 changes: 48 additions & 0 deletions src/librustc/middle/infer/unify_key.rs
@@ -0,0 +1,48 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use middle::ty::{self, IntVarValue, Ty};
use rustc_data_structures::unify::UnifyKey;
use syntax::ast;

pub trait ToType<'tcx> {
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
}

impl UnifyKey for ty::IntVid {
type Value = Option<IntVarValue>;
fn index(&self) -> u32 { self.index }
fn from_index(i: u32) -> ty::IntVid { ty::IntVid { index: i } }
fn tag(_: Option<ty::IntVid>) -> &'static str { "IntVid" }
}

impl<'tcx> ToType<'tcx> for IntVarValue {
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
match *self {
ty::IntType(i) => ty::mk_mach_int(tcx, i),
ty::UintType(i) => ty::mk_mach_uint(tcx, i),
}
}
}

// Floating point type keys

impl UnifyKey for ty::FloatVid {
type Value = Option<ast::FloatTy>;
fn index(&self) -> u32 { self.index }
fn from_index(i: u32) -> ty::FloatVid { ty::FloatVid { index: i } }
fn tag(_: Option<ty::FloatVid>) -> &'static str { "FloatVid" }
}

impl<'tcx> ToType<'tcx> for ast::FloatTy {
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
ty::mk_mach_float(tcx, *self)
}
}
1 change: 1 addition & 0 deletions src/librustc_data_structures/lib.rs
Expand Up @@ -35,3 +35,4 @@ extern crate serialize as rustc_serialize; // used by deriving
pub mod snapshot_vec;
pub mod graph;
pub mod bitvec;
pub mod unify;

0 comments on commit 416f388

Please sign in to comment.