rustc: Don't cache ast_ty_to_ty results for types that have references

This commit is contained in:
Patrick Walton 2012-03-13 14:12:44 -07:00
parent 02e9400a82
commit 0837a6ba04
2 changed files with 21 additions and 7 deletions

View File

@ -135,6 +135,8 @@ export param_bounds_to_kind;
export default_arg_mode_for_ty;
export item_path;
export item_path_str;
export ast_ty_to_ty_cache_entry;
export atttce_unresolved, atttce_resolved, atttce_has_regions;
// Data types
@ -162,6 +164,12 @@ type creader_cache = hashmap<{cnum: int, pos: uint, len: uint}, t>;
type intern_key = {struct: sty, o_def_id: option<ast::def_id>};
enum ast_ty_to_ty_cache_entry {
atttce_unresolved, /* not resolved yet */
atttce_resolved(t), /* resolved to a type, irrespective of region */
atttce_has_regions /* has regions; cannot be cached */
}
type ctxt =
@{interner: hashmap<intern_key, t_box>,
mutable next_id: uint,
@ -177,7 +185,7 @@ type ctxt =
short_names_cache: hashmap<t, @str>,
needs_drop_cache: hashmap<t, bool>,
kind_cache: hashmap<t, kind>,
ast_ty_to_ty_cache: hashmap<@ast::ty, option<t>>,
ast_ty_to_ty_cache: hashmap<@ast::ty, ast_ty_to_ty_cache_entry>,
enum_var_cache: hashmap<def_id, @[variant_info]>,
iface_method_cache: hashmap<def_id, @[method]>,
ty_param_bounds: hashmap<ast::node_id, param_bounds>,

View File

@ -270,16 +270,16 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
}
}
alt tcx.ast_ty_to_ty_cache.find(ast_ty) {
some(some(ty)) { ret ty; }
some(none) {
some(ty::atttce_resolved(ty)) { ret ty; }
some(ty::atttce_unresolved) {
tcx.sess.span_fatal(ast_ty.span, "illegal recursive type. \
insert a enum in the cycle, \
if this is desired)");
}
none { }
} /* go on */
some(ty::atttce_has_regions) | none { /* go on */ }
}
tcx.ast_ty_to_ty_cache.insert(ast_ty, none::<ty::t>);
tcx.ast_ty_to_ty_cache.insert(ast_ty, ty::atttce_unresolved);
fn ast_mt_to_mt(tcx: ty::ctxt, mode: mode, mt: ast::mt) -> ty::mt {
ret {ty: ast_ty_to_ty(tcx, mode, mt.ty), mutbl: mt.mutbl};
}
@ -425,7 +425,13 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
"found `ty_mac` in unexpected place");
}
};
tcx.ast_ty_to_ty_cache.insert(ast_ty, some(typ));
if ty::type_has_rptrs(typ) {
tcx.ast_ty_to_ty_cache.insert(ast_ty, ty::atttce_has_regions);
} else {
tcx.ast_ty_to_ty_cache.insert(ast_ty, ty::atttce_resolved(typ));
}
ret typ;
}