Skip to content

Commit

Permalink
Removed DeepClone. Issue #12698.
Browse files Browse the repository at this point in the history
  • Loading branch information
pongad committed Mar 8, 2014
1 parent 96e8c00 commit 438893b
Show file tree
Hide file tree
Showing 28 changed files with 36 additions and 367 deletions.
9 changes: 1 addition & 8 deletions src/libstd/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! Types dealing with dynamic mutability

use cast;
use clone::{Clone, DeepClone};
use clone::Clone;
use cmp::Eq;
use fmt;
use kinds::{marker, Pod};
Expand Down Expand Up @@ -222,13 +222,6 @@ impl<T: Clone> Clone for RefCell<T> {
}
}

impl<T: DeepClone> DeepClone for RefCell<T> {
fn deep_clone(&self) -> RefCell<T> {
let x = self.borrow();
RefCell::new(x.get().deep_clone())
}
}

impl<T: Eq> Eq for RefCell<T> {
fn eq(&self, other: &RefCell<T>) -> bool {
let a = self.borrow();
Expand Down
100 changes: 0 additions & 100 deletions src/libstd/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ the `clone` method.
*/

use std::kinds::Freeze;

/// A common trait for cloning an object.
pub trait Clone {
/// Returns a copy of the value. The contents of owned pointers
Expand Down Expand Up @@ -125,92 +123,6 @@ extern_fn_clone!(A, B, C, D, E, F)
extern_fn_clone!(A, B, C, D, E, F, G)
extern_fn_clone!(A, B, C, D, E, F, G, H)

/// A trait distinct from `Clone` which represents "deep copies" of things like
/// managed boxes which would otherwise not be copied.
pub trait DeepClone: Clone {
/// Return a deep copy of the value. Unlike `Clone`, the contents of shared pointer types
/// *are* copied.
fn deep_clone(&self) -> Self;

/// Perform deep copy-assignment from `source`.
///
/// `a.deep_clone_from(&b)` is equivalent to `a = b.deep_clone()` in
/// functionality, but can be overridden to reuse the resources of `a` to
/// avoid unnecessary allocations.
#[inline(always)]
fn deep_clone_from(&mut self, source: &Self) {
*self = source.deep_clone()
}
}

impl<T: DeepClone> DeepClone for ~T {
/// Return a deep copy of the owned box.
#[inline]
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }

/// Perform deep copy-assignment from `source` by reusing the existing allocation.
fn deep_clone_from(&mut self, source: &~T) {
**self = (**source).deep_clone()
}
}

// FIXME: #6525: should also be implemented for `T: Send + DeepClone`
impl<T: Freeze + DeepClone + 'static> DeepClone for @T {
/// Return a deep copy of the managed box. The `Freeze` trait is required to prevent performing
/// a deep clone of a potentially cyclical type.
#[inline]
fn deep_clone(&self) -> @T { @(**self).deep_clone() }
}

macro_rules! deep_clone_impl(
($t:ty) => {
impl DeepClone for $t {
/// Return a deep copy of the value.
#[inline]
fn deep_clone(&self) -> $t { *self }
}
}
)

deep_clone_impl!(int)
deep_clone_impl!(i8)
deep_clone_impl!(i16)
deep_clone_impl!(i32)
deep_clone_impl!(i64)

deep_clone_impl!(uint)
deep_clone_impl!(u8)
deep_clone_impl!(u16)
deep_clone_impl!(u32)
deep_clone_impl!(u64)

deep_clone_impl!(f32)
deep_clone_impl!(f64)

deep_clone_impl!(())
deep_clone_impl!(bool)
deep_clone_impl!(char)

macro_rules! extern_fn_deep_clone(
($($A:ident),*) => (
impl<$($A,)* ReturnType> DeepClone for extern "Rust" fn($($A),*) -> ReturnType {
/// Return a copy of a function pointer
#[inline]
fn deep_clone(&self) -> extern "Rust" fn($($A),*) -> ReturnType { *self }
}
)
)

extern_fn_deep_clone!()
extern_fn_deep_clone!(A)
extern_fn_deep_clone!(A, B)
extern_fn_deep_clone!(A, B, C)
extern_fn_deep_clone!(A, B, C, D)
extern_fn_deep_clone!(A, B, C, D, E)
extern_fn_deep_clone!(A, B, C, D, E, F)
extern_fn_deep_clone!(A, B, C, D, E, F, G)
extern_fn_deep_clone!(A, B, C, D, E, F, G, H)

#[test]
fn test_owned_clone() {
let a = ~5i;
Expand Down Expand Up @@ -241,14 +153,6 @@ fn test_clone_from() {
assert_eq!(*b, 5);
}

#[test]
fn test_deep_clone_from() {
let a = ~5;
let mut b = ~10;
b.deep_clone_from(&a);
assert_eq!(*b, 5);
}

#[test]
fn test_extern_fn_clone() {
trait Empty {}
Expand All @@ -261,8 +165,4 @@ fn test_extern_fn_clone() {
let _ = test_fn_a.clone();
let _ = test_fn_b::<int>.clone();
let _ = test_fn_c.clone();

let _ = test_fn_a.deep_clone();
let _ = test_fn_b::<int>.deep_clone();
let _ = test_fn_c.deep_clone();
}
23 changes: 1 addition & 22 deletions src/libstd/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ collector is task-local so `Gc<T>` is not sendable.
#[allow(experimental)];

use kinds::marker;
use kinds::Send;
use clone::{Clone, DeepClone};
use clone::Clone;
use managed;

/// Immutable garbage-collected pointer type
Expand Down Expand Up @@ -78,16 +77,6 @@ pub static GC: () = ();
#[cfg(test)]
pub static GC: () = ();

/// The `Send` bound restricts this to acyclic graphs where it is well-defined.
///
/// A `Freeze` bound would also work, but `Send` *or* `Freeze` cannot be expressed.
impl<T: DeepClone + Send + 'static> DeepClone for Gc<T> {
#[inline]
fn deep_clone(&self) -> Gc<T> {
Gc::new(self.borrow().deep_clone())
}
}

#[cfg(test)]
mod tests {
use prelude::*;
Expand All @@ -104,16 +93,6 @@ mod tests {
assert_eq!(y.borrow().with(|x| *x), 20);
}

#[test]
fn test_deep_clone() {
let x = Gc::new(RefCell::new(5));
let y = x.deep_clone();
x.borrow().with_mut(|inner| {
*inner = 20;
});
assert_eq!(y.borrow().with(|x| *x), 5);
}

#[test]
fn test_simple() {
let x = Gc::new(5);
Expand Down
12 changes: 6 additions & 6 deletions src/libstd/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ impl<'a,

/// An iterator that yields `None` forever after the underlying iterator
/// yields `None` once.
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct Fuse<T> {
priv iter: T,
priv done: bool
Expand Down Expand Up @@ -1946,7 +1946,7 @@ impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
}

/// An iterator over the range [start, stop)
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct Range<A> {
priv state: A,
priv stop: A,
Expand Down Expand Up @@ -2020,7 +2020,7 @@ impl<A: Int + Ord + Clone + ToPrimitive> DoubleEndedIterator<A> for Range<A> {
}

/// An iterator over the range [start, stop]
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct RangeInclusive<A> {
priv range: Range<A>,
priv done: bool
Expand Down Expand Up @@ -2083,7 +2083,7 @@ impl<A: Sub<A, A> + Int + Ord + Clone + ToPrimitive> DoubleEndedIterator<A>
}

/// An iterator over the range [start, stop) by `step`. It handles overflow by stopping.
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct RangeStep<A> {
priv state: A,
priv stop: A,
Expand Down Expand Up @@ -2115,7 +2115,7 @@ impl<A: CheckedAdd + Ord + Clone> Iterator<A> for RangeStep<A> {
}

/// An iterator over the range [start, stop] by `step`. It handles overflow by stopping.
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct RangeStepInclusive<A> {
priv state: A,
priv stop: A,
Expand Down Expand Up @@ -2150,7 +2150,7 @@ impl<A: CheckedAdd + Ord + Clone + Eq> Iterator<A> for RangeStepInclusive<A> {
}

/// An iterator that repeats an element endlessly
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct Repeat<A> {
priv element: A
}
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#[allow(missing_doc)];

use clone::{Clone, DeepClone};
use clone::Clone;
use cmp::{Eq, Ord};
use kinds::Pod;
use mem::size_of;
Expand Down Expand Up @@ -247,7 +247,6 @@ pub trait Bitwise: Bounded
/// may be useful for systems programming.
pub trait Primitive: Pod
+ Clone
+ DeepClone
+ Num
+ NumCast
+ Ord
Expand Down
7 changes: 3 additions & 4 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@

use any::Any;
use clone::Clone;
use clone::DeepClone;
use cmp::{Eq, TotalOrd};
use cmp::{Eq, TotalEq, TotalOrd};
use default::Default;
use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize};
use kinds::Send;
use mem;
use vec;

/// The option type
#[deriving(Clone, DeepClone, Eq, Ord, TotalEq, TotalOrd, Show)]
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show)]
pub enum Option<T> {
/// No value
None,
Expand Down Expand Up @@ -387,7 +386,7 @@ impl<T> Default for Option<T> {
/////////////////////////////////////////////////////////////////////////////

/// An iterator that yields either one or zero elements
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct Item<A> {
priv opt: Option<A>
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/path/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub type RevStrComponents<'a> = Map<'a, &'a [u8], Option<&'a str>,
RevComponents<'a>>;

/// Represents a POSIX file path
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct Path {
priv repr: ~[u8], // assumed to never be empty or contain NULs
priv sepidx: Option<uint> // index of the final separator in repr
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub type RevComponents<'a> = Map<'a, Option<&'a str>, &'a [u8],
//
// The only error condition imposed here is valid utf-8. All other invalid paths are simply
// preserved by the data structure; let the Windows API error out on them.
#[deriving(Clone, DeepClone)]
#[deriving(Clone)]
pub struct Path {
priv repr: ~str, // assumed to never be empty
priv prefix: Option<PathPrefix>,
Expand Down Expand Up @@ -942,7 +942,7 @@ pub fn is_sep_byte_verbatim(u: &u8) -> bool {
}

/// Prefix types for Path
#[deriving(Eq, Clone, DeepClone)]
#[deriving(Eq, Clone)]
pub enum PathPrefix {
/// Prefix `\\?\`, uint is the length of the following component
VerbatimPrefix(uint),
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub use mem::drop;
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, IntoBytes};
pub use c_str::ToCStr;
pub use char::Char;
pub use clone::{Clone, DeepClone};
pub use clone::Clone;
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater, Equiv};
pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
pub use iter::{FromIterator, Extendable};
Expand Down
19 changes: 1 addition & 18 deletions src/libstd/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pointers, and then storing the parent pointers as `Weak` pointers.
*/

use cast::transmute;
use clone::{Clone, DeepClone};
use clone::Clone;
use cmp::{Eq, Ord};
use kinds::marker;
use ops::{Deref, Drop};
Expand Down Expand Up @@ -118,13 +118,6 @@ impl<T> Clone for Rc<T> {
}
}

impl<T: DeepClone> DeepClone for Rc<T> {
#[inline]
fn deep_clone(&self) -> Rc<T> {
Rc::new(self.borrow().deep_clone())
}
}

impl<T: Eq> Eq for Rc<T> {
#[inline(always)]
fn eq(&self, other: &Rc<T>) -> bool { *self.borrow() == *other.borrow() }
Expand Down Expand Up @@ -210,16 +203,6 @@ mod tests {
assert_eq!(y.borrow().with(|v| *v), 20);
}

#[test]
fn test_deep_clone() {
let x = Rc::new(RefCell::new(5));
let y = x.deep_clone();
x.borrow().with_mut(|inner| {
*inner = 20;
});
assert_eq!(y.borrow().with(|v| *v), 5);
}

#[test]
fn test_simple() {
let x = Rc::new(5);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use iter::{Iterator, FromIterator};
use option::{None, Option, Some};

/// `Result` is a type that represents either success (`Ok`) or failure (`Err`).
#[deriving(Clone, DeepClone, Eq, Ord, TotalEq, TotalOrd, Show)]
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show)]
#[must_use]
pub enum Result<T, E> {
/// Contains the success value
Expand Down
Loading

6 comments on commit 438893b

@brson
Copy link
Contributor

@brson brson commented on 438893b Mar 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@bors
Copy link
Contributor

@bors bors commented on 438893b Mar 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 438893b Mar 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pongad/rust/issue_12698 = 438893b into auto

@bors
Copy link
Contributor

@bors bors commented on 438893b Mar 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pongad/rust/issue_12698 = 438893b merged ok, testing candidate = 5f64adc

@bors
Copy link
Contributor

@bors bors commented on 438893b Mar 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 438893b Mar 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 5f64adc

Please sign in to comment.