From 0837a6ba04bd3cf8330901678dc38b6f2c953f20 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 13 Mar 2012 14:12:44 -0700 Subject: [PATCH] rustc: Don't cache ast_ty_to_ty results for types that have references --- src/rustc/middle/ty.rs | 10 +++++++++- src/rustc/middle/typeck.rs | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 7e0e94ef494f..ea5347a60745 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -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}; +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, mutable next_id: uint, @@ -177,7 +185,7 @@ type ctxt = short_names_cache: hashmap, needs_drop_cache: hashmap, kind_cache: hashmap, - ast_ty_to_ty_cache: hashmap<@ast::ty, option>, + ast_ty_to_ty_cache: hashmap<@ast::ty, ast_ty_to_ty_cache_entry>, enum_var_cache: hashmap, iface_method_cache: hashmap, ty_param_bounds: hashmap, diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index ba27c84a017b..337b22663856 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -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::); + 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; }