rustc: Add support for folding over tag types

This commit is contained in:
Patrick Walton 2011-03-03 16:54:15 -08:00
parent 39b0563205
commit f6682280f3
3 changed files with 15 additions and 1 deletions

View file

@ -1144,6 +1144,8 @@ fn linearize_ty_params(@block_ctxt cx, @ty.t t)
}
ret t;
}
fn fold_tag_ty(@ty.t t) -> @ty.t { ret t; }
}

View file

@ -294,6 +294,7 @@ fn ty_to_str(&@t typ) -> str {
type ty_fold = state obj {
fn fold_simple_ty(@t ty) -> @t;
fn fold_tag_ty(@t ty) -> @t;
};
fn fold_ty(ty_fold fld, @t ty) -> @t {
@ -322,7 +323,8 @@ fn fold_ty(ty_fold fld, @t ty) -> @t {
for (@t subty in subtys) {
new_subtys += vec(fold_ty(fld, subty));
}
ret rewrap(ty, ty_tag(tid, new_subtys));
auto typ = rewrap(ty, ty_tag(tid, new_subtys));
ret fld.fold_tag_ty(typ);
}
case (ty_tup(?subtys)) {
let vec[@t] new_subtys = vec();
@ -611,6 +613,8 @@ fn count_ty_params(@t ty) -> uint {
}
ret ty;
}
fn fold_tag_ty(@t ty) -> @t { ret ty; }
}
let vec[ast.def_id] param_ids_inner = vec();
@ -1429,6 +1433,8 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
}
}
}
fn fold_tag_ty(@t typ) -> @t { ret typ; }
}
ret ty.fold_ty(folder(bindings), typ);
@ -1548,6 +1554,8 @@ fn replace_type_params(@t typ, hashmap[ast.def_id,@t] param_map) -> @t {
}
}
}
fn fold_tag_ty(@t typ) -> @t { ret typ; }
}
auto replacer = param_replacer(param_map);
ret fold_ty(replacer, typ);

View file

@ -73,6 +73,8 @@ fn generalize_ty(@crate_ctxt cx, @ty.t t) -> @ty.t {
}
ret t;
}
fn fold_tag_ty(@ty.t t) -> @ty.t { ret t; }
}
auto generalizer = ty_generalizer(cx, @common.new_def_hash[@ty.t]());
@ -114,6 +116,8 @@ fn substitute_ty_params(&@crate_ctxt ccx,
case (_) { ret typ; }
}
}
fn fold_tag_ty(@ty.t typ) -> @ty.t { ret typ; }
}
fn hash_int(&int x) -> uint { ret x as uint; }