diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-04-24 18:23:54 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-04-25 15:49:27 -0700 |
| commit | 3a3a7fc426dafa8d38341fac6ab92cd49d3de526 (patch) | |
| tree | 4f6b0c21a2dab5b0c7fa4d9772275cadfa9cc153 | |
| parent | df0ef528b9ed22cad874f780b988aa8f32aac376 (diff) | |
| download | rust-3a3a7fc426dafa8d38341fac6ab92cd49d3de526.tar.gz rust-3a3a7fc426dafa8d38341fac6ab92cd49d3de526.zip | |
rustc: Cache normalized types
| -rw-r--r-- | src/rustc/middle/ty.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index d78f2cd359d..5e60baffa67 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -227,7 +227,8 @@ type ctxt = iface_method_cache: hashmap<def_id, @[method]>, ty_param_bounds: hashmap<ast::node_id, param_bounds>, inferred_modes: hashmap<ast::node_id, ast::mode>, - borrowings: hashmap<ast::node_id, ()>}; + borrowings: hashmap<ast::node_id, ()>, + normalized_cache: hashmap<t, t>}; type t_box = @{struct: sty, id: uint, @@ -461,7 +462,8 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map, iface_method_cache: new_def_hash(), ty_param_bounds: map::int_hash(), inferred_modes: map::int_hash(), - borrowings: map::int_hash()} + borrowings: map::int_hash(), + normalized_cache: new_ty_hash()} } @@ -2680,6 +2682,11 @@ fn ty_params_to_tys(tcx: ty::ctxt, tps: [ast::ty_param]) -> [t] { Returns an equivalent type with all the typedefs and self regions removed. "] fn normalize_ty(cx: ctxt, t: t) -> t { + alt cx.normalized_cache.find(t) { + some(t) { ret t; } + none { } + } + let t = alt get(t).struct { ty_enum(did, r) { alt r.self_r { @@ -2698,7 +2705,9 @@ fn normalize_ty(cx: ctxt, t: t) -> t { let t = mk_t(cx, mach_sty(cx.sess.targ_cfg, t)); let sty = fold_sty(get(t).struct) {|t| normalize_ty(cx, t) }; - mk_t(cx, sty) + let t_norm = mk_t(cx, sty); + cx.normalized_cache.insert(t, t_norm); + ret t_norm; } // Local Variables: |
