]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #13301 : erickt/rust/remove-refcell-get, r=huonw
authorbors <bors@rust-lang.org>
Fri, 4 Apr 2014 15:41:50 +0000 (08:41 -0700)
committerbors <bors@rust-lang.org>
Fri, 4 Apr 2014 15:41:50 +0000 (08:41 -0700)
`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.

1  2 
src/librustc/metadata/encoder.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/reflect.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/mod.rs

index ec6bb7de380f88fc6a5e9e9602cbe934f38d9980,b7cba60abe6432c58b00bd6ecd16e91fd4a57cd9..e453acac8109e74ffbf1bb390e9b600de8f1d34e
@@@ -33,7 -33,7 +33,7 @@@ use std::hash::Hash
  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};
@@@ -1217,7 -1217,7 +1217,7 @@@ fn encode_info_for_foreign_item(ecx: &E
                                  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);
@@@ -1279,11 -1279,11 +1279,11 @@@ fn my_visit_foreign_item(ni: &ForeignIt
      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);
      });
  }
  
@@@ -1345,7 -1345,7 +1345,7 @@@ fn encode_info_for_items(ecx: &EncodeCo
      }
  
      ebml_w.end_tag();
-     return /*bad*/(*index).get();
+     return /*bad*/index.borrow().clone();
  }
  
  
@@@ -1365,7 -1365,7 +1365,7 @@@ fn create_index<T:Clone + Hash + 'stati
  
      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;
  }
index 09bbb95fdd04e29ca825434ff1d3c9b8abe245c3,96f75705cf8e4f70d6ee9c40a615cfa2456775cd..9657265e14038aaea488192267d81d9100445061
@@@ -855,8 -855,8 +855,8 @@@ pub fn trans_external_path(ccx: &CrateC
      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,
@@@ -1128,7 -1128,7 +1128,7 @@@ pub fn make_return_pointer(fcx: &Functi
              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")
          }
      }
@@@ -1209,7 -1209,7 +1209,7 @@@ pub fn init_function<'a>
                       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.
@@@ -1399,7 -1399,7 +1399,7 @@@ pub fn trans_closure(ccx: &CrateContext
  
      // 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);
  
@@@ -1547,7 -1547,7 +1547,7 @@@ fn trans_enum_variant_or_tuple_like_str
  
      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);
@@@ -1601,7 -1601,7 +1601,7 @@@ impl<'a> Visitor<()> for TransItemVisit
  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(
@@@ -1721,7 -1721,7 +1721,7 @@@ fn register_fn(ccx: &CrateContext
                 -> 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")
@@@ -1752,7 -1752,7 +1752,7 @@@ pub fn register_fn_llvmty(ccx: &CrateCo
  }
  
  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
      }
@@@ -1997,8 -1997,8 +1997,8 @@@ pub fn get_item_val(ccx: &CrateContext
  
              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)
index 97638f7e4690ab6b2e13ca0b055a00e745a1357b,26520e98c13ae9c0acfbc07d73303876a50ef610..369807e98d7e04e11780fc896cd0d9172bdcb3f9
@@@ -322,7 -322,7 +322,7 @@@ impl<'a> FunctionContext<'a> 
                                                       .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 {
@@@ -565,7 -565,7 +565,7 @@@ pub fn C_u8(ccx: &CrateContext, i: uint
  
  // 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)
      }
  }
@@@ -900,7 -900,7 +900,7 @@@ pub fn filename_and_line_num_from_span(
                                         -> (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)
index e73ef639a0ba86bec68f32eb78aeab28f1e83bc1,41d8b05c6eae1f58af32cd30bf0355c28f82729d..1adf5cf8afe5d2d40526ce64da878dc09d9ac5da
@@@ -58,7 -58,7 +58,7 @@@ impl<'a> Reflector<'a> 
          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());
index 20ab2b699c2b6525eca9f30ea34c5b1212fcd84e,085e387dfe95b844e13aec379d0fcac4cb6f496e..8f9b67f81e884ac63445c63e4f068cb17db72340
@@@ -120,7 -120,7 +120,7 @@@ use std::mem::replace
  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;
@@@ -599,7 -599,7 +599,7 @@@ pub fn check_item(ccx: &CrateCtxt, it: 
          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");
                          }
@@@ -2209,8 -2209,8 +2209,8 @@@ fn check_expr_with_unifier(fcx: &FnCtxt
          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);
  
@@@ -3333,7 -3333,7 +3333,7 @@@ pub fn check_block_with_expected(fcx: &
          };
      });
  
-     fcx.ps.set(prev);
+     *fcx.ps.borrow_mut() = prev;
  }
  
  pub fn check_const(ccx: &CrateCtxt,
@@@ -4224,7 -4224,7 +4224,7 @@@ pub fn check_intrinsic_type(ccx: &Crate
      };
      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,
index d635a9bdec41e03ae058fa06efb55ceb074c691e,edfd9b43865842bda2f55949845782f3d340013e..446d2ff055cca90fd819f53f7e3819fac87537ec
@@@ -358,7 -358,7 +358,7 @@@ fn check_main_fn_ty(ccx: &CrateCtxt
              }
              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(),
@@@ -404,7 -404,7 +404,7 @@@ fn check_start_fn_ty(ccx: &CrateCtxt
  
              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),