Refactor ty_var and ty_var_integral into one ty_infer variant

This commit is contained in:
Niko Matsakis 2012-09-06 12:30:15 -07:00
parent d5b3e44b47
commit fe9f0556d2
17 changed files with 182 additions and 174 deletions

View file

@ -274,7 +274,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
parse_ty_rust_fn(st, conv)
}
'X' => {
return ty::mk_var(st.tcx, ty::tv_vid(parse_int(st) as uint));
return ty::mk_var(st.tcx, ty::ty_vid(parse_int(st) as uint));
}
'Y' => return ty::mk_type(st.tcx),
'C' => {

View file

@ -274,11 +274,11 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
ty::ty_fn(f) => {
enc_ty_fn(w, cx, f);
}
ty::ty_var(id) => {
ty::ty_infer(ty::TyVar(id)) => {
w.write_char('X');
w.write_uint(id.to_uint());
}
ty::ty_var_integral(id) => {
ty::ty_infer(ty::IntVar(id)) => {
w.write_char('X');
w.write_char('I');
w.write_uint(id.to_uint());

View file

@ -272,8 +272,7 @@ impl reflector {
// Miscallaneous extra types
ty::ty_trait(_, _, _) => self.leaf(~"trait"),
ty::ty_var(_) => self.leaf(~"var"),
ty::ty_var_integral(_) => self.leaf(~"var_integral"),
ty::ty_infer(_) => self.leaf(~"infer"),
ty::ty_param(p) => self.visit(~"param", ~[self.c_uint(p.idx)]),
ty::ty_self => self.leaf(~"self"),
ty::ty_type => self.leaf(~"type"),

View file

@ -363,7 +363,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
~[shape_bare_fn],
ty::ty_opaque_closure_ptr(_) =>
~[shape_opaque_closure_ptr],
ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self =>
ty::ty_infer(_) | ty::ty_self =>
ccx.sess.bug(~"shape_of: unexpected type struct found")
}
}

View file

@ -171,11 +171,8 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
common::T_named_struct(llvm_type_name(cx, a_class, did, substs.tps))
}
ty::ty_self => cx.tcx.sess.unimpl(~"type_of: ty_self"),
ty::ty_var(_) => cx.tcx.sess.bug(~"type_of with ty_var"),
ty::ty_infer(*) => cx.tcx.sess.bug(~"type_of with ty_infer"),
ty::ty_param(*) => cx.tcx.sess.bug(~"type_of with ty_param"),
ty::ty_var_integral(_) => {
cx.tcx.sess.bug(~"type_of shouldn't see a ty_var_integral");
}
};
cx.lltypes.insert(t, llty);

View file

@ -21,7 +21,7 @@ use util::ppaux::{ty_to_str, proto_ty_to_str, tys_to_str};
use std::serialization::{serialize_Option,
deserialize_Option};
export tv_vid, tvi_vid, region_vid, vid;
export ty_vid, int_vid, region_vid, vid;
export br_hashmap;
export is_instantiable;
export node_id_to_type;
@ -99,8 +99,8 @@ export ty_tup, mk_tup;
export ty_type, mk_type;
export ty_uint, mk_uint, mk_mach_uint;
export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
export ty_var, mk_var, type_is_var;
export ty_var_integral, mk_var_integral, type_is_var_integral;
export ty_infer, mk_infer, type_is_ty_var, mk_var, mk_int_var;
export InferTy, TyVar, IntVar;
export ty_self, mk_self, type_has_self;
export ty_class;
export region, bound_region, encl_region;
@ -510,12 +510,11 @@ enum sty {
ty_class(def_id, substs),
ty_tup(~[t]),
ty_var(tv_vid), // type variable during typechecking
ty_var_integral(tvi_vid), // type variable during typechecking, for
// integral types only
ty_param(param_ty), // type parameter
ty_self, // special, implicit `self` type parameter
ty_infer(InferTy), // soething used only during inference/typeck
// "Fake" types, used for trans purposes
ty_type, // type_desc*
ty_opaque_box, // used by monomorphizer to represent any @ box
@ -568,21 +567,26 @@ enum param_bound {
bound_trait(t),
}
enum tv_vid = uint;
enum tvi_vid = uint;
enum ty_vid = uint;
enum int_vid = uint;
enum region_vid = uint;
enum InferTy {
TyVar(ty_vid),
IntVar(int_vid)
}
trait vid {
pure fn to_uint() -> uint;
pure fn to_str() -> ~str;
}
impl tv_vid: vid {
impl ty_vid: vid {
pure fn to_uint() -> uint { *self }
pure fn to_str() -> ~str { fmt!("<V%u>", self.to_uint()) }
}
impl tvi_vid: vid {
impl int_vid: vid {
pure fn to_uint() -> uint { *self }
pure fn to_str() -> ~str { fmt!("<VI%u>", self.to_uint()) }
}
@ -592,6 +596,22 @@ impl region_vid: vid {
pure fn to_str() -> ~str { fmt!("%?", self) }
}
impl InferTy {
pure fn to_hash() -> uint {
match self {
TyVar(v) => v.to_uint() << 1,
IntVar(v) => (v.to_uint() << 1) + 1
}
}
pure fn to_str() -> ~str {
match self {
TyVar(v) => v.to_str(),
IntVar(v) => v.to_str()
}
}
}
trait purity_to_str {
pure fn to_str() -> ~str;
}
@ -744,7 +764,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
ty_opaque_box => (),
ty_param(_) => flags |= has_params as uint,
ty_var(_) | ty_var_integral(_) => flags |= needs_infer as uint,
ty_infer(_) => flags |= needs_infer as uint,
ty_self => flags |= has_self as uint,
ty_enum(_, ref substs) | ty_class(_, ref substs)
| ty_trait(_, ref substs, _) => {
@ -882,12 +902,14 @@ fn mk_class(cx: ctxt, class_id: ast::def_id, +substs: substs) -> t {
mk_t(cx, ty_class(class_id, substs))
}
fn mk_var(cx: ctxt, v: tv_vid) -> t { mk_t(cx, ty_var(v)) }
fn mk_var(cx: ctxt, v: ty_vid) -> t { mk_infer(cx, TyVar(v)) }
fn mk_var_integral(cx: ctxt, v: tvi_vid) -> t {
mk_t(cx, ty_var_integral(v))
fn mk_int_var(cx: ctxt, v: int_vid) -> t {
mk_infer(cx, IntVar(v))
}
fn mk_infer(cx: ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
fn mk_self(cx: ctxt) -> t { mk_t(cx, ty_self) }
fn mk_param(cx: ctxt, n: uint, k: def_id) -> t {
@ -939,8 +961,7 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
match get(ty).struct {
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_estr(_) | ty_type | ty_opaque_box | ty_self |
ty_opaque_closure_ptr(_) | ty_var(_) | ty_var_integral(_) |
ty_param(_) => {
ty_opaque_closure_ptr(_) | ty_infer(_) | ty_param(_) => {
}
ty_box(tm) | ty_evec(tm, _) | ty_unboxed_vec(tm) |
ty_ptr(tm) | ty_rptr(_, tm) => {
@ -1023,8 +1044,7 @@ fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
}
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
ty_opaque_box | ty_var(_) | ty_var_integral(_) |
ty_param(*) | ty_self => {
ty_opaque_box | ty_infer(_) | ty_param(*) | ty_self => {
*sty
}
}
@ -1240,16 +1260,9 @@ fn type_is_nil(ty: t) -> bool { get(ty).struct == ty_nil }
fn type_is_bot(ty: t) -> bool { get(ty).struct == ty_bot }
fn type_is_var(ty: t) -> bool {
fn type_is_ty_var(ty: t) -> bool {
match get(ty).struct {
ty_var(_) => true,
_ => false
}
}
fn type_is_var_integral(ty: t) -> bool {
match get(ty).struct {
ty_var_integral(_) => true,
ty_infer(TyVar(_)) => true,
_ => false
}
}
@ -1370,7 +1383,7 @@ pure fn type_is_unique(ty: t) -> bool {
pure fn type_is_scalar(ty: t) -> bool {
match get(ty).struct {
ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
ty_var_integral(_) | ty_type | ty_ptr(_) => true,
ty_infer(IntVar(_)) | ty_type | ty_ptr(_) => true,
_ => false
}
}
@ -1852,7 +1865,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
// is never bounded in any way, hence it has the bottom kind.
ty_self => kind_noncopyable(),
ty_var(_) | ty_var_integral(_) => {
ty_infer(_) => {
cx.sess.bug(~"Asked to compute kind of a type variable");
}
ty_type | ty_opaque_closure_ptr(_)
@ -1923,7 +1936,7 @@ fn type_size(cx: ctxt, ty: t) -> uint {
1
}
ty_var(_) | ty_var_integral(_) => {
ty_infer(_) => {
cx.sess.bug(~"Asked to compute kind of a type variable");
}
ty_type | ty_opaque_closure_ptr(_)
@ -1969,8 +1982,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
ty_float(_) |
ty_estr(_) |
ty_fn(_) |
ty_var(_) |
ty_var_integral(_) |
ty_infer(_) |
ty_param(_) |
ty_self |
ty_type |
@ -2103,7 +2115,7 @@ fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
fn type_is_integral(ty: t) -> bool {
match get(ty).struct {
ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool => true,
ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) | ty_bool => true,
_ => false
}
}
@ -2176,7 +2188,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
result = false;
}
ty_var(*) | ty_var_integral(*) | ty_self(*) => {
ty_infer(*) | ty_self(*) => {
cx.sess.bug(~"non concrete type in type_is_pod");
}
}
@ -2353,8 +2365,7 @@ pure fn hash_type_structure(st: &sty) -> uint {
hash_subty(h, f.output)
}
ty_self => 28u,
ty_var(v) => hash_uint(29u, v.to_uint()),
ty_var_integral(v) => hash_uint(30u, v.to_uint()),
ty_infer(v) => hash_uint(29u, v.to_hash()),
ty_param(p) => hash_def(hash_uint(31u, p.idx), p.def_id),
ty_type => 32u,
ty_bot => 34u,
@ -2462,21 +2473,23 @@ fn is_pred_ty(fty: t) -> bool {
is_fn_ty(fty) && type_is_bool(ty_fn_ret(fty))
}
fn ty_var_id(typ: t) -> tv_vid {
/*
fn ty_var_id(typ: t) -> ty_vid {
match get(typ).struct {
ty_var(vid) => return vid,
ty_infer(TyVar(vid)) => return vid,
_ => { error!("ty_var_id called on non-var ty"); fail; }
}
}
fn ty_var_integral_id(typ: t) -> tvi_vid {
fn int_var_id(typ: t) -> int_vid {
match get(typ).struct {
ty_var_integral(vid) => return vid,
ty_infer(IntVar(vid)) => return vid,
_ => { error!("ty_var_integral_id called on ty other than \
ty_var_integral");
fail; }
}
}
*/
// Type accessors for AST nodes
fn block_ty(cx: ctxt, b: &ast::blk) -> t {
@ -2752,15 +2765,15 @@ fn param_tys_in_type(ty: t) -> ~[param_ty] {
rslt
}
fn occurs_check(tcx: ctxt, sp: span, vid: tv_vid, rt: t) {
fn occurs_check(tcx: ctxt, sp: span, vid: ty_vid, rt: t) {
// Returns a vec of all the type variables occurring in `ty`. It may
// contain duplicates. (Integral type vars aren't counted.)
fn vars_in_type(ty: t) -> ~[tv_vid] {
fn vars_in_type(ty: t) -> ~[ty_vid] {
let mut rslt = ~[];
do walk_ty(ty) |ty| {
match get(ty).struct {
ty_var(v) => vec::push(rslt, v),
ty_infer(TyVar(v)) => vec::push(rslt, v),
_ => ()
}
}
@ -2876,8 +2889,8 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str {
ty_trait(id, _, _) => fmt!("trait %s", item_path_str(cx, id)),
ty_class(id, _) => fmt!("class %s", item_path_str(cx, id)),
ty_tup(_) => ~"tuple",
ty_var(_) => ~"variable",
ty_var_integral(_) => ~"integral variable",
ty_infer(TyVar(_)) => ~"inferred type",
ty_infer(IntVar(_)) => ~"integral variable",
ty_param(_) => ~"type parameter",
ty_self => ~"self"
}
@ -3487,7 +3500,7 @@ fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool {
fn tycat(ty: t) -> int {
match get(ty).struct {
ty_bool => tycat_bool,
ty_int(_) | ty_uint(_) | ty_var_integral(_) => tycat_int,
ty_int(_) | ty_uint(_) | ty_infer(IntVar(_)) => tycat_int,
ty_float(_) => tycat_float,
ty_rec(_) | ty_tup(_) | ty_enum(_, _) => tycat_struct,
ty_bot => tycat_bot,
@ -3706,14 +3719,14 @@ impl fn_ty : cmp::Eq {
}
}
impl tv_vid: cmp::Eq {
pure fn eq(&&other: tv_vid) -> bool {
impl ty_vid: cmp::Eq {
pure fn eq(&&other: ty_vid) -> bool {
*self == *other
}
}
impl tvi_vid: cmp::Eq {
pure fn eq(&&other: tvi_vid) -> bool {
impl int_vid: cmp::Eq {
pure fn eq(&&other: int_vid) -> bool {
*self == *other
}
}
@ -3800,6 +3813,12 @@ impl substs : cmp::Eq {
}
}
impl InferTy : cmp::Eq {
pure fn eq(&&other: InferTy) -> bool {
self.to_hash() == other.to_hash()
}
}
impl sty : cmp::Eq {
pure fn eq(&&other: sty) -> bool {
match self {
@ -3912,15 +3931,9 @@ impl sty : cmp::Eq {
_ => false
}
}
ty_var(e0a) => {
ty_infer(e0a) => {
match other {
ty_var(e0b) => e0a == e0b,
_ => false
}
}
ty_var_integral(e0a) => {
match other {
ty_var_integral(e0b) => e0a == e0b,
ty_infer(e0b) => e0a == e0b,
_ => false
}
}

View file

@ -422,7 +422,7 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope copy owned>(
// If the type is not specified, then this must be a fn expr.
// Leave the mode as infer(_), it will get inferred based
// on constraints elsewhere.
ty::ty_var(_) => a.mode,
ty::ty_infer(_) => a.mode,
// If the type is known, then use the default for that type.
// Here we unify m and the default. This should update the

View file

@ -60,7 +60,7 @@ type variable is rather an "instance" of a type parameter: that is,
given a generic function `fn foo<T>(t: T)`: while checking the
function `foo`, the type `ty_param(0)` refers to the type `T`, which
is treated in abstract. When `foo()` is called, however, `T` will be
substituted for a fresh type variable `ty_var(N)`. This variable will
substituted for a fresh type variable `N`. This variable will
eventually be resolved to some concrete type (which might itself be
type parameter).
@ -68,7 +68,7 @@ type parameter).
use astconv::{ast_conv, ast_path_to_ty, ast_ty_to_ty};
use astconv::{ast_region_to_region};
use middle::ty::{tv_vid, vid};
use middle::ty::{ty_vid, vid};
use regionmanip::{replace_bound_regions_in_fn_ty};
use rscope::{anon_rscope, binding_rscope, empty_rscope, in_anon_rscope};
use rscope::{in_binding_rscope, region_scope, type_rscope,
@ -98,7 +98,7 @@ type self_info = {
/// share the inherited fields.
struct inherited {
infcx: infer::infer_ctxt;
locals: hashmap<ast::node_id, tv_vid>;
locals: hashmap<ast::node_id, ty_vid>;
node_types: hashmap<ast::node_id, ty::t>;
node_type_substs: hashmap<ast::node_id, ty::substs>;
borrowings: hashmap<ast::node_id, ty::borrow>;
@ -749,33 +749,33 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
// Some extra checks to detect weird cycles and so forth:
match sty {
ty::ty_box(inner) | ty::ty_uniq(inner) | ty::ty_rptr(_, inner) => {
match ty::get(t1).struct {
ty::ty_var(v1) => {
ty::occurs_check(fcx.ccx.tcx, sp, v1,
ty::mk_box(fcx.ccx.tcx, inner));
}
_ => ()
ty::ty_box(inner) | ty::ty_uniq(inner) | ty::ty_rptr(_, inner) => {
match ty::get(t1).struct {
ty::ty_infer(ty::TyVar(v1)) => {
ty::occurs_check(fcx.ccx.tcx, sp, v1,
ty::mk_box(fcx.ccx.tcx, inner));
}
_ => ()
}
}
}
ty::ty_enum(did, _) => {
// Watch out for a type like `enum t = @t`. Such a type would
// otherwise infinitely auto-deref. This is the only autoderef
// loop that needs to be concerned with this, as an error will be
// reported on the enum definition as well because the enum is not
// instantiable.
if vec::contains(enum_dids, did) {
return t1;
ty::ty_enum(did, _) => {
// Watch out for a type like `enum t = @t`. Such a type would
// otherwise infinitely auto-deref. This is the only autoderef
// loop that needs to be concerned with this, as an error will be
// reported on the enum definition as well because the enum is not
// instantiable.
if vec::contains(enum_dids, did) {
return t1;
}
vec::push(enum_dids, did);
}
vec::push(enum_dids, did);
}
_ => { /*ok*/ }
_ => { /*ok*/ }
}
// Otherwise, deref if type is derefable:
match ty::deref_sty(fcx.ccx.tcx, &sty, false) {
None => return t1,
Some(mt) => t1 = mt.ty
None => return t1,
Some(mt) => t1 = mt.ty
}
};
}
@ -791,7 +791,7 @@ fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t {
ast::lit_int_unsuffixed(_) => {
// An unsuffixed integer literal could have any integral type,
// so we create an integral type variable for it.
ty::mk_var_integral(tcx, fcx.infcx().next_ty_var_integral_id())
ty::mk_int_var(tcx, fcx.infcx().next_int_var_id())
}
ast::lit_float(_, t) => ty::mk_mach_float(tcx, t),
ast::lit_nil => ty::mk_nil(tcx),
@ -2304,7 +2304,7 @@ fn self_ref(fcx: @fn_ctxt, id: ast::node_id) -> bool {
ast_util::is_self)
}
fn lookup_local(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> tv_vid {
fn lookup_local(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> ty_vid {
match fcx.inh.locals.find(id) {
Some(x) => x,
_ => {
@ -2441,7 +2441,7 @@ fn instantiate_path(fcx: @fn_ctxt,
// resolution is possible, then an error is reported.
fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
match infer::resolve_type(fcx.infcx(), tp, force_tvar) {
Ok(t_s) if !ty::type_is_var(t_s) => return t_s,
Ok(t_s) if !ty::type_is_ty_var(t_s) => return t_s,
_ => {
fcx.ccx.tcx.sess.span_fatal
(sp, ~"the type of this value must be known in this context");

View file

@ -12,9 +12,9 @@ use middle::ty::{get, lookup_item_type, subst, t, ty_box};
use middle::ty::{ty_uniq, ty_ptr, ty_rptr, ty_enum};
use middle::ty::{ty_class, ty_nil, ty_bot, ty_bool, ty_int, ty_uint};
use middle::ty::{ty_float, ty_estr, ty_evec, ty_rec};
use middle::ty::{ty_fn, ty_trait, ty_tup, ty_var, ty_var_integral};
use middle::ty::{ty_fn, ty_trait, ty_tup, ty_infer};
use middle::ty::{ty_param, ty_self, ty_type, ty_opaque_box};
use middle::ty::{ty_opaque_closure_ptr, ty_unboxed_vec, type_is_var};
use middle::ty::{ty_opaque_closure_ptr, ty_unboxed_vec, type_is_ty_var};
use middle::typeck::infer::{infer_ctxt, can_mk_subty};
use middle::typeck::infer::{new_infer_ctxt, resolve_ivar, resolve_type};
use syntax::ast::{crate, def_id, def_mod};
@ -43,7 +43,7 @@ fn get_base_type(inference_context: infer_ctxt, span: span, original_type: t)
match resolve_type(inference_context,
original_type,
resolve_ivar) {
Ok(resulting_type) if !type_is_var(resulting_type) => {
Ok(resulting_type) if !type_is_ty_var(resulting_type) => {
resolved_type = resulting_type;
}
_ => {
@ -72,7 +72,7 @@ fn get_base_type(inference_context: infer_ctxt, span: span, original_type: t)
ty_nil | ty_bot | ty_bool | ty_int(*) | ty_uint(*) | ty_float(*) |
ty_estr(*) | ty_evec(*) | ty_rec(*) |
ty_fn(*) | ty_tup(*) | ty_var(*) | ty_var_integral(*) |
ty_fn(*) | ty_tup(*) | ty_infer(*) |
ty_param(*) | ty_self | ty_type | ty_opaque_box |
ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) => {
debug!("(getting base type) no base type; found %?",

View file

@ -250,8 +250,8 @@ use std::smallintmap;
use std::smallintmap::smallintmap;
use std::map::hashmap;
use middle::ty;
use middle::ty::{tv_vid, tvi_vid, region_vid, vid,
ty_int, ty_uint, get, terr_fn};
use middle::ty::{ty_vid, int_vid, region_vid, vid,
ty_int, ty_uint, get, terr_fn, TyVar, IntVar};
use syntax::{ast, ast_util};
use syntax::ast::{ret_style, purity};
use util::ppaux::{ty_to_str, mt_to_str};
@ -312,25 +312,25 @@ enum infer_ctxt = @{
// We instantiate vals_and_bindings with bounds<ty::t> because the
// types that might instantiate a general type variable have an
// order, represented by its upper and lower bounds.
ty_var_bindings: vals_and_bindings<ty::tv_vid, bounds<ty::t>>,
ty_var_bindings: vals_and_bindings<ty::ty_vid, bounds<ty::t>>,
// The types that might instantiate an integral type variable are
// represented by an int_ty_set.
ty_var_integral_bindings: vals_and_bindings<ty::tvi_vid, int_ty_set>,
int_var_bindings: vals_and_bindings<ty::int_vid, int_ty_set>,
// For region variables.
region_vars: RegionVarBindings,
// For keeping track of existing type and region variables.
ty_var_counter: @mut uint,
ty_var_integral_counter: @mut uint,
int_var_counter: @mut uint,
region_var_counter: @mut uint
};
enum fixup_err {
unresolved_int_ty(tvi_vid),
unresolved_ty(tv_vid),
cyclic_ty(tv_vid),
unresolved_int_ty(int_vid),
unresolved_ty(ty_vid),
cyclic_ty(ty_vid),
unresolved_region(region_vid),
region_var_bound_by_region_var(region_vid, region_vid)
}
@ -358,10 +358,10 @@ fn new_vals_and_bindings<V:copy, T:copy>() -> vals_and_bindings<V, T> {
fn new_infer_ctxt(tcx: ty::ctxt) -> infer_ctxt {
infer_ctxt(@{tcx: tcx,
ty_var_bindings: new_vals_and_bindings(),
ty_var_integral_bindings: new_vals_and_bindings(),
int_var_bindings: new_vals_and_bindings(),
region_vars: RegionVarBindings(tcx),
ty_var_counter: @mut 0u,
ty_var_integral_counter: @mut 0u,
int_var_counter: @mut 0u,
region_var_counter: @mut 0u})}
fn mk_subty(cx: infer_ctxt, a_is_expected: bool, span: span,
@ -508,7 +508,7 @@ fn rollback_to<V:copy vid, T:copy>(
struct Snapshot {
ty_var_bindings_len: uint;
ty_var_integral_bindings_len: uint;
int_var_bindings_len: uint;
region_vars_snapshot: uint;
}
@ -532,8 +532,8 @@ impl infer_ctxt {
Snapshot {
ty_var_bindings_len:
self.ty_var_bindings.bindings.len(),
ty_var_integral_bindings_len:
self.ty_var_integral_bindings.bindings.len(),
int_var_bindings_len:
self.int_var_bindings.bindings.len(),
region_vars_snapshot:
self.region_vars.start_snapshot(),
}
@ -543,9 +543,9 @@ impl infer_ctxt {
debug!("rollback!");
rollback_to(&self.ty_var_bindings, snapshot.ty_var_bindings_len);
// FIXME(#3211) -- ty_var_integral not transactional
//rollback_to(&self.ty_var_integral_bindings,
// snapshot.ty_var_integral_bindings_len);
// FIXME(#3211) -- int_var not transactional
//rollback_to(&self.int_var_bindings,
// snapshot.int_var_bindings_len);
self.region_vars.rollback_to(
snapshot.region_vars_snapshot);
@ -563,7 +563,7 @@ impl infer_ctxt {
// destructors but kept the vec at its currently allocated
// length
self.ty_var_bindings.bindings = ~[];
self.ty_var_integral_bindings.bindings = ~[];
self.int_var_bindings.bindings = ~[];
self.region_vars.commit();
r
}
@ -596,12 +596,12 @@ impl infer_ctxt {
}
impl infer_ctxt {
fn next_ty_var_id() -> tv_vid {
fn next_ty_var_id() -> ty_vid {
let id = *self.ty_var_counter;
*self.ty_var_counter += 1u;
self.ty_var_bindings.vals.insert(id,
root({lb: None, ub: None}, 0u));
return tv_vid(id);
return ty_vid(id);
}
fn next_ty_var() -> ty::t {
@ -612,17 +612,17 @@ impl infer_ctxt {
vec::from_fn(n, |_i| self.next_ty_var())
}
fn next_ty_var_integral_id() -> tvi_vid {
let id = *self.ty_var_integral_counter;
*self.ty_var_integral_counter += 1u;
fn next_int_var_id() -> int_vid {
let id = *self.int_var_counter;
*self.int_var_counter += 1u;
self.ty_var_integral_bindings.vals.insert(id,
self.int_var_bindings.vals.insert(id,
root(int_ty_set_all(), 0u));
return tvi_vid(id);
return int_vid(id);
}
fn next_ty_var_integral() -> ty::t {
ty::mk_var_integral(self.tcx, self.next_ty_var_integral_id())
fn next_int_var() -> ty::t {
ty::mk_int_var(self.tcx, self.next_int_var_id())
}
fn next_region_var_nb(span: span) -> ty::region {

View file

@ -75,7 +75,7 @@ impl Assign {
Ok(None)
}
(ty::ty_var(a_id), ty::ty_var(b_id)) => {
(ty::ty_infer(TyVar(a_id)), ty::ty_infer(TyVar(b_id))) => {
let nde_a = self.infcx.get(&self.infcx.ty_var_bindings, a_id);
let nde_b = self.infcx.get(&self.infcx.ty_var_bindings, b_id);
let a_bounds = nde_a.possible_types;
@ -86,7 +86,7 @@ impl Assign {
self.assign_tys_or_sub(a, b, a_bnd, b_bnd)
}
(ty::ty_var(a_id), _) => {
(ty::ty_infer(TyVar(a_id)), _) => {
let nde_a = self.infcx.get(&self.infcx.ty_var_bindings, a_id);
let a_bounds = nde_a.possible_types;
@ -94,7 +94,7 @@ impl Assign {
self.assign_tys_or_sub(a, b, a_bnd, Some(b))
}
(_, ty::ty_var(b_id)) => {
(_, ty::ty_infer(TyVar(b_id))) => {
let nde_b = self.infcx.get(&self.infcx.ty_var_bindings, b_id);
let b_bounds = nde_b.possible_types;

View file

@ -345,8 +345,8 @@ fn super_tys<C:combine>(
// The "subtype" ought to be handling cases involving bot or var:
(ty::ty_bot, _) |
(_, ty::ty_bot) |
(ty::ty_var(_), _) |
(_, ty::ty_var(_)) => {
(ty::ty_infer(TyVar(_)), _) |
(_, ty::ty_infer(TyVar(_))) => {
tcx.sess.bug(
fmt!("%s: bot and var types should have been handled (%s,%s)",
self.tag(),
@ -355,16 +355,16 @@ fn super_tys<C:combine>(
}
// Relate integral variables to other types
(ty::ty_var_integral(a_id), ty::ty_var_integral(b_id)) => {
self.infcx().vars_integral(a_id, b_id).then(|| Ok(a) )
(ty::ty_infer(IntVar(a_id)), ty::ty_infer(IntVar(b_id))) => {
self.infcx().int_vars(a_id, b_id).then(|| Ok(a) )
}
(ty::ty_var_integral(a_id), ty::ty_int(_)) |
(ty::ty_var_integral(a_id), ty::ty_uint(_)) => {
self.infcx().var_integral_sub_t(a_id, b).then(|| Ok(a) )
(ty::ty_infer(IntVar(a_id)), ty::ty_int(_)) |
(ty::ty_infer(IntVar(a_id)), ty::ty_uint(_)) => {
self.infcx().int_var_sub_t(a_id, b).then(|| Ok(a) )
}
(ty::ty_int(_), ty::ty_var_integral(b_id)) |
(ty::ty_uint(_), ty::ty_var_integral(b_id)) => {
self.infcx().t_sub_var_integral(a, b_id).then(|| Ok(a) )
(ty::ty_int(_), ty::ty_infer(IntVar(b_id))) |
(ty::ty_uint(_), ty::ty_infer(IntVar(b_id))) => {
self.infcx().t_sub_int_var(a, b_id).then(|| Ok(a) )
}
(ty::ty_int(_), _) |

View file

@ -46,17 +46,17 @@ fn lattice_tys<L:lattice_ops combine>(
(ty::ty_bot, _) => self.ty_bot(b),
(_, ty::ty_bot) => self.ty_bot(a),
(ty::ty_var(a_id), ty::ty_var(b_id)) => {
(ty::ty_infer(TyVar(a_id)), ty::ty_infer(TyVar(b_id))) => {
lattice_vars(self, a, a_id, b_id,
|x, y| self.tys(x, y) )
}
(ty::ty_var(a_id), _) => {
(ty::ty_infer(TyVar(a_id)), _) => {
lattice_var_and_t(self, a_id, b,
|x, y| self.tys(x, y) )
}
(_, ty::ty_var(b_id)) => {
(_, ty::ty_infer(TyVar(b_id))) => {
lattice_var_and_t(self, b_id, a,
|x, y| self.tys(x, y) )
}
@ -68,7 +68,7 @@ fn lattice_tys<L:lattice_ops combine>(
}
fn lattice_vars<L:lattice_ops combine>(
self: &L, +a_t: ty::t, +a_vid: ty::tv_vid, +b_vid: ty::tv_vid,
self: &L, +a_t: ty::t, +a_vid: ty::ty_vid, +b_vid: ty::ty_vid,
c_ts: fn(ty::t, ty::t) -> cres<ty::t>) -> cres<ty::t> {
// The comments in this function are written for LUB and types,
@ -112,7 +112,7 @@ fn lattice_vars<L:lattice_ops combine>(
}
fn lattice_var_and_t<L:lattice_ops combine>(
self: &L, a_id: ty::tv_vid, b: ty::t,
self: &L, a_id: ty::ty_vid, b: ty::t,
c_ts: fn(ty::t, ty::t) -> cres<ty::t>) -> cres<ty::t> {
let vb = &self.infcx().ty_var_bindings;

View file

@ -55,7 +55,7 @@ type resolve_state_ = {
infcx: infer_ctxt,
modes: uint,
mut err: Option<fixup_err>,
mut v_seen: ~[tv_vid]
mut v_seen: ~[ty_vid]
};
enum resolve_state {
@ -113,11 +113,11 @@ impl resolve_state {
if !ty::type_needs_infer(typ) { return typ; }
match ty::get(typ).struct {
ty::ty_var(vid) => {
ty::ty_infer(TyVar(vid)) => {
self.resolve_ty_var(vid)
}
ty::ty_var_integral(vid) => {
self.resolve_ty_var_integral(vid)
ty::ty_infer(IntVar(vid)) => {
self.resolve_int_var(vid)
}
_ => {
if !self.should(resolve_rvar) &&
@ -169,7 +169,7 @@ impl resolve_state {
}
}
fn resolve_ty_var(vid: tv_vid) -> ty::t {
fn resolve_ty_var(vid: ty_vid) -> ty::t {
if vec::contains(self.v_seen, vid) {
self.err = Some(cyclic_ty(vid));
return ty::mk_var(self.infcx.tcx, vid);
@ -202,12 +202,12 @@ impl resolve_state {
}
}
fn resolve_ty_var_integral(vid: tvi_vid) -> ty::t {
fn resolve_int_var(vid: int_vid) -> ty::t {
if !self.should(resolve_ivar) {
return ty::mk_var_integral(self.infcx.tcx, vid);
return ty::mk_int_var(self.infcx.tcx, vid);
}
let nde = self.infcx.get(&self.infcx.ty_var_integral_bindings, vid);
let nde = self.infcx.get(&self.infcx.int_var_bindings, vid);
let pt = nde.possible_types;
// If there's only one type in the set of possible types, then
@ -219,13 +219,13 @@ impl resolve_state {
// As a last resort, default to int.
let ty = ty::mk_int(self.infcx.tcx);
self.infcx.set(
&self.infcx.ty_var_integral_bindings, vid,
&self.infcx.int_var_bindings, vid,
root(convert_integral_ty_to_int_ty_set(self.infcx.tcx,
ty),
nde.rank));
ty
} else {
ty::mk_var_integral(self.infcx.tcx, vid)
ty::mk_int_var(self.infcx.tcx, vid)
}
}
}

View file

@ -105,13 +105,13 @@ impl Sub: combine {
(ty::ty_bot, _) => {
Ok(a)
}
(ty::ty_var(a_id), ty::ty_var(b_id)) => {
(ty::ty_infer(TyVar(a_id)), ty::ty_infer(TyVar(b_id))) => {
var_sub_var(&self, a_id, b_id).then(|| Ok(a) )
}
(ty::ty_var(a_id), _) => {
(ty::ty_infer(TyVar(a_id)), _) => {
var_sub_t(&self, a_id, b).then(|| Ok(a) )
}
(_, ty::ty_var(b_id)) => {
(_, ty::ty_infer(TyVar(b_id))) => {
t_sub_var(&self, a, b_id).then(|| Ok(a) )
}
(_, ty::ty_bot) => {

View file

@ -113,7 +113,7 @@ fn merge_bnds<C: combine>(
fn set_var_to_merged_bounds<C: combine>(
self: &C,
v_id: ty::tv_vid,
v_id: ty::ty_vid,
a: bounds<ty::t>,
b: bounds<ty::t>,
rank: uint) -> ures {
@ -175,8 +175,8 @@ fn set_var_to_merged_bounds<C: combine>(
/// subtle and tricky process, as described in detail at the top
/// of infer.rs
fn var_sub_var<C: combine>(self: &C,
a_id: ty::tv_vid,
b_id: ty::tv_vid) -> ures {
a_id: ty::ty_vid,
b_id: ty::ty_vid) -> ures {
let vb = &self.infcx().ty_var_bindings;
// Need to make sub_id a subtype of sup_id.
@ -241,7 +241,7 @@ fn var_sub_var<C: combine>(self: &C,
}
/// make variable a subtype of T
fn var_sub_t<C: combine>(self: &C, a_id: ty::tv_vid, b: ty::t) -> ures {
fn var_sub_t<C: combine>(self: &C, a_id: ty::ty_vid, b: ty::t) -> ures {
let vb = &self.infcx().ty_var_bindings;
let nde_a = self.infcx().get(vb, a_id);
@ -257,7 +257,7 @@ fn var_sub_t<C: combine>(self: &C, a_id: ty::tv_vid, b: ty::t) -> ures {
}
/// make T a subtype of variable
fn t_sub_var<C: combine>(self: &C, a: ty::t, b_id: ty::tv_vid) -> ures {
fn t_sub_var<C: combine>(self: &C, a: ty::t, b_id: ty::ty_vid) -> ures {
let vb = &self.infcx().ty_var_bindings;
let a_bounds = {lb: Some(a), ub: None};
@ -294,8 +294,8 @@ fn bnds<C: combine>(
// Integral variables
impl infer_ctxt {
fn vars_integral(a_id: ty::tvi_vid, b_id: ty::tvi_vid) -> ures {
let vb = &self.ty_var_integral_bindings;
fn int_vars(a_id: ty::int_vid, b_id: ty::int_vid) -> ures {
let vb = &self.int_var_bindings;
let nde_a = self.get(vb, a_id);
let nde_b = self.get(vb, b_id);
@ -317,18 +317,18 @@ impl infer_ctxt {
// Rank optimization
if nde_a.rank > nde_b.rank {
debug!("vars_integral(): a has smaller rank");
debug!("int_vars(): a has smaller rank");
// a has greater rank, so a should become b's parent,
// i.e., b should redirect to a.
self.set(vb, a_id, root(intersection, nde_a.rank));
self.set(vb, b_id, redirect(a_id));
} else if nde_a.rank < nde_b.rank {
debug!("vars_integral(): b has smaller rank");
debug!("int_vars(): b has smaller rank");
// b has greater rank, so a should redirect to b.
self.set(vb, b_id, root(intersection, nde_b.rank));
self.set(vb, a_id, redirect(b_id));
} else {
debug!("vars_integral(): a and b have equal rank");
debug!("int_vars(): a and b have equal rank");
assert nde_a.rank == nde_b.rank;
// If equal, just redirect one to the other and increment
// the other's rank. We choose arbitrarily to redirect b
@ -340,10 +340,10 @@ impl infer_ctxt {
uok()
}
fn var_integral_sub_t(a_id: ty::tvi_vid, b: ty::t) -> ures {
fn int_var_sub_t(a_id: ty::int_vid, b: ty::t) -> ures {
assert ty::type_is_integral(b);
let vb = &self.ty_var_integral_bindings;
let vb = &self.int_var_bindings;
let nde_a = self.get(vb, a_id);
let a_id = nde_a.root;
let a_pt = nde_a.possible_types;
@ -358,9 +358,9 @@ impl infer_ctxt {
uok()
}
fn t_sub_var_integral(a: ty::t, b_id: ty::tvi_vid) -> ures {
fn t_sub_int_var(a: ty::t, b_id: ty::int_vid) -> ures {
assert ty::type_is_integral(a);
let vb = &self.ty_var_integral_bindings;
let vb = &self.int_var_bindings;
let nde_b = self.get(vb, b_id);
let b_id = nde_b.root;

View file

@ -9,7 +9,7 @@ use middle::ty::{ty_bool, ty_bot, ty_box, ty_class, ty_enum};
use middle::ty::{ty_estr, ty_evec, ty_float, ty_fn, ty_trait, ty_int};
use middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param};
use middle::ty::{ty_ptr, ty_rec, ty_rptr, ty_self, ty_tup};
use middle::ty::{ty_type, ty_uniq, ty_uint, ty_var, ty_var_integral};
use middle::ty::{ty_type, ty_uniq, ty_uint, ty_infer};
use middle::ty::{ty_unboxed_vec, vid};
use metadata::encoder;
use syntax::codemap;
@ -335,8 +335,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str {
fn_to_str(cx, f.purity, f.proto, None, f.inputs,
f.output, f.ret_style)
}
ty_var(v) => v.to_str(),
ty_var_integral(v) => v.to_str(),
ty_infer(infer_ty) => infer_ty.to_str(),
ty_param({idx: id, _}) => {
~"'" + str::from_bytes(~[('a' as u8) + (id as u8)])
}