Skip to content

Commit f15f938

Browse files
committed
librustc: De-@mut the type context's methods table
1 parent 386300d commit f15f938

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

src/librustc/middle/lint.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,14 @@ fn check_missing_doc_method(cx: &Context, m: &ast::method) {
11411141
crate: ast::LOCAL_CRATE,
11421142
node: m.id
11431143
};
1144-
match cx.tcx.methods.find(&did) {
1144+
1145+
let method_opt;
1146+
{
1147+
let methods = cx.tcx.methods.borrow();
1148+
method_opt = methods.get().find(&did).map(|method| *method);
1149+
}
1150+
1151+
match method_opt {
11451152
None => cx.tcx.sess.span_bug(m.span, "missing method descriptor?!"),
11461153
Some(md) => {
11471154
match md.container {

src/librustc/middle/privacy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ impl<'a> PrivacyVisitor<'a> {
340340
return Allowable;
341341
}
342342
debug!("privacy - is {:?} a public method", did);
343-
return match self.tcx.methods.find(&did) {
343+
344+
let methods = self.tcx.methods.borrow();
345+
return match methods.get().find(&did) {
344346
Some(meth) => {
345347
debug!("privacy - well at least it's a method: {:?}", meth);
346348
match meth.container {

src/librustc/middle/ty.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ struct ctxt_ {
287287
node_type_substs: RefCell<HashMap<NodeId, ~[t]>>,
288288

289289
// Maps from a method to the method "descriptor"
290-
methods: @mut HashMap<DefId, @Method>,
290+
methods: RefCell<HashMap<DefId, @Method>>,
291291

292292
// Maps from a trait def-id to a list of the def-ids of its methods
293293
trait_method_def_ids: @mut HashMap<DefId, @~[DefId]>,
@@ -998,7 +998,7 @@ pub fn mk_ctxt(s: session::Session,
998998
tc_cache: @mut HashMap::new(),
999999
ast_ty_to_ty_cache: @mut HashMap::new(),
10001000
enum_var_cache: @mut HashMap::new(),
1001-
methods: @mut HashMap::new(),
1001+
methods: RefCell::new(HashMap::new()),
10021002
trait_method_def_ids: @mut HashMap::new(),
10031003
trait_methods_cache: @mut HashMap::new(),
10041004
impl_trait_cache: @mut HashMap::new(),
@@ -3603,9 +3603,10 @@ pub fn trait_methods(cx: ctxt, trait_did: ast::DefId) -> @~[@Method] {
36033603
}
36043604

36053605
pub fn method(cx: ctxt, id: ast::DefId) -> @Method {
3606-
lookup_locally_or_in_crate_store(
3607-
"methods", id, cx.methods,
3608-
|| @csearch::get_method(cx, id))
3606+
let mut methods = cx.methods.borrow_mut();
3607+
lookup_locally_or_in_crate_store("methods", id, methods.get(), || {
3608+
@csearch::get_method(cx, id)
3609+
})
36093610
}
36103611

36113612
pub fn trait_method_def_ids(cx: ctxt, id: ast::DefId) -> @~[DefId] {
@@ -4577,7 +4578,12 @@ pub fn trait_of_method(tcx: ctxt, def_id: ast::DefId)
45774578
if def_id.crate != LOCAL_CRATE {
45784579
return csearch::get_trait_of_method(tcx.cstore, def_id, tcx);
45794580
}
4580-
match tcx.methods.find(&def_id) {
4581+
let method;
4582+
{
4583+
let methods = tcx.methods.borrow();
4584+
method = methods.get().find(&def_id).map(|method| *method);
4585+
}
4586+
match method {
45814587
Some(method) => {
45824588
match method.container {
45834589
TraitContainer(def_id) => Some(def_id),
@@ -4596,10 +4602,15 @@ pub fn trait_of_method(tcx: ctxt, def_id: ast::DefId)
45964602
/// Otherwise, return `None`.
45974603
pub fn trait_method_of_method(tcx: ctxt,
45984604
def_id: ast::DefId) -> Option<ast::DefId> {
4599-
let name = match tcx.methods.find(&def_id) {
4600-
Some(method) => method.ident.name,
4601-
None => return None
4602-
};
4605+
let method;
4606+
{
4607+
let methods = tcx.methods.borrow();
4608+
match methods.get().find(&def_id) {
4609+
Some(m) => method = *m,
4610+
None => return None,
4611+
}
4612+
}
4613+
let name = method.ident.name;
46034614
match trait_of_method(tcx, def_id) {
46044615
Some(trait_did) => {
46054616
let trait_methods = ty::trait_methods(tcx, trait_did);

src/librustc/middle/typeck/coherence.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ impl CoherenceChecker {
366366
debug!("new_polytype={}", new_polytype.repr(tcx));
367367

368368
tcx.tcache.insert(new_did, new_polytype);
369-
tcx.methods.insert(new_did, new_method_ty);
369+
370+
let mut methods = tcx.methods.borrow_mut();
371+
methods.get().insert(new_did, new_method_ty);
370372

371373
// Pair the new synthesized ID up with the
372374
// ID of the method.

src/librustc/middle/typeck/collect.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
213213
&trait_ty_generics);
214214
}
215215

216-
tcx.methods.insert(ty_method.def_id, ty_method);
216+
let mut methods = tcx.methods.borrow_mut();
217+
methods.get().insert(ty_method.def_id, ty_method);
217218
}
218219

219220
// Add an entry mapping
@@ -476,7 +477,9 @@ fn convert_methods(ccx: &CrateCtxt,
476477
ty: fty
477478
});
478479
write_ty_to_tcx(tcx, m.id, fty);
479-
tcx.methods.insert(mty.def_id, mty);
480+
481+
let mut methods = tcx.methods.borrow_mut();
482+
methods.get().insert(mty.def_id, mty);
480483
}
481484

482485
fn ty_of_method(ccx: &CrateCtxt,

0 commit comments

Comments
 (0)