Skip to content

Commit df2297f

Browse files
committed
---
yaml --- r: 61340 b: refs/heads/try c: cda3ac9 h: refs/heads/master v: v3
1 parent 1163bcd commit df2297f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+732
-632
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
5-
refs/heads/try: 4e4f90d4a0b887c45d1ced359657fbdb23ab2438
5+
refs/heads/try: cda3ac905a56dc6580429eea259143d30a7f3c02
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/cell.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ Similar to a mutable option type, but friendlier.
2121
*/
2222

2323
#[mutable]
24+
#[deriving(Clone)]
2425
pub struct Cell<T> {
2526
priv value: Option<T>
2627
}
2728

29+
impl<T: DeepClone> DeepClone for Cell<T> {
30+
fn deep_clone(&self) -> Cell<T> {
31+
Cell{value: self.value.deep_clone()}
32+
}
33+
}
34+
2835
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
2936
fn eq(&self, other: &Cell<T>) -> bool {
3037
(self.value) == (other.value)

branches/try/src/libcore/clone.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@ by convention implementing the `Clone` trait and calling the
2323
*/
2424

2525
pub trait Clone {
26-
/// Return a deep copy of the owned object tree. Managed boxes are cloned with a shallow copy.
26+
/// Return a deep copy of the owned object tree. Types with shared ownership like managed boxes
27+
/// are cloned with a shallow copy.
2728
fn clone(&self) -> Self;
2829
}
2930

30-
impl Clone for () {
31-
/// Return a copy of the value.
32-
#[inline(always)]
33-
fn clone(&self) -> () { () }
34-
}
35-
36-
impl<T:Clone> Clone for ~T {
31+
impl<T: Clone> Clone for ~T {
3732
/// Return a deep copy of the owned box.
3833
#[inline(always)]
3934
fn clone(&self) -> ~T { ~(**self).clone() }
@@ -54,7 +49,7 @@ impl<T> Clone for @mut T {
5449
macro_rules! clone_impl(
5550
($t:ty) => {
5651
impl Clone for $t {
57-
/// Return a copy of the value.
52+
/// Return a deep copy of the value.
5853
#[inline(always)]
5954
fn clone(&self) -> $t { *self }
6055
}
@@ -77,9 +72,53 @@ clone_impl!(float)
7772
clone_impl!(f32)
7873
clone_impl!(f64)
7974

75+
clone_impl!(())
8076
clone_impl!(bool)
8177
clone_impl!(char)
8278

79+
pub trait DeepClone {
80+
/// Return a deep copy of the object tree. Types with shared ownership are also copied via a
81+
/// deep copy, unlike `Clone`. Note that this is currently unimplemented for managed boxes, as
82+
/// it would need to handle cycles.
83+
fn deep_clone(&self) -> Self;
84+
}
85+
86+
macro_rules! deep_clone_impl(
87+
($t:ty) => {
88+
impl DeepClone for $t {
89+
/// Return a deep copy of the value.
90+
#[inline(always)]
91+
fn deep_clone(&self) -> $t { *self }
92+
}
93+
}
94+
)
95+
96+
impl<T: DeepClone> DeepClone for ~T {
97+
/// Return a deep copy of the owned box.
98+
#[inline(always)]
99+
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }
100+
}
101+
102+
deep_clone_impl!(int)
103+
deep_clone_impl!(i8)
104+
deep_clone_impl!(i16)
105+
deep_clone_impl!(i32)
106+
deep_clone_impl!(i64)
107+
108+
deep_clone_impl!(uint)
109+
deep_clone_impl!(u8)
110+
deep_clone_impl!(u16)
111+
deep_clone_impl!(u32)
112+
deep_clone_impl!(u64)
113+
114+
deep_clone_impl!(float)
115+
deep_clone_impl!(f32)
116+
deep_clone_impl!(f64)
117+
118+
deep_clone_impl!(())
119+
deep_clone_impl!(bool)
120+
deep_clone_impl!(char)
121+
83122
#[test]
84123
fn test_owned_clone() {
85124
let a: ~int = ~5i;

branches/try/src/libcore/option.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use num::Zero;
4949
use old_iter::{BaseIter, MutableIter, ExtendedIter};
5050
use old_iter;
5151
use str::StrSlice;
52+
use clone::DeepClone;
5253

5354
#[cfg(test)] use str;
5455

@@ -59,6 +60,15 @@ pub enum Option<T> {
5960
Some(T),
6061
}
6162

63+
impl<T: DeepClone> DeepClone for Option<T> {
64+
fn deep_clone(&self) -> Option<T> {
65+
match *self {
66+
Some(ref x) => Some(x.deep_clone()),
67+
None => None
68+
}
69+
}
70+
}
71+
6272
impl<T:Ord> Ord for Option<T> {
6373
fn lt(&self, other: &Option<T>) -> bool {
6474
match (self, other) {

branches/try/src/libcore/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use io::{print, println};
2727

2828
/* Reexported types and traits */
2929

30-
pub use clone::Clone;
30+
pub use clone::{Clone, DeepClone};
3131
pub use cmp::{Eq, ApproxEq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater, Equiv};
3232
pub use container::{Container, Mutable, Map, Set};
3333
pub use hash::Hash;

branches/try/src/libcore/to_bytes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B,
458458
b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
459459
}
460460
#[cfg(not(stage0))]
461-
#[inline(always)]
462461
pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B,
463462
lsb0: bool, z: Cb) -> bool {
464463
a.iter_bytes(lsb0, z) && b.iter_bytes(lsb0, z)

branches/try/src/librustc/metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub static tag_mod_impl_trait: uint = 0x47u;
100100
different tags.
101101
*/
102102
pub static tag_item_impl_method: uint = 0x48u;
103-
pub static tag_item_trait_method_explicit_self: uint = 0x4b;
103+
pub static tag_item_trait_method_self_ty: uint = 0x4b;
104104
pub static tag_item_trait_method_self_ty_region: uint = 0x4c;
105105

106106

branches/try/src/librustc/metadata/csearch.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax::ast_map;
2222
use syntax::diagnostic::expect;
2323

2424
pub struct ProvidedTraitMethodInfo {
25-
ty: ty::Method,
25+
ty: ty::method,
2626
def_id: ast::def_id
2727
}
2828

@@ -129,18 +129,17 @@ pub fn get_impls_for_mod(cstore: @mut cstore::CStore, def: ast::def_id,
129129
}
130130

131131
pub fn get_method(tcx: ty::ctxt,
132-
def: ast::def_id) -> ty::Method
132+
def: ast::def_id) -> ty::method
133133
{
134134
let cdata = cstore::get_crate_data(tcx.cstore, def.crate);
135135
decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx)
136136
}
137137

138-
pub fn get_method_name_and_explicit_self(cstore: @mut cstore::CStore,
139-
def: ast::def_id)
140-
-> (ast::ident, ast::explicit_self_)
138+
pub fn get_method_name_and_self_ty(cstore: @mut cstore::CStore,
139+
def: ast::def_id) -> (ast::ident, ast::self_ty_)
141140
{
142141
let cdata = cstore::get_crate_data(cstore, def.crate);
143-
decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node)
142+
decoder::get_method_name_and_self_ty(cstore.intr, cdata, def.node)
144143
}
145144

146145
pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,

branches/try/src/librustc/metadata/decoder.rs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
653653
item, tcx, cdata);
654654
let name = item_name(intr, item);
655655
let arg_tys = match ty::get(ctor_ty).sty {
656-
ty::ty_bare_fn(ref f) => copy f.sig.inputs,
656+
ty::ty_bare_fn(ref f) => f.sig.inputs.map(|a| a.ty),
657657
_ => ~[], // Nullary enum variant.
658658
};
659659
match variant_disr_val(item) {
@@ -670,7 +670,7 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
670670
return infos;
671671
}
672672

673-
fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
673+
fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
674674
fn get_mutability(ch: u8) -> ast::mutability {
675675
match ch as char {
676676
'i' => { ast::m_imm }
@@ -682,11 +682,11 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
682682
}
683683
}
684684

685-
let explicit_self_doc = reader::get_doc(item, tag_item_trait_method_explicit_self);
686-
let string = reader::doc_as_str(explicit_self_doc);
685+
let self_type_doc = reader::get_doc(item, tag_item_trait_method_self_ty);
686+
let string = reader::doc_as_str(self_type_doc);
687687

688-
let explicit_self_kind = string[0];
689-
match explicit_self_kind as char {
688+
let self_ty_kind = string[0];
689+
match self_ty_kind as char {
690690
's' => { return ast::sty_static; }
691691
'v' => { return ast::sty_value; }
692692
'@' => { return ast::sty_box(get_mutability(string[1])); }
@@ -696,7 +696,7 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
696696
return ast::sty_region(None, get_mutability(string[1]));
697697
}
698698
_ => {
699-
fail!("unknown self type code: `%c`", explicit_self_kind as char);
699+
fail!("unknown self type code: `%c`", self_ty_kind as char);
700700
}
701701
}
702702
}
@@ -707,12 +707,12 @@ fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc,
707707
for reader::tagged_docs(item, tag_item_impl_method) |doc| {
708708
let m_did = reader::with_doc_data(doc, |d| parse_def_id(d));
709709
let mth_item = lookup_item(m_did.node, cdata.data);
710-
let explicit_self = get_explicit_self(mth_item);
710+
let self_ty = get_self_ty(mth_item);
711711
rslt.push(@resolve::MethodInfo {
712712
did: translate_def_id(cdata, m_did),
713713
n_tps: item_ty_param_count(mth_item) - base_tps,
714714
ident: item_name(intr, mth_item),
715-
explicit_self: explicit_self});
715+
self_type: self_ty});
716716
}
717717
rslt
718718
}
@@ -748,19 +748,19 @@ pub fn get_impls_for_mod(intr: @ident_interner,
748748
@result
749749
}
750750

751-
pub fn get_method_name_and_explicit_self(
751+
pub fn get_method_name_and_self_ty(
752752
intr: @ident_interner,
753753
cdata: cmd,
754-
id: ast::node_id) -> (ast::ident, ast::explicit_self_)
754+
id: ast::node_id) -> (ast::ident, ast::self_ty_)
755755
{
756756
let method_doc = lookup_item(id, cdata.data);
757757
let name = item_name(intr, method_doc);
758-
let explicit_self = get_explicit_self(method_doc);
759-
(name, explicit_self)
758+
let self_ty = get_self_ty(method_doc);
759+
(name, self_ty)
760760
}
761761

762762
pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
763-
tcx: ty::ctxt) -> ty::Method
763+
tcx: ty::ctxt) -> ty::method
764764
{
765765
let method_doc = lookup_item(id, cdata.data);
766766
let def_id = item_def_id(method_doc, cdata);
@@ -770,20 +770,19 @@ pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
770770
let transformed_self_ty = doc_transformed_self_ty(method_doc, tcx, cdata);
771771
let fty = doc_method_fty(method_doc, tcx, cdata);
772772
let vis = item_visibility(method_doc);
773-
let explicit_self = get_explicit_self(method_doc);
774-
775-
ty::Method::new(
776-
name,
777-
ty::Generics {
773+
let self_ty = get_self_ty(method_doc);
774+
ty::method {
775+
ident: name,
776+
generics: ty::Generics {
778777
type_param_defs: type_param_defs,
779778
region_param: None
780779
},
781-
transformed_self_ty,
782-
fty,
783-
explicit_self,
784-
vis,
785-
def_id
786-
)
780+
transformed_self_ty: transformed_self_ty,
781+
fty: fty,
782+
self_ty: self_ty,
783+
vis: vis,
784+
def_id: def_id
785+
}
787786
}
788787

789788
pub fn get_trait_method_def_ids(cdata: cmd,
@@ -824,20 +823,19 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
824823
};
825824

826825
let transformed_self_ty = doc_transformed_self_ty(mth, tcx, cdata);
827-
let explicit_self = get_explicit_self(mth);
828-
829-
let ty_method = ty::Method::new(
830-
name,
831-
ty::Generics {
826+
let self_ty = get_self_ty(mth);
827+
let ty_method = ty::method {
828+
ident: name,
829+
generics: ty::Generics {
832830
type_param_defs: type_param_defs,
833831
region_param: None
834832
},
835-
transformed_self_ty,
836-
fty,
837-
explicit_self,
838-
ast::public,
839-
did
840-
);
833+
transformed_self_ty: transformed_self_ty,
834+
fty: fty,
835+
self_ty: self_ty,
836+
vis: ast::public,
837+
def_id: did
838+
};
841839
let provided_trait_method_info = ProvidedTraitMethodInfo {
842840
ty: ty_method,
843841
def_id: did

0 commit comments

Comments
 (0)