`RefCell::get` can be a bit surprising, because it actually clones the wrapped value. This removes `RefCell::get` and replaces all the users with `RefCell::borrow()` when it can, and `RefCell::borrow().clone()` when it can't. It removes `RefCell::set` for consistency. This closes #13182.
It also fixes an infinite loop in a test when debugging is on.
use std::io::MemWriter;
use std::str;
use collections::HashMap;
-use syntax::abi::AbiSet;
+use syntax::abi;
use syntax::ast::*;
use syntax::ast;
use syntax::ast_map::{PathElem, PathElems};
nitem: &ForeignItem,
index: @RefCell<Vec<entry<i64>> >,
path: PathElems,
- abi: AbiSet) {
+ abi: abi::Abi) {
index.borrow_mut().push(entry {
val: nitem.id as i64,
pos: ebml_w.writer.tell().unwrap(),
encode_bounds_and_type(ebml_w, ecx,
&lookup_item_type(ecx.tcx,local_def(nitem.id)));
encode_name(ebml_w, nitem.ident.name);
- if abi.is_intrinsic() {
+ if abi == abi::RustIntrinsic {
(ecx.encode_inlined_item)(ecx, ebml_w, IIForeignRef(nitem));
} else {
encode_symbol(ecx, ebml_w, nitem.id);
let mut ebml_w = unsafe {
ebml_w.unsafe_clone()
};
- let abis = ecx.tcx.map.get_foreign_abis(ni.id);
+ let abi = ecx.tcx.map.get_foreign_abi(ni.id);
ecx.tcx.map.with_path(ni.id, |path| {
encode_info_for_foreign_item(ecx, &mut ebml_w,
ni, index,
- path, abis);
+ path, abi);
});
}
}
ebml_w.end_tag();
- return /*bad*/(*index).get();
+ return /*bad*/index.borrow().clone();
}
let mut buckets_frozen = Vec::new();
for bucket in buckets.iter() {
- buckets_frozen.push(@/*bad*/(**bucket).get());
+ buckets_frozen.push(@/*bad*/bucket.borrow().clone());
}
return buckets_frozen;
}
let name = csearch::get_symbol(&ccx.sess().cstore, did);
match ty::get(t).sty {
ty::ty_bare_fn(ref fn_ty) => {
- match fn_ty.abis.for_target(ccx.sess().targ_cfg.os,
- ccx.sess().targ_cfg.arch) {
+ match fn_ty.abi.for_target(ccx.sess().targ_cfg.os,
+ ccx.sess().targ_cfg.arch) {
Some(Rust) | Some(RustIntrinsic) => {
get_extern_rust_fn(ccx,
fn_ty.sig.inputs.as_slice(),
did)
}
Some(..) | None => {
- let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
+ let c = foreign::llvm_calling_convention(ccx, fn_ty.abi);
let cconv = c.unwrap_or(lib::llvm::CCallConv);
let llty = type_of_fn_from_ty(ccx, t);
get_extern_fn(&mut *ccx.externs.borrow_mut(), ccx.llmod,
llvm::LLVMGetParam(fcx.llfn, 0)
} else {
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
- let bcx = fcx.entry_bcx.get().unwrap();
+ let bcx = fcx.entry_bcx.borrow().clone().unwrap();
Alloca(bcx, lloutputtype, "__make_return_pointer")
}
}
param_substs: Option<@param_substs>) {
let entry_bcx = fcx.new_temp_block("entry-block");
- fcx.entry_bcx.set(Some(entry_bcx));
+ *fcx.entry_bcx.borrow_mut() = Some(entry_bcx);
// Use a dummy instruction as the insertion point for all allocas.
// This is later removed in FunctionContext::cleanup.
// Create the first basic block in the function and keep a handle on it to
// pass to finish_fn later.
- let bcx_top = fcx.entry_bcx.get().unwrap();
+ let bcx_top = fcx.entry_bcx.borrow().clone().unwrap();
let mut bcx = bcx_top;
let block_ty = node_id_type(bcx, body.id);
let arg_datums = create_datums_for_fn_args(&fcx, arg_tys.as_slice());
- let bcx = fcx.entry_bcx.get().unwrap();
+ let bcx = fcx.entry_bcx.borrow().clone().unwrap();
if !type_is_zero_size(fcx.ccx, result_ty) {
let repr = adt::represent_type(ccx, result_ty);
pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
let _icx = push_ctxt("trans_item");
match item.node {
- ast::ItemFn(decl, purity, _abis, ref generics, body) => {
+ ast::ItemFn(decl, purity, _abi, ref generics, body) => {
if purity == ast::ExternFn {
let llfndecl = get_item_val(ccx, item.id);
foreign::trans_rust_fn_with_foreign_abi(
-> ValueRef {
let f = match ty::get(node_type).sty {
ty::ty_bare_fn(ref f) => {
- assert!(f.abis.is_rust() || f.abis.is_intrinsic());
+ assert!(f.abi == Rust || f.abi == RustIntrinsic);
f
}
_ => fail!("expected bare rust fn or an intrinsic")
}
pub fn is_entry_fn(sess: &Session, node_id: ast::NodeId) -> bool {
- match sess.entry_fn.get() {
+ match *sess.entry_fn.borrow() {
Some((entry_id, _)) => node_id == entry_id,
None => false
}
match ni.node {
ast::ForeignItemFn(..) => {
- let abis = ccx.tcx.map.get_foreign_abis(id);
- foreign::register_foreign_item_fn(ccx, abis, ni)
+ let abi = ccx.tcx.map.get_foreign_abi(id);
+ foreign::register_foreign_item_fn(ccx, abi, ni)
}
ast::ForeignItemStatic(..) => {
foreign::register_static(ccx, ni)
.unwrap());
}
// Remove the cycle between fcx and bcx, so memory can be freed
- self.entry_bcx.set(None);
+ *self.entry_bcx.borrow_mut() = None;
}
pub fn get_llreturn(&self) -> BasicBlockRef {
// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
-pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
+pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef {
unsafe {
match cx.const_cstr_cache.borrow().find(&s) {
Some(&llval) => return llval,
let sc = llvm::LLVMConstStringInContext(cx.llcx,
s.get().as_ptr() as *c_char,
s.get().len() as c_uint,
- False);
+ !null_terminated as Bool);
let gsym = token::gensym("str");
let g = format!("str{}", gsym).with_c_str(|buf| {
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
unsafe {
let len = s.get().len();
- let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s), Type::i8p(cx).to_ref());
+ let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s, false), Type::i8p(cx).to_ref());
C_struct(cx, [cs, C_uint(cx, len)], false)
}
}
-> (ValueRef, ValueRef) {
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
let filename_cstr = C_cstr(bcx.ccx(),
- token::intern_and_get_ident(loc.file.name));
+ token::intern_and_get_ident(loc.file.name), true);
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p(bcx.ccx()));
let line = C_int(bcx.ccx(), loc.line as int);
(filename, line)
let str_ty = ty::mk_str(bcx.tcx(), str_vstore);
let scratch = rvalue_scratch_datum(bcx, str_ty, "");
let len = C_uint(bcx.ccx(), s.get().len());
- let c_str = PointerCast(bcx, C_cstr(bcx.ccx(), s), Type::i8p(bcx.ccx()));
+ let c_str = PointerCast(bcx, C_cstr(bcx.ccx(), s, false), Type::i8p(bcx.ccx()));
Store(bcx, c_str, GEPi(bcx, scratch.val, [ 0, 0 ]));
Store(bcx, len, GEPi(bcx, scratch.val, [ 0, 1 ]));
scratch.val
//
llvm::LLVMGetParam(llfdecl, fcx.arg_pos(0u) as c_uint)
};
- let bcx = fcx.entry_bcx.get().unwrap();
+ let bcx = fcx.entry_bcx.borrow().clone().unwrap();
let arg = BitCast(bcx, arg, llptrty);
let ret = adt::trans_get_discr(bcx, repr, arg, Some(Type::i64(ccx)));
Store(bcx, ret, fcx.llretptr.get().unwrap());
use std::result;
use std::slice;
use std::vec::Vec;
-use syntax::abi::AbiSet;
+use syntax::abi;
use syntax::ast::{Provided, Required};
use syntax::ast;
use syntax::ast_util::local_def;
check_bounds_are_used(ccx, t.span, &generics.ty_params, tpt_ty);
}
ast::ItemForeignMod(ref m) => {
- if m.abis.is_intrinsic() {
+ if m.abi == abi::RustIntrinsic {
for item in m.items.iter() {
check_intrinsic_type(ccx, *item);
}
match item.node {
ast::ForeignItemFn(ref fn_decl, _) => {
- if fn_decl.variadic && !m.abis.is_c() {
+ if fn_decl.variadic && m.abi != abi::C {
ccx.tcx.sess.span_err(
item.span, "variadic function must have C calling convention");
}
fcx.write_ty(expr.id, fty);
let (inherited_purity, id) =
- ty::determine_inherited_purity((fcx.ps.get().purity,
- fcx.ps.get().def),
+ ty::determine_inherited_purity((fcx.ps.borrow().purity,
+ fcx.ps.borrow().def),
(purity, expr.id),
sigil);
};
});
- fcx.ps.set(prev);
+ *fcx.ps.borrow_mut() = prev;
}
pub fn check_const(ccx: &CrateCtxt,
};
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
purity: ast::UnsafeFn,
- abis: AbiSet::Intrinsic(),
+ abi: abi::RustIntrinsic,
sig: FnSig {binder_id: it.id,
inputs: inputs,
output: output,
}
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
purity: ast::ImpureFn,
- abis: abi::AbiSet::Rust(),
+ abi: abi::Rust,
sig: ty::FnSig {
binder_id: main_id,
inputs: Vec::new(),
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
purity: ast::ImpureFn,
- abis: abi::AbiSet::Rust(),
+ abi: abi::Rust,
sig: ty::FnSig {
binder_id: start_id,
inputs: vec!(
fn check_for_entry_fn(ccx: &CrateCtxt) {
let tcx = ccx.tcx;
if !tcx.sess.building_library.get() {
- match tcx.sess.entry_fn.get() {
+ match *tcx.sess.entry_fn.borrow() {
Some((id, sp)) => match tcx.sess.entry_type.get() {
Some(session::EntryMain) => check_main_fn_ty(ccx, id, sp),
Some(session::EntryStart) => check_start_fn_ty(ccx, id, sp),