Skip to content

Commit 3e9bcea

Browse files
committed
librustc: Remove ty_param_defs from the type context
1 parent d803a0f commit 3e9bcea

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

src/librustc/middle/astencode.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
963963
}
964964

965965
{
966-
let r = tcx.ty_param_defs.find(&id);
967-
for &type_param_def in r.iter() {
966+
let r = {
967+
let ty_param_defs = tcx.ty_param_defs.borrow();
968+
ty_param_defs.get().find(&id).map(|def| *def)
969+
};
970+
for type_param_def in r.iter() {
968971
ebml_w.tag(c::tag_table_param_defs, |ebml_w| {
969972
ebml_w.id(id);
970973
ebml_w.tag(c::tag_table_val, |ebml_w| {
@@ -1247,7 +1250,10 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
12471250
}
12481251
c::tag_table_param_defs => {
12491252
let bounds = val_dsr.read_type_param_def(xcx);
1250-
dcx.tcx.ty_param_defs.insert(id, bounds);
1253+
let mut ty_param_defs = dcx.tcx
1254+
.ty_param_defs
1255+
.borrow_mut();
1256+
ty_param_defs.get().insert(id, bounds);
12511257
}
12521258
c::tag_table_method_map => {
12531259
dcx.maps.method_map.insert(

src/librustc/middle/ty.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ struct ctxt_ {
311311
tc_cache: RefCell<HashMap<uint, TypeContents>>,
312312
ast_ty_to_ty_cache: RefCell<HashMap<NodeId, ast_ty_to_ty_cache_entry>>,
313313
enum_var_cache: RefCell<HashMap<DefId, @~[@VariantInfo]>>,
314-
ty_param_defs: @mut HashMap<ast::NodeId, TypeParameterDef>,
314+
ty_param_defs: RefCell<HashMap<ast::NodeId, TypeParameterDef>>,
315315
adjustments: @mut HashMap<ast::NodeId, @AutoAdjustment>,
316316
normalized_cache: @mut HashMap<t, t>,
317317
lang_items: middle::lang_items::LanguageItems,
@@ -1001,7 +1001,7 @@ pub fn mk_ctxt(s: session::Session,
10011001
trait_method_def_ids: RefCell::new(HashMap::new()),
10021002
trait_methods_cache: RefCell::new(HashMap::new()),
10031003
impl_trait_cache: RefCell::new(HashMap::new()),
1004-
ty_param_defs: @mut HashMap::new(),
1004+
ty_param_defs: RefCell::new(HashMap::new()),
10051005
adjustments: @mut HashMap::new(),
10061006
normalized_cache: new_ty_hash(),
10071007
lang_items: lang_items,
@@ -2123,7 +2123,8 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
21232123
// def-id.
21242124
assert_eq!(p.def_id.crate, ast::LOCAL_CRATE);
21252125

2126-
let tp_def = cx.ty_param_defs.get(&p.def_id.node);
2126+
let ty_param_defs = cx.ty_param_defs.borrow();
2127+
let tp_def = ty_param_defs.get().get(&p.def_id.node);
21272128
kind_bounds_to_contents(cx,
21282129
tp_def.bounds.builtin_bounds,
21292130
tp_def.bounds.trait_bounds)
@@ -2568,7 +2569,8 @@ pub fn type_is_sized(cx: ctxt, ty: ty::t) -> bool {
25682569
match get(ty).sty {
25692570
// FIXME(#6308) add trait, vec, str, etc here.
25702571
ty_param(p) => {
2571-
let param_def = cx.ty_param_defs.get(&p.def_id.node);
2572+
let ty_param_defs = cx.ty_param_defs.borrow();
2573+
let param_def = ty_param_defs.get().get(&p.def_id.node);
25722574
if param_def.bounds.builtin_bounds.contains_elem(BoundSized) {
25732575
return true;
25742576
}

src/librustc/middle/typeck/collect.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,12 @@ pub fn ty_generics(ccx: &CrateCtxt,
892892
def_id: local_def(l.id) }
893893
}).collect(),
894894
type_param_defs: @generics.ty_params.mapi_to_vec(|offset, param| {
895-
match ccx.tcx.ty_param_defs.find(&param.id) {
896-
Some(&def) => def,
895+
let existing_def_opt = {
896+
let ty_param_defs = ccx.tcx.ty_param_defs.borrow();
897+
ty_param_defs.get().find(&param.id).map(|def| *def)
898+
};
899+
match existing_def_opt {
900+
Some(def) => def,
897901
None => {
898902
let param_ty = ty::param_ty {idx: base_index + offset,
899903
def_id: local_def(param.id)};
@@ -904,7 +908,11 @@ pub fn ty_generics(ccx: &CrateCtxt,
904908
bounds: bounds
905909
};
906910
debug!("def for param: {}", def.repr(ccx.tcx));
907-
ccx.tcx.ty_param_defs.insert(param.id, def);
911+
912+
let mut ty_param_defs = ccx.tcx
913+
.ty_param_defs
914+
.borrow_mut();
915+
ty_param_defs.get().insert(param.id, def);
908916
def
909917
}
910918
}

src/librustc/util/ppaux.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,10 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
472472
ty_infer(infer_ty) => infer_ty.to_str(),
473473
ty_err => ~"[type error]",
474474
ty_param(param_ty {idx: id, def_id: did}) => {
475-
let param_def = cx.ty_param_defs.find(&did.node);
475+
let ty_param_defs = cx.ty_param_defs.borrow();
476+
let param_def = ty_param_defs.get().find(&did.node);
476477
let ident = match param_def {
477-
Some(def) => {
478-
cx.sess.str_of(def.ident).to_owned()
479-
}
478+
Some(def) => cx.sess.str_of(def.ident).to_owned(),
480479
None => {
481480
// This should not happen...
482481
format!("BUG[{:?}]", id)

0 commit comments

Comments
 (0)