]> git.lizzy.rs Git - rust.git/commitdiff
rollup merge of #18407 : thestinger/arena
authorAlex Crichton <alex@alexcrichton.com>
Thu, 30 Oct 2014 15:57:30 +0000 (08:57 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 30 Oct 2014 16:29:23 +0000 (09:29 -0700)
1  2 
src/libarena/lib.rs
src/librustc/middle/typeck/variance.rs

diff --combined src/libarena/lib.rs
index 924dd5ffed62cd300c4e5d3190ce046efbad844d,5682bb76d55605ffe7a8bf12b3fda4a81d79abaf..1528c313b738e804ff4b012ab8351be473e4b114
@@@ -69,7 -69,7 +69,7 @@@ impl Chunk 
  /// element). When the arena is destroyed, it iterates through all of its
  /// chunks, and uses the tydesc information to trace through the objects,
  /// calling the destructors on them. One subtle point that needs to be
 -/// addressed is how to handle failures while running the user provided
 +/// addressed is how to handle panics while running the user provided
  /// initializer function. It is important to not run the destructor on
  /// uninitialized objects, but how to detect them is somewhat subtle. Since
  /// `alloc()` can be invoked recursively, it is not sufficient to simply exclude
@@@ -162,7 -162,7 +162,7 @@@ unsafe fn destroy_chunk(chunk: &Chunk) 
  
  // We encode whether the object a tydesc describes has been
  // initialized in the arena in the low bit of the tydesc pointer. This
 -// is necessary in order to properly do cleanup if a failure occurs
 +// is necessary in order to properly do cleanup if a panic occurs
  // during an initializer.
  #[inline]
  fn bitpack_tydesc_ptr(p: *const TyDesc, is_done: bool) -> uint {
@@@ -208,13 -208,13 +208,13 @@@ impl Arena 
      }
  
      #[inline]
-     fn alloc_copy<T>(&self, op: || -> T) -> &T {
+     fn alloc_copy<T>(&self, op: || -> T) -> &mut T {
          unsafe {
              let ptr = self.alloc_copy_inner(mem::size_of::<T>(),
                                              mem::min_align_of::<T>());
              let ptr = ptr as *mut T;
              ptr::write(&mut (*ptr), op());
-             return &*ptr;
+             return &mut *ptr;
          }
      }
  
      }
  
      #[inline]
-     fn alloc_noncopy<T>(&self, op: || -> T) -> &T {
+     fn alloc_noncopy<T>(&self, op: || -> T) -> &mut T {
          unsafe {
              let tydesc = get_tydesc::<T>();
              let (ty_ptr, ptr) =
              // the object is there.
              *ty_ptr = bitpack_tydesc_ptr(tydesc, true);
  
-             return &*ptr;
+             return &mut *ptr;
          }
      }
  
      /// Allocates a new item in the arena, using `op` to initialize the value,
      /// and returns a reference to it.
      #[inline]
-     pub fn alloc<T>(&self, op: || -> T) -> &T {
+     pub fn alloc<T>(&self, op: || -> T) -> &mut T {
          unsafe {
              if intrinsics::needs_drop::<T>() {
                  self.alloc_noncopy(op)
@@@ -337,9 -337,10 +337,9 @@@ fn test_arena_destructors_fail() 
          // things interesting.
          arena.alloc(|| { [0u8, 1u8, 2u8] });
      }
 -    // Now, fail while allocating
 +    // Now, panic while allocating
      arena.alloc::<Rc<int>>(|| {
 -        // Now fail.
 -        fail!();
 +        panic!();
      });
  }
  
@@@ -458,12 -459,12 +458,12 @@@ impl<T> TypedArena<T> 
  
      /// Allocates an object in the `TypedArena`, returning a reference to it.
      #[inline]
-     pub fn alloc(&self, object: T) -> &T {
+     pub fn alloc(&self, object: T) -> &mut T {
          if self.ptr == self.end {
              self.grow()
          }
  
-         let ptr: &T = unsafe {
+         let ptr: &mut T = unsafe {
              let ptr: &mut T = mem::transmute(self.ptr);
              ptr::write(ptr, object);
              self.ptr.set(self.ptr.get().offset(1));
index c8214a743de73338245a17712afef8daa64db50a,1b64d90427bd08be618b90ac6bbb9e63bd3f9dd9..b8c47cff48c6b1fe9f92dcbd667d0ae1114169d4
@@@ -572,7 -572,7 +572,7 @@@ impl<'a, 'tcx> ConstraintContext<'a, 't
          match tcx.named_region_map.find(&param_id) {
              Some(&rl::DefEarlyBoundRegion(_, _, lifetime_decl_id))
                  => lifetime_decl_id,
 -            Some(_) => fail!("should not encounter non early-bound cases"),
 +            Some(_) => panic!("should not encounter non early-bound cases"),
  
              // The lookup should only fail when `param_id` is
              // itself a lifetime binding: use it as the decl_id.
              assert!(is_lifetime(&tcx.map, param_id));
              let parent_id = tcx.map.get_parent(decl_id);
              let parent = tcx.map.find(parent_id).unwrap_or_else(
 -                || fail!("tcx.map missing entry for id: {}", parent_id));
 +                || panic!("tcx.map missing entry for id: {}", parent_id));
  
              let is_inferred;
              macro_rules! cannot_happen { () => { {
 -                fail!("invalid parent: {:s} for {:s}",
 +                panic!("invalid parent: {:s} for {:s}",
                        tcx.map.node_to_string(parent_id),
                        tcx.map.node_to_string(param_id));
              } } }
              }
  
              _ => {
-                 self.terms_cx.arena.alloc(|| TransformTerm(v1, v2))
+                 &*self.terms_cx.arena.alloc(|| TransformTerm(v1, v2))
              }
          }
      }
          debug!("add_constraints_from_ty(ty={})", ty.repr(self.tcx()));
  
          match ty::get(ty).sty {
 -            ty::ty_nil | ty::ty_bot | ty::ty_bool |
 +            ty::ty_nil | ty::ty_bool |
              ty::ty_char | ty::ty_int(_) | ty::ty_uint(_) |
              ty::ty_float(_) | ty::ty_str => {
                  /* leaf type -- noop */
              }
  
 -            ty::ty_unboxed_closure(_, region) => {
 -                let contra = self.contravariant(variance);
 -                self.add_constraints_from_region(region, contra);
 +            ty::ty_unboxed_closure(..) => {
 +                self.tcx().sess.bug("Unexpected unboxed closure type in variance computation");
              }
  
              ty::ty_rptr(region, ref mt) => {
          for &input in sig.inputs.iter() {
              self.add_constraints_from_ty(input, contra);
          }
 -        self.add_constraints_from_ty(sig.output, variance);
 +        if let ty::FnConverging(result_type) = sig.output {
 +            self.add_constraints_from_ty(result_type, variance);
 +        }
      }
  
      /// Adds constraints appropriate for a region appearing in a