Skip to content

Commit

Permalink
librustc: De-@mut the inherent implementations list
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Dec 26, 2013
1 parent ed819c9 commit fecef74
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
let inherent_impls = ecx.tcx.inherent_impls.borrow();
match inherent_impls.get().find(&exp.def_id) {
Some(implementations) => {
for &base_impl in implementations.iter() {
let implementations = implementations.borrow();
for &base_impl in implementations.get().iter() {
for &m in base_impl.methods.iter() {
if m.explicit_self == ast::sty_static {
encode_reexported_static_method(ecx, ebml_w, exp,
Expand Down Expand Up @@ -884,7 +885,8 @@ fn encode_inherent_implementations(ecx: &EncodeContext,
match inherent_impls.get().find(&def_id) {
None => {}
Some(&implementations) => {
for implementation in implementations.iter() {
let implementations = implementations.borrow();
for implementation in implementations.get().iter() {
ebml_w.start_tag(tag_items_data_item_inherent_impl);
encode_def_id(ebml_w, implementation.did);
ebml_w.end_tag();
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ impl DeadVisitor {
match inherent_impls.get().find(&def_id) {
None => (),
Some(ref impl_list) => {
for impl_ in impl_list.iter() {
let impl_list = impl_list.borrow();
for impl_ in impl_list.get().iter() {
for method in impl_.methods.iter() {
if self.live_symbols.contains(&method.def_id.node) {
return true;
Expand Down
10 changes: 7 additions & 3 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ struct ctxt_ {
// Maps a def_id of a type to a list of its inherent impls.
// Contains implementations of methods that are inherent to a type.
// Methods in these implementations don't need to be exported.
inherent_impls: RefCell<HashMap<ast::DefId, @mut ~[@Impl]>>,
inherent_impls: RefCell<HashMap<ast::DefId, @RefCell<~[@Impl]>>>,

// Maps a def_id of an impl to an Impl structure.
// Note that this contains all of the impls that we know about,
Expand Down Expand Up @@ -4561,14 +4561,18 @@ pub fn populate_implementations_for_type_if_necessary(tcx: ctxt,
let mut inherent_impls = tcx.inherent_impls.borrow_mut();
match inherent_impls.get().find(&type_id) {
None => {
implementation_list = @mut ~[];
implementation_list = @RefCell::new(~[]);
inherent_impls.get().insert(type_id, implementation_list);
}
Some(&existing_implementation_list) => {
implementation_list = existing_implementation_list;
}
}
implementation_list.push(implementation);
{
let mut implementation_list =
implementation_list.borrow_mut();
implementation_list.get().push(implementation);
}
}

// Store the implementation info.
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/typeck/check/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ impl<'a> LookupContext<'a> {
let inherent_impls = self.tcx().inherent_impls.borrow();
let opt_impl_infos = inherent_impls.get().find(&did);
for impl_infos in opt_impl_infos.iter() {
for impl_info in impl_infos.iter() {
let impl_infos = impl_infos.borrow();
for impl_info in impl_infos.get().iter() {
let mut inherent_candidates = self.inherent_candidates
.borrow_mut();
self.push_candidates_from_impl(inherent_candidates.get(),
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/typeck/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use syntax::codemap::Span;
use syntax::opt_vec;
use syntax::visit;

use std::cell::RefCell;
use std::hashmap::HashSet;
use std::result::Ok;
use std::vec;
Expand Down Expand Up @@ -391,15 +392,16 @@ impl CoherenceChecker {
let mut inherent_impls = tcx.inherent_impls.borrow_mut();
match inherent_impls.get().find(&base_def_id) {
None => {
implementation_list = @mut ~[];
implementation_list = @RefCell::new(~[]);
inherent_impls.get().insert(base_def_id, implementation_list);
}
Some(&existing_implementation_list) => {
implementation_list = existing_implementation_list;
}
}

implementation_list.push(implementation);
let mut implementation_list = implementation_list.borrow_mut();
implementation_list.get().push(implementation);
}

pub fn add_trait_impl(&self,
Expand Down

0 comments on commit fecef74

Please sign in to comment.