Skip to content

Commit 7f5e57a

Browse files
committed
librustc: De-@mut supertraits in the type context
1 parent 84e4503 commit 7f5e57a

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/librustc/middle/ty.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ struct ctxt_ {
317317
lang_items: middle::lang_items::LanguageItems,
318318
// A mapping of fake provided method def_ids to the default implementation
319319
provided_method_sources: RefCell<HashMap<ast::DefId, ast::DefId>>,
320-
supertraits: @mut HashMap<ast::DefId, @~[@TraitRef]>,
320+
supertraits: RefCell<HashMap<ast::DefId, @~[@TraitRef]>>,
321321

322322
// Maps from def-id of a type or region parameter to its
323323
// (inferred) variance.
@@ -1006,7 +1006,7 @@ pub fn mk_ctxt(s: session::Session,
10061006
normalized_cache: new_ty_hash(),
10071007
lang_items: lang_items,
10081008
provided_method_sources: RefCell::new(HashMap::new()),
1009-
supertraits: @mut HashMap::new(),
1009+
supertraits: RefCell::new(HashMap::new()),
10101010
destructor_for_type: @mut HashMap::new(),
10111011
destructors: @mut HashSet::new(),
10121012
trait_impls: @mut HashMap::new(),
@@ -3552,13 +3552,14 @@ pub fn provided_trait_methods(cx: ctxt, id: ast::DefId) -> ~[@Method] {
35523552
}
35533553
}
35543554

3555-
pub fn trait_supertraits(cx: ctxt,
3556-
id: ast::DefId) -> @~[@TraitRef]
3557-
{
3555+
pub fn trait_supertraits(cx: ctxt, id: ast::DefId) -> @~[@TraitRef] {
35583556
// Check the cache.
3559-
match cx.supertraits.find(&id) {
3560-
Some(&trait_refs) => { return trait_refs; }
3561-
None => {} // Continue.
3557+
{
3558+
let supertraits = cx.supertraits.borrow();
3559+
match supertraits.get().find(&id) {
3560+
Some(&trait_refs) => { return trait_refs; }
3561+
None => {} // Continue.
3562+
}
35623563
}
35633564

35643565
// Not in the cache. It had better be in the metadata, which means it
@@ -3568,7 +3569,8 @@ pub fn trait_supertraits(cx: ctxt,
35683569
// Get the supertraits out of the metadata and create the
35693570
// TraitRef for each.
35703571
let result = @csearch::get_supertraits(cx, id);
3571-
cx.supertraits.insert(id, result);
3572+
let mut supertraits = cx.supertraits.borrow_mut();
3573+
supertraits.get().insert(id, result);
35723574
return result;
35733575
}
35743576

src/librustc/middle/typeck/collect.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
401401

402402
// Called only the first time trait_def_of_item is called.
403403
// Supertraits are ensured at the same time.
404-
assert!(!tcx.supertraits.contains_key(&local_def(id)));
404+
{
405+
let supertraits = tcx.supertraits.borrow();
406+
assert!(!supertraits.get().contains_key(&local_def(id)));
407+
}
405408

406409
let self_ty = ty::mk_self(ccx.tcx, local_def(id));
407410
let mut ty_trait_refs: ~[@ty::TraitRef] = ~[];
@@ -425,7 +428,9 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
425428
}
426429
}
427430
}
428-
tcx.supertraits.insert(local_def(id), @ty_trait_refs);
431+
432+
let mut supertraits = tcx.supertraits.borrow_mut();
433+
supertraits.get().insert(local_def(id), @ty_trait_refs);
429434
bounds
430435
}
431436

0 commit comments

Comments
 (0)