rustc: Switch @ty.t to ty.t so that we can change it to a uint

This commit is contained in:
Patrick Walton 2011-04-22 12:27:28 -07:00
parent fac8cc3b06
commit c7473c8260
7 changed files with 424 additions and 423 deletions

View file

@ -22,8 +22,8 @@ type ty_param = ident;
// Annotations added during successive passes.
tag ann {
ann_none;
ann_type(@middle.ty.t,
option.t[vec[@middle.ty.t]], /* ty param substs */
ann_type(middle.ty.t,
option.t[vec[middle.ty.t]], /* ty param substs */
option.t[@ts_ann]); /* pre- and postcondition for typestate */
}

View file

@ -63,7 +63,7 @@ fn next(@pstate st) -> u8 {
ret ch as u8;
}
fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> @ty.t {
fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> ty.t {
auto len = _str.byte_len(rep);
auto st = @rec(rep=rep, mutable pos=0u, len=len, tystore=tystore);
auto result = parse_ty(st, sd);
@ -75,7 +75,7 @@ fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> @ty.t {
ret result;
}
fn parse_ty(@pstate st, str_def sd) -> @ty.t {
fn parse_ty(@pstate st, str_def sd) -> ty.t {
alt (next(st) as char) {
case ('n') { ret ty.mk_nil(st.tystore); }
case ('b') { ret ty.mk_bool(st.tystore); }
@ -101,7 +101,7 @@ fn parse_ty(@pstate st, str_def sd) -> @ty.t {
case ('t') {
check(next(st) as char == '[');
auto def = parse_def(st, sd);
let vec[@ty.t] params = vec();
let vec[ty.t] params = vec();
while (peek(st) as char != ']') {
params += vec(parse_ty(st, sd));
}
@ -213,7 +213,7 @@ fn parse_int(@pstate st) -> int {
ret n;
}
fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) {
fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], ty.t) {
check(next(st) as char == '[');
let vec[ty.arg] inputs = vec();
while (peek(st) as char != ']') {
@ -331,7 +331,7 @@ fn variant_tag_id(&ebml.doc d) -> ast.def_id {
ret parse_def_id(ebml.doc_data(tagdoc));
}
fn item_type(&ebml.doc item, int this_cnum, @ty.type_store tystore) -> @ty.t {
fn item_type(&ebml.doc item, int this_cnum, @ty.type_store tystore) -> ty.t {
fn parse_external_def_id(int this_cnum, str s) -> ast.def_id {
// FIXME: This is completely wrong when linking against a crate
// that, in turn, links against another crate. We need a mapping
@ -545,7 +545,7 @@ fn get_tag_variants(session.session sess,
for (ast.def_id did in variant_ids) {
auto item = find_item(did._1, items);
auto ctor_ty = item_type(item, external_crate_id, tystore);
let vec[@ty.t] arg_tys = vec();
let vec[ty.t] arg_tys = vec();
alt (ty.struct(ctor_ty)) {
case (ty.ty_fn(_, ?args, _)) {
for (ty.arg a in args) {

View file

@ -52,7 +52,7 @@ const uint tag_index_table = 0x15u;
// Callback to translate defs to strs or back.
type def_str = fn(ast.def_id) -> str;
fn ty_str(@ty.t t, def_str ds) -> str {
fn ty_str(ty.t t, def_str ds) -> str {
ret sty_str(ty.struct(t), ds);
}
@ -91,7 +91,7 @@ fn sty_str(ty.sty st, def_str ds) -> str {
case (ty.ty_str) {ret "s";}
case (ty.ty_tag(?def,?tys)) { // TODO restore def_id
auto acc = "t[" + ds(def) + "|";
for (@ty.t t in tys) {acc += ty_str(t, ds);}
for (ty.t t in tys) {acc += ty_str(t, ds);}
ret acc + "]";
}
case (ty.ty_box(?mt)) {ret "@" + mt_str(mt, ds);}
@ -151,7 +151,7 @@ fn proto_str(ast.proto proto) -> str {
}
}
fn ty_fn_str(vec[ty.arg] args, @ty.t out, def_str ds) -> str {
fn ty_fn_str(vec[ty.arg] args, ty.t out, def_str ds) -> str {
auto acc = "[";
for (ty.arg arg in args) {
if (arg.mode == ast.alias) {acc += "&";}
@ -327,7 +327,7 @@ fn encode_variant_id(&ebml.writer ebml_w, ast.def_id vid) {
ebml.end_tag(ebml_w);
}
fn encode_type(&ebml.writer ebml_w, @ty.t typ) {
fn encode_type(&ebml.writer ebml_w, ty.t typ) {
ebml.start_tag(ebml_w, tag_items_data_item_type);
auto f = def_to_str;
ebml_w.writer.write(_str.bytes(ty_str(typ, f)));

File diff suppressed because it is too large Load diff

View file

@ -21,18 +21,18 @@ import util.typestate_ann.ts_ann;
// Data types
type arg = rec(ast.mode mode, @t ty);
type arg = rec(ast.mode mode, t ty);
type field = rec(ast.ident ident, mt mt);
type method = rec(ast.proto proto,
ast.ident ident,
vec[arg] inputs,
@t output);
t output);
type mt = rec(@t ty, ast.mutability mut);
type mt = rec(t ty, ast.mutability mut);
// Convert from method type to function type. Pretty easy; we just drop
// 'ident'.
fn method_ty_to_fn_ty(@type_store tystore, method m) -> @ty.t {
fn method_ty_to_fn_ty(@type_store tystore, method m) -> t {
ret mk_fn(tystore, m.proto, m.inputs, m.output);
}
@ -42,7 +42,8 @@ fn method_ty_to_fn_ty(@type_store tystore, method m) -> @ty.t {
//
// TODO: It'd be really nice to be able to hide this definition from the
// outside world, to enforce the above invariants.
type t = rec(sty struct, option.t[str] cname, uint hash);
type raw_t = rec(sty struct, option.t[str] cname, uint hash);
type t = @raw_t;
// NB: If you change this, you'll probably want to change the corresponding
// AST structure in front/ast.rs as well.
@ -55,16 +56,16 @@ tag sty {
ty_machine(util.common.ty_mach);
ty_char;
ty_str;
ty_tag(ast.def_id, vec[@t]);
ty_tag(ast.def_id, vec[t]);
ty_box(mt);
ty_vec(mt);
ty_port(@t);
ty_chan(@t);
ty_port(t);
ty_chan(t);
ty_task;
ty_tup(vec[mt]);
ty_rec(vec[field]);
ty_fn(ast.proto, vec[arg], @t);
ty_native_fn(ast.native_abi, vec[arg], @t);
ty_fn(ast.proto, vec[arg], t);
ty_native_fn(ast.native_abi, vec[arg], t);
ty_obj(vec[method]);
ty_var(int); // ephemeral type var
ty_local(ast.def_id); // type of a local var
@ -72,15 +73,15 @@ tag sty {
ty_bound_param(uint); // bound param, only paths
ty_type;
ty_native;
// TODO: ty_fn_arg(@t), for a possibly-aliased function argument
// TODO: ty_fn_arg(t), for a possibly-aliased function argument
}
// Data structures used in type unification
type unify_handler = obj {
fn resolve_local(ast.def_id id) -> option.t[@t];
fn record_local(ast.def_id id, @t ty); // TODO: -> Unify.result
fn record_param(uint index, @t binding) -> Unify.result;
fn resolve_local(ast.def_id id) -> option.t[t];
fn record_local(ast.def_id id, t ty); // TODO: -> Unify.result
fn record_param(uint index, t binding) -> Unify.result;
};
tag type_err {
@ -98,36 +99,36 @@ tag type_err {
}
type ty_param_count_and_ty = tup(uint, @t);
type ty_param_count_and_ty = tup(uint, t);
type type_cache = hashmap[ast.def_id,ty_param_count_and_ty];
type type_store = hashmap[@t,@t];
type type_store = hashmap[t,t];
fn mk_type_store() -> @type_store {
auto hasher = hash_ty;
auto eqer = eq_ty_full;
ret @map.mk_hashmap[@t,@t](hasher, eqer);
ret @map.mk_hashmap[t,t](hasher, eqer);
}
// Type constructors
// These are private constructors to this module. External users should always
// use the mk_foo() functions below.
fn gen_ty(@type_store tystore, &sty st) -> @t {
fn gen_ty(@type_store tystore, &sty st) -> t {
ret gen_ty_full(tystore, st, none[str]);
}
fn gen_ty_full(@type_store tystore, &sty st, option.t[str] cname) -> @t {
fn gen_ty_full(@type_store tystore, &sty st, option.t[str] cname) -> t {
auto h = hash_type_structure(st);
auto new_type = @rec(struct=st, cname=cname, hash=h);
// Is it interned?
alt (tystore.find(new_type)) {
case (some[@t](?typ)) {
case (some[t](?typ)) {
ret typ;
}
case (none[@t]) {
case (none[t]) {
// Nope. Insert it and return.
tystore.insert(new_type, new_type);
ret new_type;
@ -135,86 +136,86 @@ fn gen_ty_full(@type_store tystore, &sty st, option.t[str] cname) -> @t {
}
}
fn mk_nil(@type_store ts) -> @t { ret gen_ty(ts, ty_nil); }
fn mk_bool(@type_store ts) -> @t { ret gen_ty(ts, ty_bool); }
fn mk_int(@type_store ts) -> @t { ret gen_ty(ts, ty_int); }
fn mk_float(@type_store ts) -> @t { ret gen_ty(ts, ty_float); }
fn mk_uint(@type_store ts) -> @t { ret gen_ty(ts, ty_uint); }
fn mk_nil(@type_store ts) -> t { ret gen_ty(ts, ty_nil); }
fn mk_bool(@type_store ts) -> t { ret gen_ty(ts, ty_bool); }
fn mk_int(@type_store ts) -> t { ret gen_ty(ts, ty_int); }
fn mk_float(@type_store ts) -> t { ret gen_ty(ts, ty_float); }
fn mk_uint(@type_store ts) -> t { ret gen_ty(ts, ty_uint); }
fn mk_mach(@type_store ts, util.common.ty_mach tm) -> @t {
fn mk_mach(@type_store ts, util.common.ty_mach tm) -> t {
ret gen_ty(ts, ty_machine(tm));
}
fn mk_char(@type_store ts) -> @t { ret gen_ty(ts, ty_char); }
fn mk_str(@type_store ts) -> @t { ret gen_ty(ts, ty_str); }
fn mk_char(@type_store ts) -> t { ret gen_ty(ts, ty_char); }
fn mk_str(@type_store ts) -> t { ret gen_ty(ts, ty_str); }
fn mk_tag(@type_store ts, ast.def_id did, vec[@t] tys) -> @t {
fn mk_tag(@type_store ts, ast.def_id did, vec[t] tys) -> t {
ret gen_ty(ts, ty_tag(did, tys));
}
fn mk_box(@type_store ts, mt tm) -> @t {
fn mk_box(@type_store ts, mt tm) -> t {
ret gen_ty(ts, ty_box(tm));
}
fn mk_imm_box(@type_store ts, @t ty) -> @t {
fn mk_imm_box(@type_store ts, t ty) -> t {
ret mk_box(ts, rec(ty=ty, mut=ast.imm));
}
fn mk_vec(@type_store ts, mt tm) -> @t { ret gen_ty(ts, ty_vec(tm)); }
fn mk_port(@type_store ts, @t ty) -> @t { ret gen_ty(ts, ty_port(ty)); }
fn mk_chan(@type_store ts, @t ty) -> @t { ret gen_ty(ts, ty_chan(ty)); }
fn mk_task(@type_store ts) -> @t { ret gen_ty(ts, ty_task); }
fn mk_vec(@type_store ts, mt tm) -> t { ret gen_ty(ts, ty_vec(tm)); }
fn mk_port(@type_store ts, t ty) -> t { ret gen_ty(ts, ty_port(ty)); }
fn mk_chan(@type_store ts, t ty) -> t { ret gen_ty(ts, ty_chan(ty)); }
fn mk_task(@type_store ts) -> t { ret gen_ty(ts, ty_task); }
fn mk_tup(@type_store ts, vec[mt] tms) -> @t {
fn mk_tup(@type_store ts, vec[mt] tms) -> t {
ret gen_ty(ts, ty_tup(tms));
}
fn mk_imm_tup(@type_store ts, vec[@t] tys) -> @t {
fn mk_imm_tup(@type_store ts, vec[t] tys) -> t {
// TODO: map
let vec[ty.mt] mts = vec();
for (@ty.t typ in tys) {
for (t typ in tys) {
mts += vec(rec(ty=typ, mut=ast.imm));
}
ret mk_tup(ts, mts);
}
fn mk_rec(@type_store ts, vec[field] fs) -> @t {
fn mk_rec(@type_store ts, vec[field] fs) -> t {
ret gen_ty(ts, ty_rec(fs));
}
fn mk_fn(@type_store ts, ast.proto proto, vec[arg] args, @t ty) -> @t {
fn mk_fn(@type_store ts, ast.proto proto, vec[arg] args, t ty) -> t {
ret gen_ty(ts, ty_fn(proto, args, ty));
}
fn mk_native_fn(@type_store ts, ast.native_abi abi, vec[arg] args, @t ty)
-> @t {
fn mk_native_fn(@type_store ts, ast.native_abi abi, vec[arg] args, t ty)
-> t {
ret gen_ty(ts, ty_native_fn(abi, args, ty));
}
fn mk_obj(@type_store ts, vec[method] meths) -> @t {
fn mk_obj(@type_store ts, vec[method] meths) -> t {
ret gen_ty(ts, ty_obj(meths));
}
fn mk_var(@type_store ts, int v) -> @t { ret gen_ty(ts, ty_var(v)); }
fn mk_var(@type_store ts, int v) -> t { ret gen_ty(ts, ty_var(v)); }
fn mk_local(@type_store ts, ast.def_id did) -> @t {
fn mk_local(@type_store ts, ast.def_id did) -> t {
ret gen_ty(ts, ty_local(did));
}
fn mk_param(@type_store ts, uint n) -> @t {
fn mk_param(@type_store ts, uint n) -> t {
ret gen_ty(ts, ty_param(n));
}
fn mk_bound_param(@type_store ts, uint n) -> @t {
fn mk_bound_param(@type_store ts, uint n) -> t {
ret gen_ty(ts, ty_bound_param(n));
}
fn mk_type(@type_store ts) -> @t { ret gen_ty(ts, ty_type); }
fn mk_native(@type_store ts) -> @t { ret gen_ty(ts, ty_native); }
fn mk_type(@type_store ts) -> t { ret gen_ty(ts, ty_type); }
fn mk_native(@type_store ts) -> t { ret gen_ty(ts, ty_native); }
// Returns the one-level-deep type structure of the given type.
fn struct(@t typ) -> sty { ret typ.struct; }
fn struct(t typ) -> sty { ret typ.struct; }
// Stringification
@ -230,9 +231,9 @@ fn path_to_str(&ast.path pth) -> str {
ret result;
}
fn ty_to_str(&@t typ) -> str {
fn ty_to_str(&t typ) -> str {
fn fn_input_to_str(&rec(ast.mode mode, @t ty) input) -> str {
fn fn_input_to_str(&rec(ast.mode mode, t ty) input) -> str {
auto s;
if (mode_is_alias(input.mode)) {
s = "&";
@ -245,7 +246,7 @@ fn ty_to_str(&@t typ) -> str {
fn fn_to_str(ast.proto proto,
option.t[ast.ident] ident,
vec[arg] inputs, @t output) -> str {
vec[arg] inputs, t output) -> str {
auto f = fn_input_to_str;
auto s;
@ -329,9 +330,9 @@ fn ty_to_str(&@t typ) -> str {
// The user should never see this if the cname is set properly!
s += "<tag#" + util.common.istr(id._0) + ":" +
util.common.istr(id._1) + ">";
if (_vec.len[@t](tps) > 0u) {
if (_vec.len[t](tps) > 0u) {
auto f = ty_to_str;
auto strs = _vec.map[@t,str](f, tps);
auto strs = _vec.map[t,str](f, tps);
s += "[" + _str.connect(strs, ",") + "]";
}
}
@ -380,9 +381,9 @@ fn ty_to_str(&@t typ) -> str {
// Type folds
type ty_walk = fn(@t);
type ty_walk = fn(t);
fn walk_ty(ty_walk walker, @t ty) {
fn walk_ty(ty_walk walker, t ty) {
alt (struct(ty)) {
case (ty_nil) { /* no-op */ }
case (ty_bool) { /* no-op */ }
@ -399,7 +400,7 @@ fn walk_ty(ty_walk walker, @t ty) {
case (ty_port(?subty)) { walk_ty(walker, subty); }
case (ty_chan(?subty)) { walk_ty(walker, subty); }
case (ty_tag(?tid, ?subtys)) {
for (@t subty in subtys) {
for (t subty in subtys) {
walk_ty(walker, subty);
}
}
@ -443,9 +444,9 @@ fn walk_ty(ty_walk walker, @t ty) {
walker(ty);
}
type ty_fold = fn(@t) -> @t;
type ty_fold = fn(t) -> t;
fn fold_ty(@type_store tystore, ty_fold fld, @t ty_0) -> @t {
fn fold_ty(@type_store tystore, ty_fold fld, t ty_0) -> t {
auto ty = ty_0;
alt (struct(ty)) {
case (ty_nil) { /* no-op */ }
@ -478,8 +479,8 @@ fn fold_ty(@type_store tystore, ty_fold fld, @t ty_0) -> @t {
mk_chan(tystore, fold_ty(tystore, fld, subty)), ty);
}
case (ty_tag(?tid, ?subtys)) {
let vec[@t] new_subtys = vec();
for (@t subty in subtys) {
let vec[t] new_subtys = vec();
for (t subty in subtys) {
new_subtys += vec(fold_ty(tystore, fld, subty));
}
ty = copy_cname(tystore, mk_tag(tystore, tid, new_subtys), ty);
@ -547,13 +548,13 @@ fn fold_ty(@type_store tystore, ty_fold fld, @t ty_0) -> @t {
// Type utilities
fn rename(@type_store tystore, @t typ, str new_cname) -> @t {
fn rename(@type_store tystore, t typ, str new_cname) -> t {
ret gen_ty_full(tystore, struct(typ), some[str](new_cname));
}
// Returns a type with the structural part taken from `struct_ty` and the
// canonical name from `cname_ty`.
fn copy_cname(@type_store tystore, @t struct_ty, @t cname_ty) -> @t {
fn copy_cname(@type_store tystore, t struct_ty, t cname_ty) -> t {
ret gen_ty_full(tystore, struct(struct_ty), cname_ty.cname);
}
@ -566,7 +567,7 @@ fn mode_is_alias(ast.mode m) -> bool {
fail;
}
fn type_is_nil(@t ty) -> bool {
fn type_is_nil(t ty) -> bool {
alt (struct(ty)) {
case (ty_nil) { ret true; }
case (_) { ret false; }
@ -574,7 +575,7 @@ fn type_is_nil(@t ty) -> bool {
fail;
}
fn type_is_bool(@t ty) -> bool {
fn type_is_bool(t ty) -> bool {
alt (struct(ty)) {
case (ty_bool) { ret true; }
case (_) { ret false; }
@ -582,7 +583,7 @@ fn type_is_bool(@t ty) -> bool {
}
fn type_is_structural(@t ty) -> bool {
fn type_is_structural(t ty) -> bool {
alt (struct(ty)) {
case (ty_tup(_)) { ret true; }
case (ty_rec(_)) { ret true; }
@ -594,7 +595,7 @@ fn type_is_structural(@t ty) -> bool {
fail;
}
fn type_is_sequence(@t ty) -> bool {
fn type_is_sequence(t ty) -> bool {
alt (struct(ty)) {
case (ty_str) { ret true; }
case (ty_vec(_)) { ret true; }
@ -603,7 +604,7 @@ fn type_is_sequence(@t ty) -> bool {
fail;
}
fn sequence_element_type(@type_store tystore, @t ty) -> @t {
fn sequence_element_type(@type_store tystore, t ty) -> t {
alt (struct(ty)) {
case (ty_str) { ret mk_mach(tystore, common.ty_u8); }
case (ty_vec(?mt)) { ret mt.ty; }
@ -612,7 +613,7 @@ fn sequence_element_type(@type_store tystore, @t ty) -> @t {
}
fn type_is_tup_like(@t ty) -> bool {
fn type_is_tup_like(t ty) -> bool {
alt (struct(ty)) {
case (ty_box(_)) { ret true; }
case (ty_tup(_)) { ret true; }
@ -623,7 +624,7 @@ fn type_is_tup_like(@t ty) -> bool {
fail;
}
fn get_element_type(@t ty, uint i) -> @t {
fn get_element_type(t ty, uint i) -> t {
check (type_is_tup_like(ty));
alt (struct(ty)) {
case (ty_tup(?mts)) {
@ -636,7 +637,7 @@ fn get_element_type(@t ty, uint i) -> @t {
fail;
}
fn type_is_box(@t ty) -> bool {
fn type_is_box(t ty) -> bool {
alt (struct(ty)) {
case (ty_box(_)) { ret true; }
case (_) { ret false; }
@ -644,7 +645,7 @@ fn type_is_box(@t ty) -> bool {
fail;
}
fn type_is_boxed(@t ty) -> bool {
fn type_is_boxed(t ty) -> bool {
alt (struct(ty)) {
case (ty_str) { ret true; }
case (ty_vec(_)) { ret true; }
@ -656,7 +657,7 @@ fn type_is_boxed(@t ty) -> bool {
fail;
}
fn type_is_scalar(@t ty) -> bool {
fn type_is_scalar(t ty) -> bool {
alt (struct(ty)) {
case (ty_nil) { ret true; }
case (ty_bool) { ret true; }
@ -674,7 +675,7 @@ fn type_is_scalar(@t ty) -> bool {
// FIXME: should we just return true for native types in
// type_is_scalar?
fn type_is_native(@t ty) -> bool {
fn type_is_native(t ty) -> bool {
alt (struct(ty)) {
case (ty_native) { ret true; }
case (_) { ret false; }
@ -682,7 +683,7 @@ fn type_is_native(@t ty) -> bool {
fail;
}
fn type_has_dynamic_size(@t ty) -> bool {
fn type_has_dynamic_size(t ty) -> bool {
alt (struct(ty)) {
case (ty_tup(?mts)) {
auto i = 0u;
@ -700,7 +701,7 @@ fn type_has_dynamic_size(@t ty) -> bool {
}
case (ty_tag(_, ?subtys)) {
auto i = 0u;
while (i < _vec.len[@t](subtys)) {
while (i < _vec.len[t](subtys)) {
if (type_has_dynamic_size(subtys.(i))) { ret true; }
i += 1u;
}
@ -711,7 +712,7 @@ fn type_has_dynamic_size(@t ty) -> bool {
ret false;
}
fn type_is_integral(@t ty) -> bool {
fn type_is_integral(t ty) -> bool {
alt (struct(ty)) {
case (ty_int) { ret true; }
case (ty_uint) { ret true; }
@ -735,7 +736,7 @@ fn type_is_integral(@t ty) -> bool {
fail;
}
fn type_is_fp(@t ty) -> bool {
fn type_is_fp(t ty) -> bool {
alt (struct(ty)) {
case (ty_machine(?tm)) {
alt (tm) {
@ -752,7 +753,7 @@ fn type_is_fp(@t ty) -> bool {
fail;
}
fn type_is_signed(@t ty) -> bool {
fn type_is_signed(t ty) -> bool {
alt (struct(ty)) {
case (ty_int) { ret true; }
case (ty_machine(?tm)) {
@ -769,7 +770,7 @@ fn type_is_signed(@t ty) -> bool {
fail;
}
fn type_param(@t ty) -> option.t[uint] {
fn type_param(t ty) -> option.t[uint] {
alt (struct(ty)) {
case (ty_param(?id)) { ret some[uint](id); }
case (_) { /* fall through */ }
@ -797,13 +798,13 @@ fn hash_type_structure(&sty st) -> uint {
ret h;
}
fn hash_subty(uint id, @t subty) -> uint {
fn hash_subty(uint id, t subty) -> uint {
auto h = id;
h += h << 5u + hash_ty(subty);
ret h;
}
fn hash_fn(uint id, vec[arg] args, @t rty) -> uint {
fn hash_fn(uint id, vec[arg] args, t rty) -> uint {
auto h = id;
for (arg a in args) {
h += h << 5u + hash_ty(a.ty);
@ -838,7 +839,7 @@ fn hash_type_structure(&sty st) -> uint {
case (ty_str) { ret 16u; }
case (ty_tag(?did, ?tys)) {
auto h = hash_def(17u, did);
for (@ty.t typ in tys) {
for (t typ in tys) {
h += h << 5u + hash_ty(typ);
}
ret h;
@ -880,13 +881,13 @@ fn hash_type_structure(&sty st) -> uint {
}
}
fn hash_ty(&@t typ) -> uint { ret typ.hash; }
fn hash_ty(&t typ) -> uint { ret typ.hash; }
// Type equality. This function is private to this module (and slow); external
// users should use `eq_ty()` instead.
fn equal_type_structures(&sty a, &sty b) -> bool {
fn equal_ty(@t a, @t b) -> bool { ret Box.ptr_eq[t](a, b); }
fn equal_ty(t a, t b) -> bool { ret Box.ptr_eq[raw_t](a, b); }
fn equal_proto(ast.proto a, ast.proto b) -> bool {
alt (a) {
@ -972,8 +973,8 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
ret equal_mut(a.mut, b.mut) && equal_ty(a.ty, b.ty);
}
fn equal_fn(vec[arg] args_a, @t rty_a,
vec[arg] args_b, @t rty_b) -> bool {
fn equal_fn(vec[arg] args_a, t rty_a,
vec[arg] args_b, t rty_b) -> bool {
if (!equal_ty(rty_a, rty_b)) { ret false; }
auto len = _vec.len[arg](args_a);
@ -1050,8 +1051,8 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
case (ty_tag(?id_b, ?tys_b)) {
if (!equal_def(id_a, id_b)) { ret false; }
auto len = _vec.len[@ty.t](tys_a);
if (len != _vec.len[@ty.t](tys_b)) { ret false; }
auto len = _vec.len[t](tys_a);
if (len != _vec.len[t](tys_b)) { ret false; }
auto i = 0u;
while (i < len) {
if (!equal_ty(tys_a.(i), tys_b.(i))) { ret false; }
@ -1206,7 +1207,7 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
// An expensive type equality function. This function is private to this
// module.
fn eq_ty_full(&@t a, &@t b) -> bool {
fn eq_ty_full(&t a, &t b) -> bool {
// Check hashes (fast path).
if (a.hash != b.hash) {
ret false;
@ -1236,10 +1237,10 @@ fn eq_ty_full(&@t a, &@t b) -> bool {
// This is the equality function the public should use. It works as long as
// the types are interned.
fn eq_ty(&@t a, &@t b) -> bool { ret Box.ptr_eq[t](a, b); }
fn eq_ty(&t a, &t b) -> bool { ret Box.ptr_eq[raw_t](a, b); }
fn ann_to_type(&ast.ann ann) -> @t {
fn ann_to_type(&ast.ann ann) -> t {
alt (ann) {
case (ast.ann_none) {
log_err "ann_to_type() called on node with no type";
@ -1251,7 +1252,7 @@ fn ann_to_type(&ast.ann ann) -> @t {
}
}
fn ann_to_type_params(&ast.ann ann) -> vec[@t] {
fn ann_to_type_params(&ast.ann ann) -> vec[t] {
alt (ann) {
case (ast.ann_none) {
log_err "ann_to_type_params() called on node with no type params";
@ -1259,11 +1260,11 @@ fn ann_to_type_params(&ast.ann ann) -> vec[@t] {
}
case (ast.ann_type(_, ?tps, _)) {
alt (tps) {
case (none[vec[@ty.t]]) {
let vec[@t] result = vec();
case (none[vec[t]]) {
let vec[t] result = vec();
ret result;
}
case (some[vec[@ty.t]](?tps)) { ret tps; }
case (some[vec[t]](?tps)) { ret tps; }
}
}
}
@ -1271,7 +1272,7 @@ fn ann_to_type_params(&ast.ann ann) -> vec[@t] {
// Returns the type of an annotation, with type parameter substitutions
// performed if applicable.
fn ann_to_monotype(@type_store tystore, ast.ann a) -> @ty.t {
fn ann_to_monotype(@type_store tystore, ast.ann a) -> t {
// TODO: Refactor to use recursive pattern matching when we're more
// confident that it works.
alt (a) {
@ -1281,8 +1282,8 @@ fn ann_to_monotype(@type_store tystore, ast.ann a) -> @ty.t {
}
case (ast.ann_type(?typ, ?tps_opt, _)) {
alt (tps_opt) {
case (none[vec[@ty.t]]) { ret typ; }
case (some[vec[@ty.t]](?tps)) {
case (none[vec[t]]) { ret typ; }
case (some[vec[t]](?tps)) {
ret substitute_type_params(tystore, tps, typ);
}
}
@ -1291,13 +1292,13 @@ fn ann_to_monotype(@type_store tystore, ast.ann a) -> @ty.t {
}
// Turns a type into an ann_type, using defaults for other fields.
fn triv_ann(@ty.t typ) -> ast.ann {
ret ast.ann_type(typ, none[vec[@ty.t]], none[@ts_ann]);
fn triv_ann(t typ) -> ast.ann {
ret ast.ann_type(typ, none[vec[t]], none[@ts_ann]);
}
// Returns the number of distinct type parameters in the given type.
fn count_ty_params(@t ty) -> uint {
fn counter(@mutable vec[uint] param_indices, @t ty) {
fn count_ty_params(t ty) -> uint {
fn counter(@mutable vec[uint] param_indices, t ty) {
alt (struct(ty)) {
case (ty_param(?param_idx)) {
auto seen = false;
@ -1321,8 +1322,8 @@ fn count_ty_params(@t ty) -> uint {
ret _vec.len[uint](*param_indices);
}
fn type_contains_vars(@t typ) -> bool {
fn checker(@mutable bool flag, @t typ) {
fn type_contains_vars(t typ) -> bool {
fn checker(@mutable bool flag, t typ) {
alt (struct(typ)) {
case (ty_var(_)) { *flag = true; }
case (_) { /* fall through */ }
@ -1337,7 +1338,7 @@ fn type_contains_vars(@t typ) -> bool {
// Type accessors for substructures of types
fn ty_fn_args(@t fty) -> vec[arg] {
fn ty_fn_args(t fty) -> vec[arg] {
alt (struct(fty)) {
case (ty.ty_fn(_, ?a, _)) { ret a; }
case (ty.ty_native_fn(_, ?a, _)) { ret a; }
@ -1345,21 +1346,21 @@ fn ty_fn_args(@t fty) -> vec[arg] {
fail;
}
fn ty_fn_proto(@t fty) -> ast.proto {
fn ty_fn_proto(t fty) -> ast.proto {
alt (struct(fty)) {
case (ty.ty_fn(?p, _, _)) { ret p; }
}
fail;
}
fn ty_fn_abi(@t fty) -> ast.native_abi {
fn ty_fn_abi(t fty) -> ast.native_abi {
alt (struct(fty)) {
case (ty.ty_native_fn(?a, _, _)) { ret a; }
}
fail;
}
fn ty_fn_ret(@t fty) -> @t {
fn ty_fn_ret(t fty) -> t {
alt (struct(fty)) {
case (ty.ty_fn(_, _, ?r)) { ret r; }
case (ty.ty_native_fn(_, _, ?r)) { ret r; }
@ -1367,7 +1368,7 @@ fn ty_fn_ret(@t fty) -> @t {
fail;
}
fn is_fn_ty(@t fty) -> bool {
fn is_fn_ty(t fty) -> bool {
alt (struct(fty)) {
case (ty.ty_fn(_, _, _)) { ret true; }
case (ty.ty_native_fn(_, _, _)) { ret true; }
@ -1425,7 +1426,7 @@ fn item_ty(@ast.item it) -> ty_param_count_and_ty {
ret tup(ty_param_count, result_ty);
}
fn stmt_ty(@type_store tystore, @ast.stmt s) -> @t {
fn stmt_ty(@type_store tystore, @ast.stmt s) -> t {
alt (s.node) {
case (ast.stmt_expr(?e,_)) {
ret expr_ty(tystore, e);
@ -1436,7 +1437,7 @@ fn stmt_ty(@type_store tystore, @ast.stmt s) -> @t {
}
}
fn block_ty(@type_store tystore, &ast.block b) -> @t {
fn block_ty(@type_store tystore, &ast.block b) -> t {
alt (b.node.expr) {
case (some[@ast.expr](?e)) { ret expr_ty(tystore, e); }
case (none[@ast.expr]) { ret mk_nil(tystore); }
@ -1445,7 +1446,7 @@ fn block_ty(@type_store tystore, &ast.block b) -> @t {
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
// doesn't provide type parameter substitutions.
fn pat_ty(@type_store ts, @ast.pat pat) -> @t {
fn pat_ty(@type_store ts, @ast.pat pat) -> t {
alt (pat.node) {
case (ast.pat_wild(?ann)) { ret ann_to_monotype(ts, ann); }
case (ast.pat_lit(_, ?ann)) { ret ann_to_monotype(ts, ann); }
@ -1507,7 +1508,7 @@ fn expr_ann(@ast.expr expr) -> option.t[ast.ann] {
// ask for the type of "id" in "id(3)", it will return "fn(&int) -> int"
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
// expr_ty_params_and_ty() below.
fn expr_ty(@type_store tystore, @ast.expr expr) -> @t {
fn expr_ty(@type_store tystore, @ast.expr expr) -> t {
alt (expr_ann(expr)) {
case (none[ast.ann]) { ret mk_nil(tystore); }
case (some[ast.ann](?a)) { ret ann_to_monotype(tystore, a); }
@ -1515,10 +1516,10 @@ fn expr_ty(@type_store tystore, @ast.expr expr) -> @t {
}
fn expr_ty_params_and_ty(@type_store tystore, @ast.expr expr)
-> tup(vec[@t], @t) {
-> tup(vec[t], t) {
alt (expr_ann(expr)) {
case (none[ast.ann]) {
let vec[@t] tps = vec();
let vec[t] tps = vec();
ret tup(tps, mk_nil(tystore));
}
case (some[ast.ann](?a)) {
@ -1535,7 +1536,7 @@ fn expr_has_ty_params(@ast.expr expr) -> bool {
alt (a) {
case (ast.ann_none) { fail; }
case (ast.ann_type(_, ?tps_opt, _)) {
ret !option.is_none[vec[@t]](tps_opt);
ret !option.is_none[vec[t]](tps_opt);
}
}
}
@ -1543,12 +1544,12 @@ fn expr_has_ty_params(@ast.expr expr) -> bool {
}
// FIXME: At the moment this works only for call, bind, and path expressions.
fn replace_expr_type(@ast.expr expr, tup(vec[@t], @t) new_tyt) -> @ast.expr {
fn replace_expr_type(@ast.expr expr, tup(vec[t], t) new_tyt) -> @ast.expr {
auto new_tps;
if (expr_has_ty_params(expr)) {
new_tps = some[vec[@t]](new_tyt._0);
new_tps = some[vec[t]](new_tyt._0);
} else {
new_tps = none[vec[@t]];
new_tps = none[vec[t]];
}
auto ann = ast.ann_type(new_tyt._1, new_tps, none[@ts_ann]);
@ -1662,13 +1663,13 @@ fn is_lval(@ast.expr expr) -> bool {
mod Unify {
tag result {
ures_ok(@ty.t);
ures_err(type_err, @ty.t, @ty.t);
ures_ok(t);
ures_err(type_err, t, t);
}
type ctxt = rec(UFind.ufind sets,
hashmap[int,uint] var_ids,
mutable vec[mutable vec[@t]] types,
mutable vec[mutable vec[t]] types,
unify_handler handler,
@type_store tystore);
@ -1680,7 +1681,7 @@ mod Unify {
// something we'll probably need to develop over time.
// Simple structural type comparison.
fn struct_cmp(@ty.t expected, @ty.t actual) -> result {
fn struct_cmp(t expected, t actual) -> result {
if (struct(expected) == struct(actual)) {
ret ures_ok(expected);
}
@ -1705,14 +1706,14 @@ mod Unify {
tag fn_common_res {
fn_common_res_err(result);
fn_common_res_ok(vec[arg], @t);
fn_common_res_ok(vec[arg], t);
}
fn unify_fn_common(@ctxt cx,
@ty.t expected,
@ty.t actual,
vec[arg] expected_inputs, @t expected_output,
vec[arg] actual_inputs, @t actual_output)
t expected,
t actual,
vec[arg] expected_inputs, t expected_output,
vec[arg] actual_inputs, t actual_output)
-> fn_common_res {
auto expected_len = _vec.len[arg](expected_inputs);
auto actual_len = _vec.len[arg](actual_inputs);
@ -1768,10 +1769,10 @@ mod Unify {
fn unify_fn(@ctxt cx,
ast.proto e_proto,
ast.proto a_proto,
@ty.t expected,
@ty.t actual,
vec[arg] expected_inputs, @t expected_output,
vec[arg] actual_inputs, @t actual_output)
t expected,
t actual,
vec[arg] expected_inputs, t expected_output,
vec[arg] actual_inputs, t actual_output)
-> result {
if (e_proto != a_proto) {
@ -1794,10 +1795,10 @@ mod Unify {
fn unify_native_fn(@ctxt cx,
ast.native_abi e_abi,
ast.native_abi a_abi,
@ty.t expected,
@ty.t actual,
vec[arg] expected_inputs, @t expected_output,
vec[arg] actual_inputs, @t actual_output)
t expected,
t actual,
vec[arg] expected_inputs, t expected_output,
vec[arg] actual_inputs, t actual_output)
-> result {
if (e_abi != a_abi) {
ret ures_err(terr_mismatch, expected, actual);
@ -1819,8 +1820,8 @@ mod Unify {
}
fn unify_obj(@ctxt cx,
@ty.t expected,
@ty.t actual,
t expected,
t actual,
vec[method] expected_meths,
vec[method] actual_meths) -> result {
let vec[method] result_meths = vec();
@ -1876,7 +1877,7 @@ mod Unify {
ret set_num;
}
fn unify_step(@ctxt cx, @ty.t expected, @ty.t actual) -> result {
fn unify_step(@ctxt cx, t expected, t actual) -> result {
// TODO: rewrite this using tuple pattern matching when available, to
// avoid all this rightward drift and spikiness.
@ -1899,7 +1900,7 @@ mod Unify {
case (_) {
// Just bind the type variable to the expected type.
auto vlen = _vec.len[mutable vec[@t]](cx.types);
auto vlen = _vec.len[mutable vec[t]](cx.types);
if (actual_n < vlen) {
cx.types.(actual_n) += vec(expected);
} else {
@ -1913,8 +1914,8 @@ mod Unify {
case (ty.ty_local(?actual_id)) {
auto result_ty;
alt (cx.handler.resolve_local(actual_id)) {
case (none[@ty.t]) { result_ty = expected; }
case (some[@ty.t](?actual_ty)) {
case (none[t]) { result_ty = expected; }
case (some[t](?actual_ty)) {
auto result = unify_step(cx, expected, actual_ty);
alt (result) {
case (ures_ok(?rty)) { result_ty = rty; }
@ -1964,9 +1965,9 @@ mod Unify {
// TODO: factor this cruft out, see the TODO in the
// ty.ty_tup case
let vec[@ty.t] result_tps = vec();
let vec[t] result_tps = vec();
auto i = 0u;
auto expected_len = _vec.len[@ty.t](expected_tps);
auto expected_len = _vec.len[t](expected_tps);
while (i < expected_len) {
auto expected_tp = expected_tps.(i);
auto actual_tp = actual_tps.(i);
@ -1977,7 +1978,7 @@ mod Unify {
alt (result) {
case (ures_ok(?rty)) {
_vec.push[@ty.t](result_tps, rty);
_vec.push[t](result_tps, rty);
}
case (_) {
ret result;
@ -2268,7 +2269,7 @@ mod Unify {
case (ty.ty_var(?expected_id)) {
// Add a binding.
auto expected_n = get_or_create_set(cx, expected_id);
auto vlen = _vec.len[mutable vec[@t]](cx.types);
auto vlen = _vec.len[mutable vec[t]](cx.types);
if (expected_n < vlen) {
cx.types.(expected_n) += vec(actual);
} else {
@ -2281,8 +2282,8 @@ mod Unify {
case (ty.ty_local(?expected_id)) {
auto result_ty;
alt (cx.handler.resolve_local(expected_id)) {
case (none[@ty.t]) { result_ty = actual; }
case (some[@ty.t](?expected_ty)) {
case (none[t]) { result_ty = actual; }
case (some[t](?expected_ty)) {
auto result = unify_step(cx, expected_ty, actual);
alt (result) {
case (ures_ok(?rty)) { result_ty = rty; }
@ -2305,8 +2306,8 @@ mod Unify {
}
// Performs type binding substitution.
fn substitute(@ctxt cx, vec[@t] set_types, @t typ) -> @t {
fn substituter(@ctxt cx, vec[@t] types, @t typ) -> @t {
fn substitute(@ctxt cx, vec[t] set_types, t typ) -> t {
fn substituter(@ctxt cx, vec[t] types, t typ) -> t {
alt (struct(typ)) {
case (ty_var(?id)) {
alt (cx.var_ids.find(id)) {
@ -2325,26 +2326,26 @@ mod Unify {
ret fold_ty(cx.tystore, f, typ);
}
fn unify_sets(@ctxt cx) -> vec[@t] {
let vec[@t] throwaway = vec();
let vec[mutable vec[@t]] set_types = vec(mutable throwaway);
_vec.pop[mutable vec[@t]](set_types); // FIXME: botch
fn unify_sets(@ctxt cx) -> vec[t] {
let vec[t] throwaway = vec();
let vec[mutable vec[t]] set_types = vec(mutable throwaway);
_vec.pop[mutable vec[t]](set_types); // FIXME: botch
for (UFind.node node in cx.sets.nodes) {
let vec[@t] v = vec();
let vec[t] v = vec();
set_types += vec(mutable v);
}
auto i = 0u;
while (i < _vec.len[mutable vec[@t]](set_types)) {
while (i < _vec.len[mutable vec[t]](set_types)) {
auto root = UFind.find(cx.sets, i);
set_types.(root) += cx.types.(i);
i += 1u;
}
let vec[@t] result = vec();
for (vec[@t] types in set_types) {
if (_vec.len[@t](types) > 1u) {
let vec[t] result = vec();
for (vec[t] types in set_types) {
if (_vec.len[t](types) > 1u) {
log_err "unification of > 1 types in a type set is " +
"unimplemented";
fail;
@ -2355,13 +2356,13 @@ mod Unify {
ret result;
}
fn unify(@ty.t expected,
@ty.t actual,
fn unify(t expected,
t actual,
&unify_handler handler,
@type_store tystore) -> result {
let vec[@t] throwaway = vec();
let vec[mutable vec[@t]] types = vec(mutable throwaway);
_vec.pop[mutable vec[@t]](types); // FIXME: botch
let vec[t] throwaway = vec();
let vec[mutable vec[t]] types = vec(mutable throwaway);
_vec.pop[mutable vec[t]](types); // FIXME: botch
auto cx = @rec(sets=UFind.make(),
var_ids=common.new_int_hash[uint](),
@ -2437,9 +2438,9 @@ fn type_err_to_str(&ty.type_err err) -> str {
// Performs bound type parameter replacement using the supplied mapping from
// parameter IDs to types.
fn substitute_type_params(@type_store tystore,
vec[@t] bindings,
@t typ) -> @t {
fn replacer(vec[@t] bindings, @t typ) -> @t {
vec[t] bindings,
t typ) -> t {
fn replacer(vec[t] bindings, t typ) -> t {
alt (struct(typ)) {
case (ty_bound_param(?param_index)) {
ret bindings.(param_index);
@ -2453,8 +2454,8 @@ fn substitute_type_params(@type_store tystore,
}
// Converts type parameters in a type to bound type parameters.
fn bind_params_in_type(@type_store tystore, @t typ) -> @t {
fn binder(@type_store tystore, @t typ) -> @t {
fn bind_params_in_type(@type_store tystore, t typ) -> t {
fn binder(@type_store tystore, t typ) -> t {
alt (struct(typ)) {
case (ty_bound_param(?index)) {
log_err "bind_params_in_type() called on type that already " +

View file

@ -43,7 +43,7 @@ import pretty.pprust;
import util.typestate_ann.ts_ann;
type ty_table = hashmap[ast.def_id, @ty.t];
type ty_table = hashmap[ast.def_id, ty.t];
tag any_item {
any_item_rust(@ast.item);
@ -52,7 +52,7 @@ tag any_item {
type ty_item_table = hashmap[ast.def_id,any_item];
type unify_cache_entry = tup(@ty.t,@ty.t,vec[mutable @ty.t]);
type unify_cache_entry = tup(ty.t,ty.t,vec[mutable ty.t]);
type unify_cache = hashmap[unify_cache_entry,ty.Unify.result];
type crate_ctxt = rec(session.session sess,
@ -66,7 +66,7 @@ type crate_ctxt = rec(session.session sess,
mutable uint cache_misses,
@ty.type_store tystore);
type fn_ctxt = rec(@ty.t ret_ty,
type fn_ctxt = rec(ty.t ret_ty,
@ty_table locals,
@crate_ctxt ccx);
@ -76,18 +76,18 @@ type ty_getter = fn(ast.def_id) -> ty.ty_param_count_and_ty;
// Substitutes the user's explicit types for the parameters in a path
// expression.
fn substitute_ty_params(&@crate_ctxt ccx,
@ty.t typ,
ty.t typ,
uint ty_param_count,
vec[@ty.t] supplied,
&span sp) -> @ty.t {
fn substituter(@crate_ctxt ccx, vec[@ty.t] supplied, @ty.t typ) -> @ty.t {
vec[ty.t] supplied,
&span sp) -> ty.t {
fn substituter(@crate_ctxt ccx, vec[ty.t] supplied, ty.t typ) -> ty.t {
alt (struct(typ)) {
case (ty.ty_bound_param(?pid)) { ret supplied.(pid); }
case (_) { ret typ; }
}
}
auto supplied_len = _vec.len[@ty.t](supplied);
auto supplied_len = _vec.len[ty.t](supplied);
if (ty_param_count != supplied_len) {
ccx.sess.span_err(sp, "expected " +
_uint.to_str(ty_param_count, 10u) +
@ -112,8 +112,8 @@ fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.def defn)
case (ast.def_local(?id)) {
auto t;
alt (fcx.locals.find(id)) {
case (some[@ty.t](?t1)) { t = t1; }
case (none[@ty.t]) { t = ty.mk_local(fcx.ccx.tystore, id); }
case (some[ty.t](?t1)) { t = t1; }
case (none[ty.t]) { t = ty.mk_local(fcx.ccx.tystore, id); }
}
ret tup(0u, t);
}
@ -175,13 +175,13 @@ fn instantiate_path(@fn_ctxt fcx, &ast.path pth, &ty_param_count_and_ty tpt,
auto ty_substs_opt;
auto ty_substs_len = _vec.len[@ast.ty](pth.node.types);
if (ty_substs_len > 0u) {
let vec[@ty.t] ty_substs = vec();
let vec[ty.t] ty_substs = vec();
auto i = 0u;
while (i < ty_substs_len) {
ty_substs += vec(ast_ty_to_ty_crate(fcx.ccx, pth.node.types.(i)));
i += 1u;
}
ty_substs_opt = some[vec[@ty.t]](ty_substs);
ty_substs_opt = some[vec[ty.t]](ty_substs);
if (ty_param_count == 0u) {
fcx.ccx.sess.span_err(sp, "this item does not take type " +
@ -190,13 +190,13 @@ fn instantiate_path(@fn_ctxt fcx, &ast.path pth, &ty_param_count_and_ty tpt,
}
} else {
// We will acquire the type parameters through unification.
let vec[@ty.t] ty_substs = vec();
let vec[ty.t] ty_substs = vec();
auto i = 0u;
while (i < ty_param_count) {
ty_substs += vec(next_ty_var(fcx.ccx));
i += 1u;
}
ty_substs_opt = some[vec[@ty.t]](ty_substs);
ty_substs_opt = some[vec[ty.t]](ty_substs);
}
ret ast.ann_type(t, ty_substs_opt, none[@ts_ann]);
@ -207,11 +207,11 @@ fn instantiate_path(@fn_ctxt fcx, &ast.path pth, &ty_param_count_and_ty tpt,
// corresponding to a definition ID.
fn ast_ty_to_ty(@ty.type_store tystore,
ty_getter getter,
&@ast.ty ast_ty) -> @ty.t {
&@ast.ty ast_ty) -> ty.t {
fn ast_arg_to_arg(@ty.type_store tystore,
ty_getter getter,
&rec(ast.mode mode, @ast.ty ty) arg)
-> rec(ast.mode mode, @ty.t ty) {
-> rec(ast.mode mode, ty.t ty) {
ret rec(mode=arg.mode, ty=ast_ty_to_ty(tystore, getter, arg.ty));
}
@ -224,7 +224,7 @@ fn ast_ty_to_ty(@ty.type_store tystore,
fn instantiate(@ty.type_store tystore,
ty_getter getter,
ast.def_id id,
vec[@ast.ty] args) -> @ty.t {
vec[@ast.ty] args) -> ty.t {
// TODO: maybe record cname chains so we can do
// "foo = int" like OCaml?
auto params_opt_and_ty = getter(id);
@ -238,7 +238,7 @@ fn ast_ty_to_ty(@ty.type_store tystore,
// TODO: Make sure the number of supplied bindings matches the number
// of type parameters in the typedef. Emit a friendly error otherwise.
auto bound_ty = bind_params_in_type(tystore, params_opt_and_ty._1);
let vec[@ty.t] param_bindings = vec();
let vec[ty.t] param_bindings = vec();
for (@ast.ty ast_ty in args) {
param_bindings += vec(ast_ty_to_ty(tystore, getter, ast_ty));
}
@ -340,7 +340,7 @@ fn ast_ty_to_ty(@ty.type_store tystore,
// A convenience function to use a crate_ctxt to resolve names for
// ast_ty_to_ty.
fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast.ty ast_ty) -> @ty.t {
fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast.ty ast_ty) -> ty.t {
fn getter(@crate_ctxt ccx, ast.def_id id) -> ty.ty_param_count_and_ty {
ret ty.lookup_item_type(ccx.sess, ccx.tystore, ccx.type_cache, id);
}
@ -368,7 +368,7 @@ mod Collect {
type env = rec(@ctxt cx, ast.native_abi abi);
fn ty_of_fn_decl(@ctxt cx,
fn(&@ast.ty ast_ty) -> @ty.t convert,
fn(&@ast.ty ast_ty) -> ty.t convert,
fn(&ast.arg a) -> arg ty_of_arg,
&ast.fn_decl decl,
ast.proto proto,
@ -384,7 +384,7 @@ mod Collect {
}
fn ty_of_native_fn_decl(@ctxt cx,
fn(&@ast.ty ast_ty) -> @ty.t convert,
fn(&@ast.ty ast_ty) -> ty.t convert,
fn(&ast.arg a) -> arg ty_of_arg,
&ast.fn_decl decl,
ast.native_abi abi,
@ -510,7 +510,7 @@ mod Collect {
case (ast.item_tag(_, _, ?tps, ?def_id, _)) {
// Create a new generic polytype.
let vec[@ty.t] subtys = vec();
let vec[ty.t] subtys = vec();
auto i = 0u;
for (ast.ty_param tp in tps) {
@ -563,7 +563,7 @@ mod Collect {
let vec[ast.variant] result = vec();
// Create a set of parameter types shared among all the variants.
let vec[@ty.t] ty_param_tys = vec();
let vec[ty.t] ty_param_tys = vec();
auto i = 0u;
for (ast.ty_param tp in ty_params) {
ty_param_tys += vec(ty.mk_param(cx.tystore, i));
@ -686,7 +686,7 @@ mod Collect {
ret @fold.respan[ast.native_item_](sp, item);
}
fn get_ctor_obj_methods(@ty.t t) -> vec[method] {
fn get_ctor_obj_methods(ty.t t) -> vec[method] {
alt (struct(t)) {
case (ty.ty_fn(_,_,?tobj)) {
alt (struct(tobj)) {
@ -735,7 +735,7 @@ mod Collect {
}
auto g = bind getter(e.cx, _);
for (ast.obj_field fld in ob.fields) {
let @ty.t fty = ast_ty_to_ty(e.cx.tystore, g, fld.ty);
let ty.t fty = ast_ty_to_ty(e.cx.tystore, g, fld.ty);
let ast.obj_field f = rec(ann=triv_ann(fty)
with fld
);
@ -746,7 +746,7 @@ mod Collect {
alt (ob.dtor) {
case (some[@ast.method](?d)) {
let vec[arg] inputs = vec();
let @ty.t output = ty.mk_nil(e.cx.tystore);
let ty.t output = ty.mk_nil(e.cx.tystore);
auto dtor_tfn = ty.mk_fn(e.cx.tystore, ast.proto_fn, inputs,
output);
auto d_ = rec(ann=triv_ann(dtor_tfn) with d.node);
@ -780,7 +780,7 @@ mod Collect {
ty_params);
auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.item_tag(i, variants_t, ty_params, id,
ast.ann_type(typ, none[vec[@ty.t]],
ast.ann_type(typ, none[vec[ty.t]],
none[@ts_ann]));
ret @fold.respan[ast.item_](sp, item);
}
@ -830,16 +830,16 @@ mod Collect {
// Type unification
mod Unify {
fn simple(@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> ty.Unify.result {
fn simple(@fn_ctxt fcx, ty.t expected, ty.t actual) -> ty.Unify.result {
// FIXME: horrid botch
let vec[mutable @ty.t] param_substs =
let vec[mutable ty.t] param_substs =
vec(mutable ty.mk_nil(fcx.ccx.tystore));
_vec.pop[mutable @ty.t](param_substs);
_vec.pop[mutable ty.t](param_substs);
ret with_params(fcx, expected, actual, param_substs);
}
fn with_params(@fn_ctxt fcx, @ty.t expected, @ty.t actual,
vec[mutable @ty.t] param_substs) -> ty.Unify.result {
fn with_params(@fn_ctxt fcx, ty.t expected, ty.t actual,
vec[mutable ty.t] param_substs) -> ty.Unify.result {
auto cache_key = tup(expected, actual, param_substs);
if (fcx.ccx.unify_cache.contains_key(cache_key)) {
fcx.ccx.cache_hits += 1u;
@ -848,25 +848,25 @@ mod Unify {
fcx.ccx.cache_misses += 1u;
obj unify_handler(@fn_ctxt fcx, vec[mutable @ty.t] param_substs) {
fn resolve_local(ast.def_id id) -> option.t[@ty.t] {
obj unify_handler(@fn_ctxt fcx, vec[mutable ty.t] param_substs) {
fn resolve_local(ast.def_id id) -> option.t[ty.t] {
alt (fcx.locals.find(id)) {
case (none[@ty.t]) { ret none[@ty.t]; }
case (some[@ty.t](?existing_type)) {
case (none[ty.t]) { ret none[ty.t]; }
case (some[ty.t](?existing_type)) {
if (ty.type_contains_vars(existing_type)) {
// Not fully resolved yet. The writeback phase
// will mop up.
ret none[@ty.t];
ret none[ty.t];
}
ret some[@ty.t](existing_type);
ret some[ty.t](existing_type);
}
}
}
fn record_local(ast.def_id id, @ty.t new_type) {
fn record_local(ast.def_id id, ty.t new_type) {
auto unified_type;
alt (fcx.locals.find(id)) {
case (none[@ty.t]) { unified_type = new_type; }
case (some[@ty.t](?old_type)) {
case (none[ty.t]) { unified_type = new_type; }
case (some[ty.t](?old_type)) {
alt (with_params(fcx, old_type, new_type,
param_substs)) {
case (ures_ok(?ut)) { unified_type = ut; }
@ -876,8 +876,8 @@ mod Unify {
}
// TODO: "freeze"
let vec[@ty.t] param_substs_1 = vec();
for (@ty.t subst in param_substs) {
let vec[ty.t] param_substs_1 = vec();
for (ty.t subst in param_substs) {
param_substs_1 += vec(subst);
}
@ -886,7 +886,7 @@ mod Unify {
unified_type);
fcx.locals.insert(id, unified_type);
}
fn record_param(uint index, @ty.t binding) -> ty.Unify.result {
fn record_param(uint index, ty.t binding) -> ty.Unify.result {
// Unify with the appropriate type in the parameter
// substitution list.
auto old_subst = param_substs.(index);
@ -921,7 +921,7 @@ tag autoderef_kind {
NO_AUTODEREF;
}
fn strip_boxes(@ty.t t) -> @ty.t {
fn strip_boxes(ty.t t) -> ty.t {
auto t1 = t;
while (true) {
alt (struct(t1)) {
@ -932,7 +932,7 @@ fn strip_boxes(@ty.t t) -> @ty.t {
fail;
}
fn add_boxes(@crate_ctxt ccx, uint n, @ty.t t) -> @ty.t {
fn add_boxes(@crate_ctxt ccx, uint n, ty.t t) -> ty.t {
auto t1 = t;
while (n != 0u) {
t1 = ty.mk_imm_box(ccx.tystore, t1);
@ -942,7 +942,7 @@ fn add_boxes(@crate_ctxt ccx, uint n, @ty.t t) -> @ty.t {
}
fn count_boxes(@ty.t t) -> uint {
fn count_boxes(ty.t t) -> uint {
auto n = 0u;
auto t1 = t;
while (true) {
@ -958,25 +958,25 @@ fn count_boxes(@ty.t t) -> uint {
// Demands - procedures that require that two types unify and emit an error
// message if they don't.
type ty_param_substs_and_ty = tup(vec[@ty.t], @ty.t);
type ty_param_substs_and_ty = tup(vec[ty.t], ty.t);
mod Demand {
fn simple(@fn_ctxt fcx, &span sp, @ty.t expected, @ty.t actual) -> @ty.t {
let vec[@ty.t] tps = vec();
fn simple(@fn_ctxt fcx, &span sp, ty.t expected, ty.t actual) -> ty.t {
let vec[ty.t] tps = vec();
ret full(fcx, sp, expected, actual, tps, NO_AUTODEREF)._1;
}
fn autoderef(@fn_ctxt fcx, &span sp, @ty.t expected, @ty.t actual,
autoderef_kind adk) -> @ty.t {
let vec[@ty.t] tps = vec();
fn autoderef(@fn_ctxt fcx, &span sp, ty.t expected, ty.t actual,
autoderef_kind adk) -> ty.t {
let vec[ty.t] tps = vec();
ret full(fcx, sp, expected, actual, tps, adk)._1;
}
// Requires that the two types unify, and prints an error message if they
// don't. Returns the unified type and the type parameter substitutions.
fn full(@fn_ctxt fcx, &span sp, @ty.t expected, @ty.t actual,
vec[@ty.t] ty_param_substs_0, autoderef_kind adk)
fn full(@fn_ctxt fcx, &span sp, ty.t expected, ty.t actual,
vec[ty.t] ty_param_substs_0, autoderef_kind adk)
-> ty_param_substs_and_ty {
auto expected_1 = expected;
@ -989,18 +989,18 @@ mod Demand {
implicit_boxes = count_boxes(actual);
}
let vec[mutable @ty.t] ty_param_substs =
let vec[mutable ty.t] ty_param_substs =
vec(mutable ty.mk_nil(fcx.ccx.tystore));
_vec.pop[mutable @ty.t](ty_param_substs); // FIXME: horrid botch
for (@ty.t ty_param_subst in ty_param_substs_0) {
_vec.pop[mutable ty.t](ty_param_substs); // FIXME: horrid botch
for (ty.t ty_param_subst in ty_param_substs_0) {
ty_param_substs += vec(mutable ty_param_subst);
}
alt (Unify.with_params(fcx, expected_1, actual_1, ty_param_substs)) {
case (ures_ok(?t)) {
// TODO: Use "freeze", when we have it.
let vec[@ty.t] result_ty_param_substs = vec();
for (mutable @ty.t ty_param_subst in ty_param_substs) {
let vec[ty.t] result_ty_param_substs = vec();
for (mutable ty.t ty_param_subst in ty_param_substs) {
result_ty_param_substs += vec(ty_param_subst);
}
@ -1024,7 +1024,7 @@ mod Demand {
// Returns true if the two types unify and false if they don't.
fn are_compatible(&@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> bool {
fn are_compatible(&@fn_ctxt fcx, ty.t expected, ty.t actual) -> bool {
alt (Unify.simple(fcx, expected, actual)) {
case (ures_ok(_)) { ret true; }
case (ures_err(_, _, _)) { ret false; }
@ -1033,10 +1033,10 @@ fn are_compatible(&@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> bool {
// Returns the types of the arguments to a tag variant.
fn variant_arg_types(@crate_ctxt ccx, &span sp, ast.def_id vid,
vec[@ty.t] tag_ty_params) -> vec[@ty.t] {
auto ty_param_count = _vec.len[@ty.t](tag_ty_params);
vec[ty.t] tag_ty_params) -> vec[ty.t] {
auto ty_param_count = _vec.len[ty.t](tag_ty_params);
let vec[@ty.t] result = vec();
let vec[ty.t] result = vec();
auto tpt = ty.lookup_item_type(ccx.sess, ccx.tystore, ccx.type_cache,
vid);
@ -1081,20 +1081,20 @@ mod Pushdown {
//
// TODO: enforce this via a predicate.
fn pushdown_pat(&@fn_ctxt fcx, @ty.t expected, @ast.pat pat) -> @ast.pat {
fn pushdown_pat(&@fn_ctxt fcx, ty.t expected, @ast.pat pat) -> @ast.pat {
auto p_1;
alt (pat.node) {
case (ast.pat_wild(?ann)) {
auto t = Demand.simple(fcx, pat.span, expected,
ann_to_type(ann));
p_1 = ast.pat_wild(ast.ann_type(t, none[vec[@ty.t]],
p_1 = ast.pat_wild(ast.ann_type(t, none[vec[ty.t]],
none[@ts_ann]));
}
case (ast.pat_lit(?lit, ?ann)) {
auto t = Demand.simple(fcx, pat.span, expected,
ann_to_type(ann));
p_1 = ast.pat_lit(lit, ast.ann_type(t, none[vec[@ty.t]],
p_1 = ast.pat_lit(lit, ast.ann_type(t, none[vec[ty.t]],
none[@ts_ann]));
}
case (ast.pat_bind(?id, ?did, ?ann)) {
@ -1102,7 +1102,7 @@ mod Pushdown {
ann_to_type(ann));
fcx.locals.insert(did, t);
p_1 = ast.pat_bind(id, did, ast.ann_type(t,
none[vec[@ty.t]],
none[vec[ty.t]],
none[@ts_ann]));
}
case (ast.pat_tag(?id, ?subpats, ?vdef_opt, ?ann)) {
@ -1143,12 +1143,12 @@ mod Pushdown {
// TODO: enforce this via a predicate.
// TODO: This function is incomplete.
fn pushdown_expr(&@fn_ctxt fcx, @ty.t expected, @ast.expr e)
fn pushdown_expr(&@fn_ctxt fcx, ty.t expected, @ast.expr e)
-> @ast.expr {
be pushdown_expr_full(fcx, expected, e, NO_AUTODEREF);
}
fn pushdown_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
fn pushdown_expr_full(&@fn_ctxt fcx, ty.t expected, @ast.expr e,
autoderef_kind adk) -> @ast.expr {
auto e_1;
@ -1374,11 +1374,11 @@ mod Pushdown {
}
case (ast.ann_type(_, ?tps_opt, _)) {
alt (tps_opt) {
case (none[vec[@ty.t]]) {
ty_params_opt = none[vec[@ty.t]];
case (none[vec[ty.t]]) {
ty_params_opt = none[vec[ty.t]];
}
case (some[vec[@ty.t]](?tps)) {
ty_params_opt = some[vec[@ty.t]](tps);
case (some[vec[ty.t]](?tps)) {
ty_params_opt = some[vec[ty.t]](tps);
}
}
}
@ -1472,7 +1472,7 @@ mod Pushdown {
}
// Push-down over typed blocks.
fn pushdown_block(&@fn_ctxt fcx, @ty.t expected, &ast.block bloc)
fn pushdown_block(&@fn_ctxt fcx, ty.t expected, &ast.block bloc)
-> ast.block {
alt (bloc.node.expr) {
case (some[@ast.expr](?e_0)) {
@ -1514,7 +1514,7 @@ fn writeback_local(&option.t[@fn_ctxt] env, &span sp, @ast.local local)
fn resolve_local_types_in_annotation(&option.t[@fn_ctxt] env, ast.ann ann)
-> ast.ann {
fn resolver(@fn_ctxt fcx, @ty.t typ) -> @ty.t {
fn resolver(@fn_ctxt fcx, ty.t typ) -> ty.t {
alt (struct(typ)) {
case (ty.ty_local(?lid)) { ret fcx.locals.get(lid); }
case (_) { ret typ; }
@ -1563,7 +1563,7 @@ fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast.block block)
// AST fragment checking
fn check_lit(@crate_ctxt ccx, @ast.lit lit) -> @ty.t {
fn check_lit(@crate_ctxt ccx, @ast.lit lit) -> ty.t {
alt (lit.node) {
case (ast.lit_str(_)) { ret ty.mk_str(ccx.tystore); }
case (ast.lit_char(_)) { ret ty.mk_char(ccx.tystore); }
@ -2218,7 +2218,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_self_method(?id, _)) {
auto t = ty.mk_nil(fcx.ccx.tystore);
let @ty.t this_obj_ty;
let ty.t this_obj_ty;
// Grab the type of the current object
auto this_obj_id = fcx.ccx.this_obj;
@ -2233,7 +2233,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
// Grab this method's type out of the current object type
// this_obj_ty is an @ty.t
// this_obj_ty is an ty.t
alt (struct(this_obj_ty)) {
case (ty.ty_obj(?methods)) {
for (ty.method method in methods) {
@ -2302,7 +2302,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_vec(?args, ?mut, _)) {
let vec[@ast.expr] args_1 = vec();
let @ty.t t;
let ty.t t;
if (_vec.len[@ast.expr](args) == 0u) {
t = next_ty_var(fcx.ccx);
} else {
@ -2544,7 +2544,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
}
fn next_ty_var(@crate_ctxt ccx) -> @ty.t {
fn next_ty_var(@crate_ctxt ccx) -> ty.t {
auto t = ty.mk_var(ccx.tystore, ccx.next_var_id);
ccx.next_var_id += 1;
ret t;
@ -2667,7 +2667,7 @@ fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,
// for checking the initializer expression.
auto rty = ann_to_type(ann);
let @fn_ctxt fcx = @rec(ret_ty = rty,
locals = @common.new_def_hash[@ty.t](),
locals = @common.new_def_hash[ty.t](),
ccx = ccx);
auto e_ = check_expr(fcx, e);
// FIXME: necessary? Correct sequence?
@ -2678,7 +2678,7 @@ fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,
fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl, ast.proto proto,
&ast.block body) -> ast._fn {
auto local_ty_table = @common.new_def_hash[@ty.t]();
auto local_ty_table = @common.new_def_hash[ty.t]();
// FIXME: duplicate work: the item annotation already has the arg types
// and return type translated to typeck.ty values. We don't need do to it
@ -2752,7 +2752,7 @@ fn hash_unify_cache_entry(&unify_cache_entry uce) -> uint {
h += h << 5u + ty.hash_ty(uce._1);
auto i = 0u;
auto tys_len = _vec.len[mutable @ty.t](uce._2);
auto tys_len = _vec.len[mutable ty.t](uce._2);
while (i < tys_len) {
h += h << 5u + ty.hash_ty(uce._2.(i));
i += 1u;
@ -2765,8 +2765,8 @@ fn eq_unify_cache_entry(&unify_cache_entry a, &unify_cache_entry b) -> bool {
if (!ty.eq_ty(a._0, b._0) || !ty.eq_ty(a._1, b._1)) { ret false; }
auto i = 0u;
auto tys_len = _vec.len[mutable @ty.t](a._2);
if (_vec.len[mutable @ty.t](b._2) != tys_len) { ret false; }
auto tys_len = _vec.len[mutable ty.t](a._2);
if (_vec.len[mutable ty.t](b._2) != tys_len) { ret false; }
while (i < tys_len) {
if (!ty.eq_ty(a._2.(i), b._2.(i))) { ret false; }

View file

@ -112,7 +112,7 @@ fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] {
fn plain_ann(@middle.ty.type_store tystore) -> ast.ann {
ret ast.ann_type(middle.ty.mk_nil(tystore),
none[vec[@middle.ty.t]], none[@ts_ann]);
none[vec[middle.ty.t]], none[@ts_ann]);
}
fn log_expr(&ast.expr e) -> () {