From 3e9bcea018d179bf361cbaee04e2db506ffac4a9 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 19 Dec 2013 17:15:13 -0800 Subject: [PATCH] librustc: Remove `ty_param_defs` from the type context --- src/librustc/middle/astencode.rs | 12 +++++++++--- src/librustc/middle/ty.rs | 10 ++++++---- src/librustc/middle/typeck/collect.rs | 14 +++++++++++--- src/librustc/util/ppaux.rs | 7 +++---- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 768d0e67893b..724499bd90fc 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -963,8 +963,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, } { - let r = tcx.ty_param_defs.find(&id); - for &type_param_def in r.iter() { + let r = { + let ty_param_defs = tcx.ty_param_defs.borrow(); + ty_param_defs.get().find(&id).map(|def| *def) + }; + for type_param_def in r.iter() { ebml_w.tag(c::tag_table_param_defs, |ebml_w| { ebml_w.id(id); ebml_w.tag(c::tag_table_val, |ebml_w| { @@ -1247,7 +1250,10 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, } c::tag_table_param_defs => { let bounds = val_dsr.read_type_param_def(xcx); - dcx.tcx.ty_param_defs.insert(id, bounds); + let mut ty_param_defs = dcx.tcx + .ty_param_defs + .borrow_mut(); + ty_param_defs.get().insert(id, bounds); } c::tag_table_method_map => { dcx.maps.method_map.insert( diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 6f4518ea95b5..92abefe31409 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -311,7 +311,7 @@ struct ctxt_ { tc_cache: RefCell>, ast_ty_to_ty_cache: RefCell>, enum_var_cache: RefCell>, - ty_param_defs: @mut HashMap, + ty_param_defs: RefCell>, adjustments: @mut HashMap, normalized_cache: @mut HashMap, lang_items: middle::lang_items::LanguageItems, @@ -1001,7 +1001,7 @@ pub fn mk_ctxt(s: session::Session, trait_method_def_ids: RefCell::new(HashMap::new()), trait_methods_cache: RefCell::new(HashMap::new()), impl_trait_cache: RefCell::new(HashMap::new()), - ty_param_defs: @mut HashMap::new(), + ty_param_defs: RefCell::new(HashMap::new()), adjustments: @mut HashMap::new(), normalized_cache: new_ty_hash(), lang_items: lang_items, @@ -2123,7 +2123,8 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { // def-id. assert_eq!(p.def_id.crate, ast::LOCAL_CRATE); - let tp_def = cx.ty_param_defs.get(&p.def_id.node); + let ty_param_defs = cx.ty_param_defs.borrow(); + let tp_def = ty_param_defs.get().get(&p.def_id.node); kind_bounds_to_contents(cx, tp_def.bounds.builtin_bounds, tp_def.bounds.trait_bounds) @@ -2568,7 +2569,8 @@ pub fn type_is_sized(cx: ctxt, ty: ty::t) -> bool { match get(ty).sty { // FIXME(#6308) add trait, vec, str, etc here. ty_param(p) => { - let param_def = cx.ty_param_defs.get(&p.def_id.node); + let ty_param_defs = cx.ty_param_defs.borrow(); + let param_def = ty_param_defs.get().get(&p.def_id.node); if param_def.bounds.builtin_bounds.contains_elem(BoundSized) { return true; } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 5bcaf41a870c..992b46af75a7 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -892,8 +892,12 @@ pub fn ty_generics(ccx: &CrateCtxt, def_id: local_def(l.id) } }).collect(), type_param_defs: @generics.ty_params.mapi_to_vec(|offset, param| { - match ccx.tcx.ty_param_defs.find(¶m.id) { - Some(&def) => def, + let existing_def_opt = { + let ty_param_defs = ccx.tcx.ty_param_defs.borrow(); + ty_param_defs.get().find(¶m.id).map(|def| *def) + }; + match existing_def_opt { + Some(def) => def, None => { let param_ty = ty::param_ty {idx: base_index + offset, def_id: local_def(param.id)}; @@ -904,7 +908,11 @@ pub fn ty_generics(ccx: &CrateCtxt, bounds: bounds }; debug!("def for param: {}", def.repr(ccx.tcx)); - ccx.tcx.ty_param_defs.insert(param.id, def); + + let mut ty_param_defs = ccx.tcx + .ty_param_defs + .borrow_mut(); + ty_param_defs.get().insert(param.id, def); def } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index ca17d8aaab43..ac88018a3c41 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -472,11 +472,10 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { ty_infer(infer_ty) => infer_ty.to_str(), ty_err => ~"[type error]", ty_param(param_ty {idx: id, def_id: did}) => { - let param_def = cx.ty_param_defs.find(&did.node); + let ty_param_defs = cx.ty_param_defs.borrow(); + let param_def = ty_param_defs.get().find(&did.node); let ident = match param_def { - Some(def) => { - cx.sess.str_of(def.ident).to_owned() - } + Some(def) => cx.sess.str_of(def.ident).to_owned(), None => { // This should not happen... format!("BUG[{:?}]", id)