提交 1e654f5f 编写于 作者: P Patrick Walton

librustc: De-`@mut` `CrateContext::externs`

上级 519db347
...@@ -205,15 +205,21 @@ pub fn get_extern_fn(externs: &mut ExternMap, llmod: ModuleRef, name: &str, ...@@ -205,15 +205,21 @@ pub fn get_extern_fn(externs: &mut ExternMap, llmod: ModuleRef, name: &str,
fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t, fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
name: &str, did: ast::DefId) -> ValueRef { name: &str, did: ast::DefId) -> ValueRef {
match ccx.externs.find_equiv(&name) { {
Some(n) => return *n, let externs = ccx.externs.borrow();
None => () match externs.get().find_equiv(&name) {
Some(n) => return *n,
None => ()
}
} }
let f = decl_rust_fn(ccx, inputs, output, name); let f = decl_rust_fn(ccx, inputs, output, name);
csearch::get_item_attrs(ccx.tcx.cstore, did, |meta_items| { csearch::get_item_attrs(ccx.tcx.cstore, did, |meta_items| {
set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x)).to_owned_vec(), f) set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x)).to_owned_vec(), f)
}); });
ccx.externs.insert(name.to_owned(), f);
let mut externs = ccx.externs.borrow_mut();
externs.get().insert(name.to_owned(), f);
f f
} }
...@@ -559,11 +565,15 @@ pub fn get_res_dtor(ccx: @mut CrateContext, ...@@ -559,11 +565,15 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
None, None,
ty::lookup_item_type(tcx, parent_id).ty); ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty); let llty = type_of_dtor(ccx, class_ty);
get_extern_fn(&mut ccx.externs,
ccx.llmod, {
name, let mut externs = ccx.externs.borrow_mut();
lib::llvm::CCallConv, get_extern_fn(externs.get(),
llty) ccx.llmod,
name,
lib::llvm::CCallConv,
llty)
}
} }
} }
...@@ -865,7 +875,8 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) -> ...@@ -865,7 +875,8 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) ->
let c = foreign::llvm_calling_convention(ccx, fn_ty.abis); let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
let cconv = c.unwrap_or(lib::llvm::CCallConv); let cconv = c.unwrap_or(lib::llvm::CCallConv);
let llty = type_of_fn_from_ty(ccx, t); let llty = type_of_fn_from_ty(ccx, t);
get_extern_fn(&mut ccx.externs, ccx.llmod, name, cconv, llty) let mut externs = ccx.externs.borrow_mut();
get_extern_fn(externs.get(), ccx.llmod, name, cconv, llty)
} }
} }
} }
...@@ -874,7 +885,8 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) -> ...@@ -874,7 +885,8 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) ->
} }
_ => { _ => {
let llty = type_of(ccx, t); let llty = type_of(ccx, t);
get_extern_const(&mut ccx.externs, ccx.llmod, name, llty) let mut externs = ccx.externs.borrow_mut();
get_extern_const(externs.get(), ccx.llmod, name, llty)
} }
} }
} }
......
...@@ -45,7 +45,7 @@ pub struct CrateContext { ...@@ -45,7 +45,7 @@ pub struct CrateContext {
metadata_llmod: ModuleRef, metadata_llmod: ModuleRef,
td: TargetData, td: TargetData,
tn: TypeNames, tn: TypeNames,
externs: ExternMap, externs: RefCell<ExternMap>,
intrinsics: HashMap<&'static str, ValueRef>, intrinsics: HashMap<&'static str, ValueRef>,
item_vals: RefCell<HashMap<ast::NodeId, ValueRef>>, item_vals: RefCell<HashMap<ast::NodeId, ValueRef>>,
exp_map2: resolve::ExportMap2, exp_map2: resolve::ExportMap2,
...@@ -181,7 +181,7 @@ pub fn new(sess: session::Session, ...@@ -181,7 +181,7 @@ pub fn new(sess: session::Session,
metadata_llmod: metadata_llmod, metadata_llmod: metadata_llmod,
td: td, td: td,
tn: tn, tn: tn,
externs: HashMap::new(), externs: RefCell::new(HashMap::new()),
intrinsics: intrinsics, intrinsics: intrinsics,
item_vals: RefCell::new(HashMap::new()), item_vals: RefCell::new(HashMap::new()),
exp_map2: emap2, exp_map2: emap2,
......
...@@ -146,8 +146,16 @@ pub fn register_foreign_item_fn(ccx: @mut CrateContext, ...@@ -146,8 +146,16 @@ pub fn register_foreign_item_fn(ccx: @mut CrateContext,
// Create the LLVM value for the C extern fn // Create the LLVM value for the C extern fn
let llfn_ty = lltype_for_fn_from_foreign_types(&tys); let llfn_ty = lltype_for_fn_from_foreign_types(&tys);
let llfn = base::get_extern_fn(&mut ccx.externs, ccx.llmod,
lname, cc, llfn_ty); let llfn;
{
let mut externs = ccx.externs.borrow_mut();
llfn = base::get_extern_fn(externs.get(),
ccx.llmod,
lname,
cc,
llfn_ty);
};
add_argument_attributes(&tys, llfn); add_argument_attributes(&tys, llfn);
return llfn; return llfn;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册