提交 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,
fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
name: &str, did: ast::DefId) -> ValueRef {
match ccx.externs.find_equiv(&name) {
{
let externs = ccx.externs.borrow();
match externs.get().find_equiv(&name) {
Some(n) => return *n,
None => ()
}
}
let f = decl_rust_fn(ccx, inputs, output, name);
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)
});
ccx.externs.insert(name.to_owned(), f);
let mut externs = ccx.externs.borrow_mut();
externs.get().insert(name.to_owned(), f);
f
}
......@@ -559,12 +565,16 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
None,
ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty);
get_extern_fn(&mut ccx.externs,
{
let mut externs = ccx.externs.borrow_mut();
get_extern_fn(externs.get(),
ccx.llmod,
name,
lib::llvm::CCallConv,
llty)
}
}
}
// Structural comparison: a rather involved form of glue.
......@@ -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 cconv = c.unwrap_or(lib::llvm::CCallConv);
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) ->
}
_ => {
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 {
metadata_llmod: ModuleRef,
td: TargetData,
tn: TypeNames,
externs: ExternMap,
externs: RefCell<ExternMap>,
intrinsics: HashMap<&'static str, ValueRef>,
item_vals: RefCell<HashMap<ast::NodeId, ValueRef>>,
exp_map2: resolve::ExportMap2,
......@@ -181,7 +181,7 @@ pub fn new(sess: session::Session,
metadata_llmod: metadata_llmod,
td: td,
tn: tn,
externs: HashMap::new(),
externs: RefCell::new(HashMap::new()),
intrinsics: intrinsics,
item_vals: RefCell::new(HashMap::new()),
exp_map2: emap2,
......
......@@ -146,8 +146,16 @@ pub fn register_foreign_item_fn(ccx: @mut CrateContext,
// Create the LLVM value for the C extern fn
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);
return llfn;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册