Skip to content

Commit 3a3a7fc

Browse files
committed
rustc: Cache normalized types
1 parent df0ef52 commit 3a3a7fc

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/rustc/middle/ty.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ type ctxt =
227227
iface_method_cache: hashmap<def_id, @[method]>,
228228
ty_param_bounds: hashmap<ast::node_id, param_bounds>,
229229
inferred_modes: hashmap<ast::node_id, ast::mode>,
230-
borrowings: hashmap<ast::node_id, ()>};
230+
borrowings: hashmap<ast::node_id, ()>,
231+
normalized_cache: hashmap<t, t>};
231232

232233
type t_box = @{struct: sty,
233234
id: uint,
@@ -461,7 +462,8 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
461462
iface_method_cache: new_def_hash(),
462463
ty_param_bounds: map::int_hash(),
463464
inferred_modes: map::int_hash(),
464-
borrowings: map::int_hash()}
465+
borrowings: map::int_hash(),
466+
normalized_cache: new_ty_hash()}
465467
}
466468

467469

@@ -2680,6 +2682,11 @@ fn ty_params_to_tys(tcx: ty::ctxt, tps: [ast::ty_param]) -> [t] {
26802682
Returns an equivalent type with all the typedefs and self regions removed.
26812683
"]
26822684
fn normalize_ty(cx: ctxt, t: t) -> t {
2685+
alt cx.normalized_cache.find(t) {
2686+
some(t) { ret t; }
2687+
none { }
2688+
}
2689+
26832690
let t = alt get(t).struct {
26842691
ty_enum(did, r) {
26852692
alt r.self_r {
@@ -2698,7 +2705,9 @@ fn normalize_ty(cx: ctxt, t: t) -> t {
26982705
let t = mk_t(cx, mach_sty(cx.sess.targ_cfg, t));
26992706

27002707
let sty = fold_sty(get(t).struct) {|t| normalize_ty(cx, t) };
2701-
mk_t(cx, sty)
2708+
let t_norm = mk_t(cx, sty);
2709+
cx.normalized_cache.insert(t, t_norm);
2710+
ret t_norm;
27022711
}
27032712

27042713
// Local Variables:

0 commit comments

Comments
 (0)