diff --git a/src/rustc/metadata/tydecode.rs b/src/rustc/metadata/tydecode.rs index 3bd4cdd47db..24f706eeb46 100644 --- a/src/rustc/metadata/tydecode.rs +++ b/src/rustc/metadata/tydecode.rs @@ -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' => { diff --git a/src/rustc/metadata/tyencode.rs b/src/rustc/metadata/tyencode.rs index 42a258e836f..0ecb9dc3dc0 100644 --- a/src/rustc/metadata/tyencode.rs +++ b/src/rustc/metadata/tyencode.rs @@ -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()); diff --git a/src/rustc/middle/trans/reflect.rs b/src/rustc/middle/trans/reflect.rs index c6d35e85826..5aeddac8ab3 100644 --- a/src/rustc/middle/trans/reflect.rs +++ b/src/rustc/middle/trans/reflect.rs @@ -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"), diff --git a/src/rustc/middle/trans/shape.rs b/src/rustc/middle/trans/shape.rs index 0ff538b3f90..92ee4e5dc90 100644 --- a/src/rustc/middle/trans/shape.rs +++ b/src/rustc/middle/trans/shape.rs @@ -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") } } diff --git a/src/rustc/middle/trans/type_of.rs b/src/rustc/middle/trans/type_of.rs index 40bf644c626..3cdb132f26c 100644 --- a/src/rustc/middle/trans/type_of.rs +++ b/src/rustc/middle/trans/type_of.rs @@ -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); diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 85ef0797437..2f352efc864 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -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!("", self.to_uint()) } } -impl tvi_vid: vid { +impl int_vid: vid { pure fn to_uint() -> uint { *self } pure fn to_str() -> ~str { fmt!("", 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) -> 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 } } diff --git a/src/rustc/middle/typeck/astconv.rs b/src/rustc/middle/typeck/astconv.rs index df0b2e1c221..933629bdf91 100644 --- a/src/rustc/middle/typeck/astconv.rs +++ b/src/rustc/middle/typeck/astconv.rs @@ -422,7 +422,7 @@ fn ty_of_arg( // 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 diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index d74bf4f208e..52970baa547 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -60,7 +60,7 @@ type variable is rather an "instance" of a type parameter: that is, given a generic function `fn foo(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; + locals: hashmap; node_types: hashmap; node_type_substs: hashmap; borrowings: hashmap; @@ -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"); diff --git a/src/rustc/middle/typeck/coherence.rs b/src/rustc/middle/typeck/coherence.rs index a01b0983e70..c1473f08b82 100644 --- a/src/rustc/middle/typeck/coherence.rs +++ b/src/rustc/middle/typeck/coherence.rs @@ -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 %?", diff --git a/src/rustc/middle/typeck/infer.rs b/src/rustc/middle/typeck/infer.rs index c630ae432ad..a658ef044df 100644 --- a/src/rustc/middle/typeck/infer.rs +++ b/src/rustc/middle/typeck/infer.rs @@ -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 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_var_bindings: vals_and_bindings>, // The types that might instantiate an integral type variable are // represented by an int_ty_set. - ty_var_integral_bindings: vals_and_bindings, + int_var_bindings: vals_and_bindings, // 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() -> vals_and_bindings { 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( 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 { diff --git a/src/rustc/middle/typeck/infer/assignment.rs b/src/rustc/middle/typeck/infer/assignment.rs index 6faee7ad411..42dc90156f9 100644 --- a/src/rustc/middle/typeck/infer/assignment.rs +++ b/src/rustc/middle/typeck/infer/assignment.rs @@ -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; diff --git a/src/rustc/middle/typeck/infer/combine.rs b/src/rustc/middle/typeck/infer/combine.rs index 4585be3e74a..2b194ebdf17 100644 --- a/src/rustc/middle/typeck/infer/combine.rs +++ b/src/rustc/middle/typeck/infer/combine.rs @@ -345,8 +345,8 @@ fn super_tys( // 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( } // 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(_), _) | diff --git a/src/rustc/middle/typeck/infer/lattice.rs b/src/rustc/middle/typeck/infer/lattice.rs index 998d32bdad3..5fc9ee8d1a7 100644 --- a/src/rustc/middle/typeck/infer/lattice.rs +++ b/src/rustc/middle/typeck/infer/lattice.rs @@ -46,17 +46,17 @@ fn lattice_tys( (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( } fn lattice_vars( - 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) -> cres { // The comments in this function are written for LUB and types, @@ -112,7 +112,7 @@ fn lattice_vars( } fn lattice_var_and_t( - 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) -> cres { let vb = &self.infcx().ty_var_bindings; diff --git a/src/rustc/middle/typeck/infer/resolve.rs b/src/rustc/middle/typeck/infer/resolve.rs index 7364b744527..8d6841357c0 100644 --- a/src/rustc/middle/typeck/infer/resolve.rs +++ b/src/rustc/middle/typeck/infer/resolve.rs @@ -55,7 +55,7 @@ type resolve_state_ = { infcx: infer_ctxt, modes: uint, mut err: Option, - 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) } } } diff --git a/src/rustc/middle/typeck/infer/sub.rs b/src/rustc/middle/typeck/infer/sub.rs index 1163c75c7fe..f3853134a37 100644 --- a/src/rustc/middle/typeck/infer/sub.rs +++ b/src/rustc/middle/typeck/infer/sub.rs @@ -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) => { diff --git a/src/rustc/middle/typeck/infer/unify.rs b/src/rustc/middle/typeck/infer/unify.rs index f5c0892219f..e8e834cfc57 100644 --- a/src/rustc/middle/typeck/infer/unify.rs +++ b/src/rustc/middle/typeck/infer/unify.rs @@ -113,7 +113,7 @@ fn merge_bnds( fn set_var_to_merged_bounds( self: &C, - v_id: ty::tv_vid, + v_id: ty::ty_vid, a: bounds, b: bounds, rank: uint) -> ures { @@ -175,8 +175,8 @@ fn set_var_to_merged_bounds( /// subtle and tricky process, as described in detail at the top /// of infer.rs fn var_sub_var(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(self: &C, } /// make variable a subtype of T -fn var_sub_t(self: &C, a_id: ty::tv_vid, b: ty::t) -> ures { +fn var_sub_t(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(self: &C, a_id: ty::tv_vid, b: ty::t) -> ures { } /// make T a subtype of variable -fn t_sub_var(self: &C, a: ty::t, b_id: ty::tv_vid) -> ures { +fn t_sub_var(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( // 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; diff --git a/src/rustc/util/ppaux.rs b/src/rustc/util/ppaux.rs index ba7b9ffa478..bb54e9df19b 100644 --- a/src/rustc/util/ppaux.rs +++ b/src/rustc/util/ppaux.rs @@ -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)]) }