Skip to content

Commit 07d7f82

Browse files
committed
Fix tag_var_cache to cache crate-external tags
And to not return a bogus mutable box.
1 parent 44f921c commit 07d7f82

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed

src/comp/middle/ty.rs

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ type mt = {ty: t, mut: ast::mutability};
207207
// the types of AST nodes.
208208
type creader_cache = hashmap<{cnum: int, pos: uint, len: uint}, ty::t>;
209209

210-
type tag_var_cache =
211-
@smallintmap::smallintmap<@mutable [variant_info]>;
212-
213210
type ctxt =
214211
@{ts: @type_store,
215212
sess: session::session,
@@ -223,7 +220,7 @@ type ctxt =
223220
needs_drop_cache: hashmap<t, bool>,
224221
kind_cache: hashmap<t, ast::kind>,
225222
ast_ty_to_ty_cache: hashmap<@ast::ty, option::t<t>>,
226-
tag_var_cache: tag_var_cache};
223+
tag_var_cache: hashmap<ast::def_id, @[variant_info]>};
227224

228225
type ty_ctxt = ctxt;
229226

@@ -404,7 +401,6 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
404401
freevars: freevars::freevar_map) -> ctxt {
405402
let ntt: node_type_table =
406403
@smallintmap::mk::<ty::ty_param_substs_opt_and_ty>();
407-
let tcache = new_def_hash::<ty::ty_param_kinds_and_ty>();
408404
fn eq_raw_ty(&&a: @raw_t, &&b: @raw_t) -> bool {
409405
ret a.hash == b.hash && a.struct == b.struct;
410406
}
@@ -416,14 +412,14 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
416412
node_types: ntt,
417413
items: amap,
418414
freevars: freevars,
419-
tcache: tcache,
415+
tcache: new_def_hash(),
420416
rcache: mk_rcache(),
421417
short_names_cache: new_ty_hash(),
422418
needs_drop_cache: new_ty_hash(),
423419
kind_cache: new_ty_hash(),
424420
ast_ty_to_ty_cache:
425421
map::mk_hashmap(ast_util::hash_ty, ast_util::eq_ty),
426-
tag_var_cache: @smallintmap::mk()};
422+
tag_var_cache: new_def_hash()};
427423
populate_type_store(cx);
428424
ret cx;
429425
}
@@ -2627,45 +2623,34 @@ fn def_has_ty_params(def: ast::def) -> bool {
26272623
// Tag information
26282624
type variant_info = @{args: [ty::t], ctor_ty: ty::t, id: ast::def_id};
26292625

2630-
fn tag_variants(cx: ctxt, id: ast::def_id) -> @mutable [variant_info] {
2631-
if ast::local_crate != id.crate {
2632-
ret @mutable csearch::get_tag_variants(cx, id);
2633-
}
2634-
assert (id.node >= 0);
2635-
alt smallintmap::find(*cx.tag_var_cache, id.node as uint) {
2636-
option::some(variants) { ret variants; }
2626+
fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
2627+
alt cx.tag_var_cache.find(id) {
2628+
some(variants) { ret variants; }
26372629
_ { /* fallthrough */ }
26382630
}
2639-
let item =
2640-
alt cx.items.find(id.node) {
2641-
some(i) { i }
2642-
none. { cx.sess.bug("expected to find cached node_item") }
2643-
};
2644-
alt item {
2645-
ast_map::node_item(item) {
2646-
alt item.node {
2647-
ast::item_tag(variants, _) {
2648-
let result: @mutable [variant_info] = @mutable [];
2649-
for variant: ast::variant in variants {
2650-
let ctor_ty = node_id_to_monotype(cx, variant.node.id);
2651-
let arg_tys: [t] = [];
2652-
if vec::len(variant.node.args) > 0u {
2653-
for a: arg in ty_fn_args(cx, ctor_ty) {
2654-
arg_tys += [a.ty];
2655-
}
2656-
}
2657-
let did = variant.node.id;
2658-
*result +=
2659-
[@{args: arg_tys,
2660-
ctor_ty: ctor_ty,
2661-
id: ast_util::local_def(did)}];
2631+
let result = if ast::local_crate != id.crate {
2632+
@csearch::get_tag_variants(cx, id)
2633+
} else {
2634+
alt cx.items.get(id.node) {
2635+
ast_map::node_item(item) {
2636+
alt item.node {
2637+
ast::item_tag(variants, _) {
2638+
@vec::map(variants, {|variant|
2639+
let ctor_ty = node_id_to_monotype(cx, variant.node.id);
2640+
let arg_tys = if vec::len(variant.node.args) > 0u {
2641+
vec::map(ty_fn_args(cx, ctor_ty), {|a| a.ty})
2642+
} else { [] };
2643+
@{args: arg_tys,
2644+
ctor_ty: ctor_ty,
2645+
id: ast_util::local_def(variant.node.id)}
2646+
})
2647+
}
26622648
}
2663-
smallintmap::insert(*cx.tag_var_cache, id.node as uint, result);
2664-
ret result;
26652649
}
26662650
}
2667-
}
2668-
}
2651+
};
2652+
cx.tag_var_cache.insert(id, result);
2653+
result
26692654
}
26702655

26712656

0 commit comments

Comments
 (0)