]> 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.

22 files changed:
src/librustc/driver/driver.rs
src/librustc/front/test.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/dead.rs
src/librustc/middle/entry.rs
src/librustc/middle/resolve.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/closure.rs
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/glue.rs
src/librustc/middle/trans/intrinsic.rs
src/librustc/middle/trans/reflect.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/regionck.rs
src/librustc/middle/typeck/infer/error_reporting.rs
src/librustc/middle/typeck/mod.rs
src/libstd/cell.rs
src/libstd/option.rs
src/test/auxiliary/issue-2631-a.rs
src/test/run-pass/cycle-collection.rs
src/test/run-pass/issue-980.rs
src/test/run-pass/out-of-stack.rs

index d5dba02ed28f27d28747eaa655bc0e6646af7baa..af5b3f8b0cdd3b666b4efbcb15ea63218239d8c8 100644 (file)
@@ -212,9 +212,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
     let time_passes = sess.time_passes();
 
     sess.building_library.set(session::building_library(&sess.opts, &krate));
-    sess.crate_types.set(session::collect_crate_types(sess,
-                                                      krate.attrs
-                                                           .as_slice()));
+    *sess.crate_types.borrow_mut() = session::collect_crate_types(sess, krate.attrs.as_slice());
 
     time(time_passes, "gated feature checking", (), |_|
          front::feature_gate::check_crate(sess, &krate));
index e39a4a9cc51f2c5d4365d419368ab2bf5e98becc..82e2e3147c93db1b0b39b18f39def54c789028d3 100644 (file)
@@ -90,7 +90,7 @@ fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate {
     fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
         self.cx.path.borrow_mut().push(i.ident);
         debug!("current path: {}",
-               ast_util::path_name_i(self.cx.path.get().as_slice()));
+               ast_util::path_name_i(self.cx.path.borrow().as_slice()));
 
         if is_test_fn(&self.cx, i) || is_bench_fn(&self.cx, i) {
             match i.node {
@@ -104,7 +104,7 @@ fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
                     debug!("this is a test function");
                     let test = Test {
                         span: i.span,
-                        path: self.cx.path.get(),
+                        path: self.cx.path.borrow().clone(),
                         bench: is_bench_fn(&self.cx, i),
                         ignore: is_ignored(&self.cx, i),
                         should_fail: should_fail(i)
index ec6bb7de380f88fc6a5e9e9602cbe934f38d9980..e453acac8109e74ffbf1bb390e9b600de8f1d34e 100644 (file)
@@ -1345,7 +1345,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
     }
 
     ebml_w.end_tag();
-    return /*bad*/(*index).get();
+    return /*bad*/index.borrow().clone();
 }
 
 
@@ -1365,7 +1365,7 @@ fn create_index<T:Clone + Hash + 'static>(
 
     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 1d23218583fc4b9d22effa975d7b2adfa8707c1d..d0bf70ea1c2c10c45b39ca6eaf573d9c1c20f645 100644 (file)
@@ -270,7 +270,7 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
     }
 
     // Seed entry point
-    match tcx.sess.entry_fn.get() {
+    match *tcx.sess.entry_fn.borrow() {
         Some((id, _)) => worklist.push(id),
         None => ()
     }
index 7adfd6e0af03b3bf789b0908b0b4f84c27e0dc05..441a3a3672983e9eb1bd0603415916b7cf432500 100644 (file)
@@ -123,13 +123,13 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
 
 fn configure_main(this: &mut EntryContext) {
     if this.start_fn.is_some() {
-        this.session.entry_fn.set(this.start_fn);
+        *this.session.entry_fn.borrow_mut() = this.start_fn;
         this.session.entry_type.set(Some(session::EntryStart));
     } else if this.attr_main_fn.is_some() {
-        this.session.entry_fn.set(this.attr_main_fn);
+        *this.session.entry_fn.borrow_mut() = this.attr_main_fn;
         this.session.entry_type.set(Some(session::EntryMain));
     } else if this.main_fn.is_some() {
-        this.session.entry_fn.set(this.main_fn);
+        *this.session.entry_fn.borrow_mut() = this.main_fn;
         this.session.entry_type.set(Some(session::EntryMain));
     } else {
         if !this.session.building_library.get() {
index 3e1c1828b6c483aa2402f77bfd66863570fb3f78..143b02f96d22f69ba995d13bf5e3d9f5aaefdb6e 100644 (file)
@@ -385,6 +385,10 @@ struct ImportResolution {
     type_id: Cell<NodeId>,
 }
 
+fn get<T: Clone>(cell: &RefCell<T>) -> T {
+    cell.borrow().clone()
+}
+
 impl ImportResolution {
     fn new(id: NodeId, is_public: bool) -> ImportResolution {
         ImportResolution {
@@ -400,8 +404,8 @@ fn new(id: NodeId, is_public: bool) -> ImportResolution {
     fn target_for_namespace(&self, namespace: Namespace)
                                 -> Option<Target> {
         match namespace {
-            TypeNS      => return self.type_target.get(),
-            ValueNS     => return self.value_target.get(),
+            TypeNS      => return self.type_target.borrow().clone(),
+            ValueNS     => return self.value_target.borrow().clone(),
         }
     }
 
@@ -546,22 +550,23 @@ fn define_module(&self,
         // Merges the module with the existing type def or creates a new one.
         let module_ = @Module::new(parent_link, def_id, kind, external,
                                        is_public);
-        match self.type_def.get() {
+        let type_def = self.type_def.borrow().clone();
+        match type_def {
             None => {
-                self.type_def.set(Some(TypeNsDef {
+                *self.type_def.borrow_mut() = Some(TypeNsDef {
                     is_public: is_public,
                     module_def: Some(module_),
                     type_def: None,
                     type_span: Some(sp)
-                }));
+                });
             }
             Some(type_def) => {
-                self.type_def.set(Some(TypeNsDef {
+                *self.type_def.borrow_mut() = Some(TypeNsDef {
                     is_public: is_public,
                     module_def: Some(module_),
                     type_span: Some(sp),
                     type_def: type_def.type_def
-                }));
+                });
             }
         }
     }
@@ -574,16 +579,17 @@ fn set_module_kind(&self,
                        external: bool,
                        is_public: bool,
                        _sp: Span) {
-        match self.type_def.get() {
+        let type_def = self.type_def.borrow().clone();
+        match type_def {
             None => {
                 let module = @Module::new(parent_link, def_id, kind,
                                               external, is_public);
-                self.type_def.set(Some(TypeNsDef {
+                *self.type_def.borrow_mut() = Some(TypeNsDef {
                     is_public: is_public,
                     module_def: Some(module),
                     type_def: None,
                     type_span: None,
-                }))
+                });
             }
             Some(type_def) => {
                 match type_def.module_def {
@@ -593,12 +599,12 @@ fn set_module_kind(&self,
                                                       kind,
                                                       external,
                                                       is_public);
-                        self.type_def.set(Some(TypeNsDef {
+                        *self.type_def.borrow_mut() = Some(TypeNsDef {
                             is_public: is_public,
                             module_def: Some(module),
                             type_def: type_def.type_def,
                             type_span: None,
-                        }))
+                        });
                     }
                     Some(module_def) => module_def.kind.set(kind),
                 }
@@ -609,33 +615,34 @@ fn set_module_kind(&self,
     /// Records a type definition.
     fn define_type(&self, def: Def, sp: Span, is_public: bool) {
         // Merges the type with the existing type def or creates a new one.
-        match self.type_def.get() {
+        let type_def = self.type_def.borrow().clone();
+        match type_def {
             None => {
-                self.type_def.set(Some(TypeNsDef {
+                *self.type_def.borrow_mut() = Some(TypeNsDef {
                     module_def: None,
                     type_def: Some(def),
                     type_span: Some(sp),
                     is_public: is_public,
-                }));
+                });
             }
             Some(type_def) => {
-                self.type_def.set(Some(TypeNsDef {
+                *self.type_def.borrow_mut() = Some(TypeNsDef {
                     type_def: Some(def),
                     type_span: Some(sp),
                     module_def: type_def.module_def,
                     is_public: is_public,
-                }));
+                });
             }
         }
     }
 
     /// Records a value definition.
     fn define_value(&self, def: Def, sp: Span, is_public: bool) {
-        self.value_def.set(Some(ValueNsDef {
+        *self.value_def.borrow_mut() = Some(ValueNsDef {
             def: def,
             value_span: Some(sp),
             is_public: is_public,
-        }));
+        });
     }
 
     /// Returns the module node if applicable.
@@ -662,17 +669,17 @@ fn get_module(&self) -> @Module {
 
     fn defined_in_namespace(&self, namespace: Namespace) -> bool {
         match namespace {
-            TypeNS   => return self.type_def.get().is_some(),
-            ValueNS  => return self.value_def.get().is_some()
+            TypeNS   => return self.type_def.borrow().is_some(),
+            ValueNS  => return self.value_def.borrow().is_some()
         }
     }
 
     fn defined_in_public_namespace(&self, namespace: Namespace) -> bool {
         match namespace {
-            TypeNS => match self.type_def.get() {
+            TypeNS => match *self.type_def.borrow() {
                 Some(def) => def.is_public, None => false
             },
-            ValueNS => match self.value_def.get() {
+            ValueNS => match *self.value_def.borrow() {
                 Some(def) => def.is_public, None => false
             }
         }
@@ -681,7 +688,7 @@ fn defined_in_public_namespace(&self, namespace: Namespace) -> bool {
     fn def_for_namespace(&self, namespace: Namespace) -> Option<Def> {
         match namespace {
             TypeNS => {
-                match self.type_def.get() {
+                match *self.type_def.borrow() {
                     None => None,
                     Some(type_def) => {
                         match type_def.type_def {
@@ -702,7 +709,7 @@ fn def_for_namespace(&self, namespace: Namespace) -> Option<Def> {
                 }
             }
             ValueNS => {
-                match self.value_def.get() {
+                match *self.value_def.borrow() {
                     None => None,
                     Some(value_def) => Some(value_def.def)
                 }
@@ -714,13 +721,13 @@ fn span_for_namespace(&self, namespace: Namespace) -> Option<Span> {
         if self.defined_in_namespace(namespace) {
             match namespace {
                 TypeNS  => {
-                    match self.type_def.get() {
+                    match *self.type_def.borrow() {
                         None => None,
                         Some(type_def) => type_def.type_span
                     }
                 }
                 ValueNS => {
-                    match self.value_def.get() {
+                    match *self.value_def.borrow() {
                         None => None,
                         Some(value_def) => value_def.value_span
                     }
@@ -1620,7 +1627,8 @@ fn handle_external_def(&mut self,
         match def {
           DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) |
           DefTy(def_id) => {
-            match child_name_bindings.type_def.get() {
+            let type_def = child_name_bindings.type_def.borrow().clone();
+            match type_def {
               Some(TypeNsDef { module_def: Some(module_def), .. }) => {
                 debug!("(building reduced graph for external crate) \
                         already created module");
@@ -1812,7 +1820,8 @@ fn build_reduced_graph_for_external_crate_def(&mut self,
                                 // Process the static methods. First,
                                 // create the module.
                                 let type_module;
-                                match child_name_bindings.type_def.get() {
+                                let type_def = child_name_bindings.type_def.borrow().clone();
+                                match type_def {
                                     Some(TypeNsDef {
                                         module_def: Some(module_def),
                                         ..
@@ -2408,8 +2417,8 @@ fn get_binding(this: &mut Resolver,
         match value_result {
             BoundResult(target_module, name_bindings) => {
                 debug!("(resolving single import) found value target");
-                import_resolution.value_target.set(
-                    Some(Target::new(target_module, name_bindings)));
+                *import_resolution.value_target.borrow_mut() =
+                    Some(Target::new(target_module, name_bindings));
                 import_resolution.value_id.set(directive.id);
                 value_used_public = name_bindings.defined_in_public_namespace(ValueNS);
             }
@@ -2421,9 +2430,9 @@ fn get_binding(this: &mut Resolver,
         match type_result {
             BoundResult(target_module, name_bindings) => {
                 debug!("(resolving single import) found type target: {:?}",
-                       {name_bindings.type_def.get().unwrap().type_def});
-                import_resolution.type_target.set(
-                    Some(Target::new(target_module, name_bindings)));
+                       { name_bindings.type_def.borrow().clone().unwrap().type_def });
+                *import_resolution.type_target.borrow_mut() =
+                    Some(Target::new(target_module, name_bindings));
                 import_resolution.type_id.set(directive.id);
                 type_used_public = name_bindings.defined_in_public_namespace(TypeNS);
             }
@@ -2433,8 +2442,8 @@ fn get_binding(this: &mut Resolver,
             }
         }
 
-        if import_resolution.value_target.get().is_none() &&
-           import_resolution.type_target.get().is_none() {
+        if import_resolution.value_target.borrow().is_none() &&
+           import_resolution.type_target.borrow().is_none() {
             let msg = format!("unresolved import: there is no \
                                `{}` in `{}`",
                               token::get_ident(source),
@@ -2452,7 +2461,7 @@ fn get_binding(this: &mut Resolver,
         // record what this import resolves to for later uses in documentation,
         // this may resolve to either a value or a type, but for documentation
         // purposes it's good enough to just favor one over the other.
-        let value_private = match import_resolution.value_target.get() {
+        let value_private = match *import_resolution.value_target.borrow() {
             Some(target) => {
                 let def = target.bindings.def_for_namespace(ValueNS).unwrap();
                 self.def_map.borrow_mut().insert(directive.id, def);
@@ -2463,7 +2472,7 @@ fn get_binding(this: &mut Resolver,
             // _exists is false.
             None => None,
         };
-        let type_private = match import_resolution.type_target.get() {
+        let type_private = match *import_resolution.type_target.borrow() {
             Some(target) => {
                 let def = target.bindings.def_for_namespace(TypeNS).unwrap();
                 self.def_map.borrow_mut().insert(directive.id, def);
@@ -2513,7 +2522,7 @@ fn resolve_glob_import(&mut self,
         for (ident, target_import_resolution) in import_resolutions.iter() {
             debug!("(resolving glob import) writing module resolution \
                     {:?} into `{}`",
-                   target_import_resolution.type_target.get().is_none(),
+                   target_import_resolution.type_target.borrow().is_none(),
                    self.module_to_str(module_));
 
             if !target_import_resolution.is_public.get() {
@@ -2528,10 +2537,10 @@ fn resolve_glob_import(&mut self,
                     // Simple: just copy the old import resolution.
                     let new_import_resolution =
                         @ImportResolution::new(id, is_public);
-                    new_import_resolution.value_target.set(
-                        target_import_resolution.value_target.get());
-                    new_import_resolution.type_target.set(
-                        target_import_resolution.type_target.get());
+                    *new_import_resolution.value_target.borrow_mut() =
+                        get(&target_import_resolution.value_target);
+                    *new_import_resolution.type_target.borrow_mut() =
+                        get(&target_import_resolution.type_target);
 
                     import_resolutions.insert
                         (*ident, new_import_resolution);
@@ -2540,22 +2549,20 @@ fn resolve_glob_import(&mut self,
                     // Merge the two import resolutions at a finer-grained
                     // level.
 
-                    match target_import_resolution.value_target.get() {
+                    match *target_import_resolution.value_target.borrow() {
                         None => {
                             // Continue.
                         }
                         Some(value_target) => {
-                            dest_import_resolution.value_target.set(
-                                Some(value_target));
+                            *dest_import_resolution.value_target.borrow_mut() = Some(value_target);
                         }
                     }
-                    match target_import_resolution.type_target.get() {
+                    match *target_import_resolution.type_target.borrow() {
                         None => {
                             // Continue.
                         }
                         Some(type_target) => {
-                            dest_import_resolution.type_target.set(
-                                Some(type_target));
+                            *dest_import_resolution.type_target.borrow_mut() = Some(type_target);
                         }
                     }
                     dest_import_resolution.is_public.set(is_public);
@@ -2627,14 +2634,14 @@ fn merge_import_resolution(&mut self,
         // Merge the child item into the import resolution.
         if name_bindings.defined_in_public_namespace(ValueNS) {
             debug!("(resolving glob import) ... for value target");
-            dest_import_resolution.value_target.set(
-                Some(Target::new(containing_module, name_bindings)));
+            *dest_import_resolution.value_target.borrow_mut() =
+                Some(Target::new(containing_module, name_bindings));
             dest_import_resolution.value_id.set(id);
         }
         if name_bindings.defined_in_public_namespace(TypeNS) {
             debug!("(resolving glob import) ... for type target");
-            dest_import_resolution.type_target.set(
-                Some(Target::new(containing_module, name_bindings)));
+            *dest_import_resolution.type_target.borrow_mut() =
+                Some(Target::new(containing_module, name_bindings));
             dest_import_resolution.type_id.set(id);
         }
         dest_import_resolution.is_public.set(is_public);
@@ -2692,7 +2699,7 @@ fn resolve_module_path_from_root(&mut self,
                 Success((target, used_proxy)) => {
                     // Check to see whether there are type bindings, and, if
                     // so, whether there is a module within.
-                    match target.bindings.type_def.get() {
+                    match *target.bindings.type_def.borrow() {
                         Some(type_def) => {
                             match type_def.module_def {
                                 None => {
@@ -3004,7 +3011,7 @@ fn resolve_module_in_lexical_scope(&mut self,
         match resolve_result {
             Success((target, _)) => {
                 let bindings = &*target.bindings;
-                match bindings.type_def.get() {
+                match *bindings.type_def.borrow() {
                     Some(type_def) => {
                         match type_def.module_def {
                             None => {
@@ -4526,8 +4533,8 @@ fn resolve_bare_identifier_pattern(&mut self, name: Ident)
                 debug!("(resolve bare identifier pattern) succeeded in \
                          finding {} at {:?}",
                         token::get_ident(name),
-                        target.bindings.value_def.get());
-                match target.bindings.value_def.get() {
+                        target.bindings.value_def.borrow());
+                match *target.bindings.value_def.borrow() {
                     None => {
                         fail!("resolved name in the value namespace to a \
                               set of name bindings with no def?!");
index 09bbb95fdd04e29ca825434ff1d3c9b8abe245c3..9657265e14038aaea488192267d81d9100445061 100644 (file)
@@ -1128,7 +1128,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
             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 @@ 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 @@ 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 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
 
     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);
@@ -1752,7 +1752,7 @@ pub fn register_fn_llvmty(ccx: &CrateContext,
 }
 
 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
     }
index 1d2e1d0232c348a411d4dcaf39a41daf86811b57..4671e21170e869bea654b35e18d8cd5c2db5ab51 100644 (file)
@@ -464,7 +464,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
     let arena = TypedArena::new();
     let fcx = new_fn_ctxt(ccx, llfn, -1, true, f.sig.output, None, None, &arena);
     init_function(&fcx, true, f.sig.output, None);
-    let bcx = fcx.entry_bcx.get().unwrap();
+    let bcx = fcx.entry_bcx.borrow().clone().unwrap();
 
     let args = create_datums_for_fn_args(&fcx,
                                          ty::ty_fn_args(closure_ty)
index 97638f7e4690ab6b2e13ca0b055a00e745a1357b..369807e98d7e04e11780fc896cd0d9172bdcb3f9 100644 (file)
@@ -322,7 +322,7 @@ pub fn cleanup(&self) {
                                                      .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 {
index da9d06b9a752613940d9a056bef6246e562eb361..87234ce3683531907f91b501a7c71a700cc54d77 100644 (file)
@@ -463,7 +463,7 @@ fn make_generic_glue(ccx: &CrateContext,
     // llfn is expected be declared to take a parameter of the appropriate
     // type, so we don't need to explicitly cast the function parameter.
 
-    let bcx = fcx.entry_bcx.get().unwrap();
+    let bcx = fcx.entry_bcx.borrow().clone().unwrap();
     let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, fcx.arg_pos(0) as c_uint) };
     let bcx = helper(bcx, llrawptr0, t);
     finish_fn(&fcx, bcx);
index 95c0b08d400eac12b1537b1a523b0d7336943f97..28a39718e7fb6a32b6a79d300cd04cd941e89d5e 100644 (file)
@@ -199,7 +199,7 @@ fn count_zeros_intrinsic(bcx: &Block, name: &'static str) {
 
     set_always_inline(fcx.llfn);
 
-    let mut bcx = fcx.entry_bcx.get().unwrap();
+    let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
     let first_real_arg = fcx.arg_pos(0u);
 
     let name = token::get_ident(item.ident);
index e73ef639a0ba86bec68f32eb78aeab28f1e83bc1..1adf5cf8afe5d2d40526ce64da878dc09d9ac5da 100644 (file)
@@ -300,7 +300,7 @@ pub fn visit_ty(&mut self, t: ty::t) {
                     //
                     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..8f9b67f81e884ac63445c63e4f068cb17db72340 100644 (file)
@@ -2209,8 +2209,8 @@ fn check_expr_fn(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 @@ pub fn check_block_with_expected(fcx: &FnCtxt,
         };
     });
 
-    fcx.ps.set(prev);
+    *fcx.ps.borrow_mut() = prev;
 }
 
 pub fn check_const(ccx: &CrateCtxt,
index e67a83cd9269db5eac4d092094a2d82e54483b74..c8613fd70652ee60e8f5909de52c6c4029ea69de 100644 (file)
@@ -398,7 +398,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
            expr.repr(rcx.fcx.tcx()), rcx.repeating_scope);
 
     let method_call = MethodCall::expr(expr.id);
-    let has_method_map = rcx.fcx.inh.method_map.get().contains_key(&method_call);
+    let has_method_map = rcx.fcx.inh.method_map.borrow().contains_key(&method_call);
 
     // Check any autoderefs or autorefs that appear.
     for &adjustment in rcx.fcx.inh.adjustments.borrow().find(&expr.id).iter() {
@@ -498,7 +498,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
         ast::ExprUnary(ast::UnDeref, base) => {
             // For *a, the lifetime of a must enclose the deref
             let method_call = MethodCall::expr(expr.id);
-            let base_ty = match rcx.fcx.inh.method_map.get().find(&method_call) {
+            let base_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) {
                 Some(method) => {
                     constrain_call(rcx, None, expr, Some(base), [], true);
                     ty::ty_fn_ret(method.ty)
@@ -852,7 +852,7 @@ fn constrain_autoderefs(rcx: &mut Rcx,
                i, derefs);
 
         let method_call = MethodCall::autoderef(deref_expr.id, i as u32);
-        derefd_ty = match rcx.fcx.inh.method_map.get().find(&method_call) {
+        derefd_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) {
             Some(method) => {
                 // Treat overloaded autoderefs as if an AutoRef adjustment
                 // was applied on the base type, as that is always the case.
index 83ca7ea7dfbd4f46f218db98a424f047807d9942..9c947fb3360e455014adeb480934f15f3fad864e 100644 (file)
@@ -1286,6 +1286,6 @@ fn num_to_str(counter: uint) -> ~str {
     }
 
     fn get_generated_lifetimes(&self) -> Vec<ast::Lifetime> {
-        self.generated.get()
+        self.generated.borrow().clone()
     }
 }
index d635a9bdec41e03ae058fa06efb55ceb074c691e..446d2ff055cca90fd819f53f7e3819fac87537ec 100644 (file)
@@ -431,7 +431,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
 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),
index eb114e895103aca49f89a243df8ea2b898284ebc..40c6c3ebccf0be857d272acd67257bdce729b534 100644 (file)
@@ -164,33 +164,11 @@ pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
             None => fail!("RefCell<T> already borrowed")
         }
     }
-
-    /// Sets the value, replacing what was there.
-    ///
-    /// # Failure
-    ///
-    /// Fails if the value is currently borrowed.
-    #[inline]
-    pub fn set(&self, value: T) {
-        *self.borrow_mut() = value;
-    }
-}
-
-impl<T:Clone> RefCell<T> {
-    /// Returns a copy of the contained value.
-    ///
-    /// # Failure
-    ///
-    /// Fails if the value is currently mutably borrowed.
-    #[inline]
-    pub fn get(&self) -> T {
-        (*self.borrow()).clone()
-    }
 }
 
 impl<T: Clone> Clone for RefCell<T> {
     fn clone(&self) -> RefCell<T> {
-        RefCell::new(self.get())
+        RefCell::new(self.borrow().clone())
     }
 }
 
@@ -216,7 +194,7 @@ fn drop(&mut self) {
 impl<'b, T> Deref<T> for Ref<'b, T> {
     #[inline]
     fn deref<'a>(&'a self) -> &'a T {
-        unsafe{ &*self.parent.value.get() }
+        unsafe { &*self.parent.value.get() }
     }
 }
 
@@ -236,14 +214,14 @@ fn drop(&mut self) {
 impl<'b, T> Deref<T> for RefMut<'b, T> {
     #[inline]
     fn deref<'a>(&'a self) -> &'a T {
-        unsafe{ &*self.parent.value.get() }
+        unsafe { &*self.parent.value.get() }
     }
 }
 
 impl<'b, T> DerefMut<T> for RefMut<'b, T> {
     #[inline]
     fn deref_mut<'a>(&'a mut self) -> &'a mut T {
-        unsafe{ &mut *self.parent.value.get() }
+        unsafe { &mut *self.parent.value.get() }
     }
 }
 
index be1c87ba7886ccb2e96264ae60cce78855ec1046..ca1ea0169e66a269f51f248b1885c1253c49b970 100644 (file)
@@ -651,7 +651,8 @@ struct R {
         impl ::ops::Drop for R {
            fn drop(&mut self) {
                 let ii = &*self.i;
-                ii.set(ii.get() + 1);
+                let i = ii.borrow().clone();
+                *ii.borrow_mut() = i + 1;
             }
         }
 
@@ -667,7 +668,7 @@ fn R(i: Rc<RefCell<int>>) -> R {
             let opt = Some(x);
             let _y = opt.unwrap();
         }
-        assert_eq!(i.get(), 1);
+        assert_eq!(*i.borrow(), 1);
     }
 
     #[test]
index e7e0bf1bd60fadc3496bab69ecd5d21218521e92..e61510f2ef2d8e8136fa284c8d9cf516705e8751 100644 (file)
@@ -21,5 +21,5 @@
 
 // the unused ty param is necessary so this gets monomorphized
 pub fn request<T>(req: &header_map) {
-  let _x = (**((**req.get(&~"METHOD")).clone()).get().get(0)).clone();
+  let _x = (**((**req.get(&~"METHOD")).clone()).borrow().clone().get(0)).clone();
 }
index ca1e18eb87b97e1bf0999804da71876e19ef463b..c6f353136bada19302eb77ac6b236caec27d2b42 100644 (file)
@@ -19,7 +19,7 @@ enum taggy {
 
 fn f() {
     let a_box = @RefCell::new(nil);
-    a_box.set(cons(a_box));
+    *a_box.borrow_mut() = cons(a_box);
 }
 
 pub fn main() {
index f6dc4adcf9b5af86e3fe9f991ea429864ced7830..06f95bae5593bcb68fb817a3e99c5ae48766ff7a 100644 (file)
@@ -23,7 +23,7 @@ struct Pointy {
 
 pub fn main() {
     let m = @RefCell::new(Pointy { x : no_pointy });
-    m.set(Pointy {
+    *m.borrow_mut() = Pointy {
         x: yes_pointy(m)
-    });
+    };
 }
index d1daa1e365eca7d86408ba8d55b59f7fafcf9d9c..71fde8667032207ba9db4c6a23a5adaa73cbaec0 100644 (file)
@@ -17,6 +17,9 @@
 use std::str;
 
 // lifted from the test module
+// Inlining to avoid llvm turning the recursive functions into tail calls,
+// which doesn't consume stack.
+#[inline(always)]
 pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } }
 
 fn silent_recurse() {