Skip to content

Commit 6711208

Browse files
committed
---
yaml --- r: 61410 b: refs/heads/try c: f89e00b h: refs/heads/master v: v3
1 parent ed2f4d8 commit 6711208

Some content is hidden

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

70 files changed

+1572
-2149
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: 65b7903ba3aab91c68d09e192f907a68b7308ee4
5+
refs/heads/try: f89e00b3d149d78b8fe21251912d9c7fa78b9f15
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/.swo

-72 KB
Binary file not shown.

branches/try/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ Supported traits for `deriving` are:
15621562

15631563
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
15641564
* Serialization: `Encodable`, `Decodable`. These require `std`.
1565-
* `Clone`, to perform deep copies.
1565+
* `Clone` and `DeepClone`, to perform (deep) copies.
15661566
* `IterBytes`, to iterate over the bytes in a data type.
15671567
* `Rand`, to create a random instance of a data type.
15681568
* `ToStr`, to convert to a string. For a type with this instance,

branches/try/doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,8 +2308,8 @@ enum ABC { A, B, C }
23082308
~~~
23092309

23102310
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
2311-
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `IterBytes`, `Rand` and
2312-
`ToStr`.
2311+
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `DeepClone`,
2312+
`IterBytes`, `Rand` and `ToStr`.
23132313

23142314
# Modules and crates
23152315

branches/try/src/libcore/at_vec.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
149149
* Creates and initializes an immutable managed vector by moving all the
150150
* elements from an owned vector.
151151
*/
152-
pub fn from_owned<T>(v: ~[T]) -> @[T] {
152+
pub fn to_managed_consume<T>(v: ~[T]) -> @[T] {
153153
let mut av = @[];
154154
unsafe {
155155
raw::reserve(&mut av, v.len());
@@ -164,7 +164,7 @@ pub fn from_owned<T>(v: ~[T]) -> @[T] {
164164
* Creates and initializes an immutable managed vector by copying all the
165165
* elements of a slice.
166166
*/
167-
pub fn from_slice<T:Copy>(v: &[T]) -> @[T] {
167+
pub fn to_managed<T:Copy>(v: &[T]) -> @[T] {
168168
from_fn(v.len(), |i| v[i])
169169
}
170170

@@ -304,20 +304,20 @@ mod test {
304304
}
305305

306306
#[test]
307-
fn test_from_owned() {
308-
assert!(from_owned::<int>(~[]) == @[]);
309-
assert!(from_owned(~[true]) == @[true]);
310-
assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
311-
assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
312-
assert!(from_owned(~[~[42]]) == @[~[42]]);
307+
fn test_to_managed_consume() {
308+
assert!(to_managed_consume::<int>(~[]) == @[]);
309+
assert!(to_managed_consume(~[true]) == @[true]);
310+
assert!(to_managed_consume(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
311+
assert!(to_managed_consume(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
312+
assert!(to_managed_consume(~[~[42]]) == @[~[42]]);
313313
}
314314
315315
#[test]
316-
fn test_from_slice() {
317-
assert!(from_slice::<int>([]) == @[]);
318-
assert!(from_slice([true]) == @[true]);
319-
assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
320-
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
321-
assert!(from_slice([@[42]]) == @[@[42]]);
316+
fn test_to_managed() {
317+
assert!(to_managed::<int>([]) == @[]);
318+
assert!(to_managed([true]) == @[true]);
319+
assert!(to_managed([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
320+
assert!(to_managed([@"abc", @"123"]) == @[@"abc", @"123"]);
321+
assert!(to_managed([@[42]]) == @[@[42]]);
322322
}
323323
}

branches/try/src/libcore/clone.rs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ by convention implementing the `Clone` trait and calling the
2222
2323
*/
2424

25+
use core::kinds::Const;
26+
2527
pub trait Clone {
2628
/// Return a deep copy of the owned object tree. Types with shared ownership like managed boxes
2729
/// are cloned with a shallow copy.
@@ -46,6 +48,12 @@ impl<T> Clone for @mut T {
4648
fn clone(&self) -> @mut T { *self }
4749
}
4850

51+
impl<'self, T> Clone for &'self T {
52+
/// Return a shallow copy of the borrowed pointer.
53+
#[inline(always)]
54+
fn clone(&self) -> &'self T { *self }
55+
}
56+
4957
macro_rules! clone_impl(
5058
($t:ty) => {
5159
impl Clone for $t {
@@ -78,11 +86,32 @@ clone_impl!(char)
7886

7987
pub trait DeepClone {
8088
/// 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.
89+
/// deep copy, unlike `Clone`.
8390
fn deep_clone(&self) -> Self;
8491
}
8592

93+
impl<T: DeepClone> DeepClone for ~T {
94+
/// Return a deep copy of the owned box.
95+
#[inline(always)]
96+
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }
97+
}
98+
99+
// FIXME: #6525: should also be implemented for `T: Owned + DeepClone`
100+
impl<T: Const + DeepClone> DeepClone for @T {
101+
/// Return a deep copy of the managed box. The `Const` trait is required to prevent performing
102+
/// a deep clone of a potentially cyclical type.
103+
#[inline(always)]
104+
fn deep_clone(&self) -> @T { @(**self).deep_clone() }
105+
}
106+
107+
// FIXME: #6525: should also be implemented for `T: Owned + DeepClone`
108+
impl<T: Const + DeepClone> DeepClone for @mut T {
109+
/// Return a deep copy of the managed box. The `Const` trait is required to prevent performing
110+
/// a deep clone of a potentially cyclical type.
111+
#[inline(always)]
112+
fn deep_clone(&self) -> @mut T { @mut (**self).deep_clone() }
113+
}
114+
86115
macro_rules! deep_clone_impl(
87116
($t:ty) => {
88117
impl DeepClone for $t {
@@ -93,12 +122,6 @@ macro_rules! deep_clone_impl(
93122
}
94123
)
95124

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-
102125
deep_clone_impl!(int)
103126
deep_clone_impl!(i8)
104127
deep_clone_impl!(i16)
@@ -121,23 +144,39 @@ deep_clone_impl!(char)
121144

122145
#[test]
123146
fn test_owned_clone() {
124-
let a: ~int = ~5i;
147+
let a = ~5i;
125148
let b: ~int = a.clone();
126149
assert!(a == b);
127150
}
128151

129152
#[test]
130153
fn test_managed_clone() {
131-
let a: @int = @5i;
154+
let a = @5i;
132155
let b: @int = a.clone();
133156
assert!(a == b);
134157
}
135158

159+
#[test]
160+
fn test_managed_mut_deep_clone() {
161+
let x = @mut 5i;
162+
let y: @mut int = x.deep_clone();
163+
*x = 20;
164+
assert_eq!(*y, 5);
165+
}
166+
136167
#[test]
137168
fn test_managed_mut_clone() {
138-
let a: @mut int = @mut 5i;
169+
let a = @mut 5i;
139170
let b: @mut int = a.clone();
140171
assert!(a == b);
141172
*b = 10;
142173
assert!(a == b);
143174
}
175+
176+
#[test]
177+
fn test_borrowed_clone() {
178+
let x = 5i;
179+
let y: &int = &x;
180+
let z: &int = (&y).clone();
181+
assert_eq!(*z, 5);
182+
}

branches/try/src/libcore/hashmap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ pub impl <T:Hash + Eq> HashSet<T> {
825825
fn consume(&mut self, f: &fn(T)) {
826826
self.map.consume(|k, _| f(k))
827827
}
828+
829+
fn contains_equiv<Q:Hash + Equiv<T>>(&self, value: &Q) -> bool {
830+
self.map.contains_key_equiv(value)
831+
}
828832
}
829833

830834
#[cfg(test)]

branches/try/src/libcore/os.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,33 @@ pub fn setenv(n: &str, v: &str) {
289289
}
290290
}
291291

292+
/// Remove a variable from the environment entirely
293+
pub fn unsetenv(n: &str) {
294+
#[cfg(unix)]
295+
fn _unsetenv(n: &str) {
296+
unsafe {
297+
do with_env_lock {
298+
do str::as_c_str(n) |nbuf| {
299+
libc::funcs::posix01::unistd::unsetenv(nbuf);
300+
}
301+
}
302+
}
303+
}
304+
#[cfg(windows)]
305+
fn _unsetenv(n: &str) {
306+
unsafe {
307+
do with_env_lock {
308+
use os::win32::as_utf16_p;
309+
do as_utf16_p(n) |nbuf| {
310+
libc::SetEnvironmentVariableW(nbuf, ptr::null());
311+
}
312+
}
313+
}
314+
}
315+
316+
_unsetenv(n);
317+
}
318+
292319
pub fn fdopen(fd: c_int) -> *FILE {
293320
unsafe {
294321
return do as_c_charp("r") |modebuf| {
@@ -1412,7 +1439,7 @@ mod tests {
14121439
use option::Some;
14131440
use option;
14141441
use os::{as_c_charp, env, getcwd, getenv, make_absolute, real_args};
1415-
use os::{remove_file, setenv};
1442+
use os::{remove_file, setenv, unsetenv};
14161443
use os;
14171444
use path::Path;
14181445
use rand::RngUtil;
@@ -1448,6 +1475,14 @@ mod tests {
14481475
assert!(getenv(n) == option::Some(~"VALUE"));
14491476
}
14501477
1478+
#[test]
1479+
fn test_unsetenv() {
1480+
let n = make_rand_name();
1481+
setenv(n, ~"VALUE");
1482+
unsetenv(n);
1483+
assert!(getenv(n) == option::None);
1484+
}
1485+
14511486
#[test]
14521487
#[ignore(cfg(windows))]
14531488
#[ignore]

branches/try/src/libcore/vec.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,23 +2546,29 @@ pub mod raw {
25462546
* would also make any pointers to it invalid.
25472547
*/
25482548
#[inline(always)]
2549-
pub unsafe fn to_ptr<T>(v: &[T]) -> *T {
2550-
let repr: **SliceRepr = transmute(&v);
2551-
transmute(&((**repr).data))
2549+
pub fn to_ptr<T>(v: &[T]) -> *T {
2550+
unsafe {
2551+
let repr: **SliceRepr = transmute(&v);
2552+
transmute(&((**repr).data))
2553+
}
25522554
}
25532555

25542556
/** see `to_ptr()` */
25552557
#[inline(always)]
2556-
pub unsafe fn to_const_ptr<T>(v: &const [T]) -> *const T {
2557-
let repr: **SliceRepr = transmute(&v);
2558-
transmute(&((**repr).data))
2558+
pub fn to_const_ptr<T>(v: &const [T]) -> *const T {
2559+
unsafe {
2560+
let repr: **SliceRepr = transmute(&v);
2561+
transmute(&((**repr).data))
2562+
}
25592563
}
25602564

25612565
/** see `to_ptr()` */
25622566
#[inline(always)]
2563-
pub unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
2564-
let repr: **SliceRepr = transmute(&v);
2565-
transmute(&((**repr).data))
2567+
pub fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
2568+
unsafe {
2569+
let repr: **SliceRepr = transmute(&v);
2570+
transmute(&((**repr).data))
2571+
}
25662572
}
25672573

25682574
/**

branches/try/src/librustc/README.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ ASTs -- are in a separate crate called "syntax", whose files are in
3535
./../libsyntax, where . is the current directory (that is, the parent
3636
directory of front/, middle/, back/, and so on).
3737

38-
The entry-point for the compiler is main() in driver/rustc.rs, and
38+
The entry-point for the compiler is main() in rustc.rc, and
3939
this file sequences the various parts together.
4040

4141

4242
The 3 central data structures:
4343
------------------------------
4444

45-
#1: ../libsyntax/ast.rs defines the AST. The AST is treated as immutable
45+
#1: ./../libsyntax/ast.rs defines the AST. The AST is treated as immutable
4646
after parsing, but it depends on mutable context data structures
4747
(mainly hash maps) to give it meaning.
4848

4949
- Many -- though not all -- nodes within this data structure are
50-
wrapped in the type spanned<T>, meaning that the front-end has
50+
wrapped in the type `spanned<T>`, meaning that the front-end has
5151
marked the input coordinates of that node. The member .node is
5252
the data itself, the member .span is the input location (file,
5353
line, column; both low and high).
@@ -78,7 +78,7 @@ Control and information flow within the compiler:
7878
- main() in rustc.rc assumes control on startup. Options are
7979
parsed, platform is detected, etc.
8080

81-
- libsyntax/parse/parser.rs parses the input files and produces an AST
81+
- ./../libsyntax/parse/parser.rs parses the input files and produces an AST
8282
that represents the input crate.
8383

8484
- Multiple middle-end passes (middle/resolve.rs, middle/typeck.rs)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,14 @@ fn parse_closure_ty(st: @mut PState, conv: conv_did) -> ty::ClosureTy {
470470
let purity = parse_purity(next(st));
471471
let onceness = parse_onceness(next(st));
472472
let region = parse_region(st);
473+
let bounds = parse_bounds(st, conv);
473474
let sig = parse_sig(st, conv);
474475
ty::ClosureTy {
475476
purity: purity,
476477
sigil: sigil,
477478
onceness: onceness,
478479
region: region,
480+
bounds: bounds.builtin_bounds,
479481
sig: sig
480482
}
481483
}
@@ -540,10 +542,10 @@ pub fn parse_type_param_def_data(data: @~[u8], start: uint,
540542

541543
fn parse_type_param_def(st: @mut PState, conv: conv_did) -> ty::TypeParameterDef {
542544
ty::TypeParameterDef {def_id: parse_def(st, NominalType, conv),
543-
bounds: parse_bounds(st, conv)}
545+
bounds: @parse_bounds(st, conv)}
544546
}
545547

546-
fn parse_bounds(st: @mut PState, conv: conv_did) -> @ty::ParamBounds {
548+
fn parse_bounds(st: @mut PState, conv: conv_did) -> ty::ParamBounds {
547549
let mut param_bounds = ty::ParamBounds {
548550
builtin_bounds: ty::EmptyBuiltinBounds(),
549551
trait_bounds: ~[]
@@ -566,7 +568,7 @@ fn parse_bounds(st: @mut PState, conv: conv_did) -> @ty::ParamBounds {
566568
param_bounds.trait_bounds.push(@parse_trait_ref(st, conv));
567569
}
568570
'.' => {
569-
return @param_bounds;
571+
return param_bounds;
570572
}
571573
_ => {
572574
fail!("parse_bounds: bad bounds")

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ fn enc_closure_ty(w: @io::Writer, cx: @ctxt, ft: &ty::ClosureTy) {
380380
enc_purity(w, ft.purity);
381381
enc_onceness(w, ft.onceness);
382382
enc_region(w, cx, ft.region);
383+
let bounds = ty::ParamBounds {builtin_bounds: ft.bounds,
384+
trait_bounds: ~[]};
385+
enc_bounds(w, cx, &bounds);
383386
enc_fn_sig(w, cx, &ft.sig);
384387
}
385388

@@ -392,7 +395,7 @@ fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
392395
enc_ty(w, cx, fsig.output);
393396
}
394397

395-
fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: @ty::ParamBounds) {
398+
fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: &ty::ParamBounds) {
396399
for bs.builtin_bounds.each |bound| {
397400
match bound {
398401
ty::BoundOwned => w.write_char('S'),

branches/try/src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
11081108
dcx.tcx.adjustments.insert(id, adj);
11091109
} else if tag == (c::tag_table_capture_map as uint) {
11101110
let cvars =
1111-
at_vec::from_owned(
1111+
at_vec::to_managed_consume(
11121112
val_dsr.read_to_vec(
11131113
|val_dsr| val_dsr.read_capture_var(xcx)));
11141114
dcx.maps.capture_map.insert(id, cvars);

0 commit comments

Comments
 (0)