提交 d16cca1f 编写于 作者: P Patrick Walton

librustc: De-`@mut` `const_values`.

上级 28943e96
......@@ -2233,7 +2233,9 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
"cannot have static_assert on a mutable \
static");
}
let v = ccx.const_values.get_copy(&item.id);
let const_values = ccx.const_values.borrow();
let v = const_values.get().get_copy(&item.id);
unsafe {
if !(llvm::LLVMConstIntGetZExtValue(v) != 0) {
ccx.sess.span_fatal(expr.span, "static assertion failed");
......@@ -2489,7 +2491,11 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
// We need the translated value here, because for enums the
// LLVM type is not fully determined by the Rust type.
let (v, inlineable) = consts::const_expr(ccx, expr);
ccx.const_values.insert(id, v);
{
let mut const_values = ccx.const_values
.borrow_mut();
const_values.get().insert(id, v);
}
let mut inlineable = inlineable;
unsafe {
......
......@@ -157,7 +157,10 @@ fn const_deref(cx: &mut CrateContext, v: ValueRef, t: ty::t, explicit: bool)
pub fn get_const_val(cx: @mut CrateContext,
mut def_id: ast::DefId) -> (ValueRef, bool) {
let contains_key = cx.const_values.contains_key(&def_id.node);
let contains_key = {
let const_values = cx.const_values.borrow();
const_values.get().contains_key(&def_id.node)
};
if !ast_util::is_local(def_id) || !contains_key {
if !ast_util::is_local(def_id) {
def_id = inline::maybe_instantiate_inline(cx, def_id);
......@@ -171,7 +174,9 @@ pub fn get_const_val(cx: @mut CrateContext,
_ => cx.tcx.sess.bug("expected a const to be an item")
}
}
(cx.const_values.get_copy(&def_id.node),
let const_values = cx.const_values.borrow();
(const_values.get().get_copy(&def_id.node),
!cx.non_inlineable_statics.contains(&def_id.node))
}
......@@ -642,7 +647,8 @@ pub fn trans_const(ccx: @mut CrateContext, m: ast::Mutability, id: ast::NodeId)
let g = base::get_item_val(ccx, id);
// At this point, get_item_val has already translated the
// constant's initializer to determine its LLVM type.
let v = ccx.const_values.get_copy(&id);
let const_values = ccx.const_values.borrow();
let v = const_values.get().get_copy(&id);
llvm::LLVMSetInitializer(g, v);
if m != ast::MutMutable {
llvm::LLVMSetGlobalConstant(g, True);
......
......@@ -84,7 +84,7 @@ pub struct CrateContext {
const_globals: RefCell<HashMap<int, ValueRef>>,
// Cache of emitted const values
const_values: HashMap<ast::NodeId, ValueRef>,
const_values: RefCell<HashMap<ast::NodeId, ValueRef>>,
// Cache of external const values
extern_const_values: HashMap<ast::DefId, ValueRef>,
......@@ -199,7 +199,7 @@ pub fn new(sess: session::Session,
vtables: RefCell::new(HashMap::new()),
const_cstr_cache: RefCell::new(HashMap::new()),
const_globals: RefCell::new(HashMap::new()),
const_values: HashMap::new(),
const_values: RefCell::new(HashMap::new()),
extern_const_values: HashMap::new(),
impl_method_cache: HashMap::new(),
module_data: HashMap::new(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册