Skip to content

Commit 8c194a0

Browse files
committed
librustc: De-@mut CrateContext::module_data
1 parent 1185fcc commit 8c194a0

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,14 +2917,19 @@ pub fn decl_gc_metadata(ccx: &mut CrateContext, llmod_id: &str) {
29172917
unsafe {
29182918
llvm::LLVMSetGlobalConstant(gc_metadata, True);
29192919
lib::llvm::SetLinkage(gc_metadata, lib::llvm::ExternalLinkage);
2920-
ccx.module_data.insert(~"_gc_module_metadata", gc_metadata);
2920+
2921+
let mut module_data = ccx.module_data.borrow_mut();
2922+
module_data.get().insert(~"_gc_module_metadata", gc_metadata);
29212923
}
29222924
}
29232925

29242926
pub fn create_module_map(ccx: &mut CrateContext) -> (ValueRef, uint) {
29252927
let str_slice_type = Type::struct_([Type::i8p(), ccx.int_type], false);
29262928
let elttype = Type::struct_([str_slice_type, ccx.int_type], false);
2927-
let maptype = Type::array(&elttype, ccx.module_data.len() as u64);
2929+
let maptype = {
2930+
let module_data = ccx.module_data.borrow();
2931+
Type::array(&elttype, module_data.get().len() as u64)
2932+
};
29282933
let map = "_rust_mod_map".with_c_str(|buf| {
29292934
unsafe {
29302935
llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf)
@@ -2936,16 +2941,22 @@ pub fn create_module_map(ccx: &mut CrateContext) -> (ValueRef, uint) {
29362941
// This is not ideal, but the borrow checker doesn't
29372942
// like the multiple borrows. At least, it doesn't
29382943
// like them on the current snapshot. (2013-06-14)
2939-
let mut keys = ~[];
2940-
for (k, _) in ccx.module_data.iter() {
2941-
keys.push(k.to_managed());
2942-
}
2944+
let keys = {
2945+
let mut keys = ~[];
2946+
let module_data = ccx.module_data.borrow();
2947+
for (k, _) in module_data.get().iter() {
2948+
keys.push(k.to_managed());
2949+
}
2950+
keys
2951+
};
29432952

29442953
for key in keys.iter() {
2945-
let val = *ccx.module_data.find_equiv(key).unwrap();
2954+
let llestrval = C_estr_slice(ccx, *key);
2955+
let module_data = ccx.module_data.borrow();
2956+
let val = *module_data.get().find_equiv(key).unwrap();
29462957
let v_ptr = p2i(ccx, val);
29472958
let elt = C_struct([
2948-
C_estr_slice(ccx, *key),
2959+
llestrval,
29492960
v_ptr
29502961
], false);
29512962
elts.push(elt);

src/librustc/middle/trans/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct CrateContext {
9191

9292
impl_method_cache: RefCell<HashMap<(ast::DefId, ast::Name), ast::DefId>>,
9393

94-
module_data: HashMap<~str, ValueRef>,
94+
module_data: RefCell<HashMap<~str, ValueRef>>,
9595
lltypes: HashMap<ty::t, Type>,
9696
llsizingtypes: HashMap<ty::t, Type>,
9797
adt_reprs: HashMap<ty::t, @adt::Repr>,
@@ -202,7 +202,7 @@ impl CrateContext {
202202
const_values: RefCell::new(HashMap::new()),
203203
extern_const_values: RefCell::new(HashMap::new()),
204204
impl_method_cache: RefCell::new(HashMap::new()),
205-
module_data: HashMap::new(),
205+
module_data: RefCell::new(HashMap::new()),
206206
lltypes: HashMap::new(),
207207
llsizingtypes: HashMap::new(),
208208
adt_reprs: HashMap::new(),

src/librustc/middle/trans/expr.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,8 +1813,15 @@ pub fn trans_log_level(bcx: @Block) -> DatumBlock {
18131813
(modpath, modname)
18141814
};
18151815

1816-
let global = if ccx.module_data.contains_key(&modname) {
1817-
ccx.module_data.get_copy(&modname)
1816+
let module_data_exists;
1817+
{
1818+
let module_data = ccx.module_data.borrow();
1819+
module_data_exists = module_data.get().contains_key(&modname);
1820+
}
1821+
1822+
let global = if module_data_exists {
1823+
let mut module_data = ccx.module_data.borrow_mut();
1824+
module_data.get().get_copy(&modname)
18181825
} else {
18191826
let s = link::mangle_internal_name_by_path_and_seq(
18201827
ccx, modpath, "loglevel");
@@ -1827,8 +1834,11 @@ pub fn trans_log_level(bcx: @Block) -> DatumBlock {
18271834
llvm::LLVMSetInitializer(global, C_null(Type::i32()));
18281835
lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
18291836
}
1830-
ccx.module_data.insert(modname, global);
1831-
global
1837+
{
1838+
let mut module_data = ccx.module_data.borrow_mut();
1839+
module_data.get().insert(modname, global);
1840+
global
1841+
}
18321842
};
18331843

18341844
return immediate_rvalue_bcx(bcx, Load(bcx, global), ty::mk_u32());

0 commit comments

Comments
 (0)