Skip to content

Commit bbc6155

Browse files
committed
---
yaml --- r: 152137 b: refs/heads/try2 c: 7889c95 h: refs/heads/master i: 152135: 11de71b v: v3
1 parent 5bfc178 commit bbc6155

Some content is hidden

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

81 files changed

+1247
-1391
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3a105464fbdf5ba9df7c97eaecffe9f8479f91b0
8+
refs/heads/try2: 7889c951240624b22cc4c9b87f2852322b0b716c
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ config.mk
6060
/rt/
6161
/rustllvm/
6262
/test/
63+
/build
6364
/inst/
6465
/mingw-build/
6566
src/.DS_Store

branches/try2/mk/crates.mk

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ DEPS_core :=
6060
DEPS_rlibc :=
6161
DEPS_alloc := core libc native:jemalloc
6262
DEPS_debug := std
63-
DEPS_std := core rand libc alloc native:rustrt native:backtrace
63+
DEPS_std := core libc alloc native:rustrt native:backtrace
6464
DEPS_graphviz := std
65-
DEPS_green := std native:context_switch
65+
DEPS_green := std rand native:context_switch
6666
DEPS_rustuv := std native:uv native:uv_support
6767
DEPS_native := std
6868
DEPS_syntax := std term serialize collections log fmt_macros debug
@@ -77,16 +77,16 @@ DEPS_glob := std
7777
DEPS_serialize := std collections log
7878
DEPS_term := std collections log
7979
DEPS_semver := std
80-
DEPS_uuid := std serialize
80+
DEPS_uuid := std serialize rand
8181
DEPS_sync := std alloc
8282
DEPS_getopts := std
83-
DEPS_collections := std debug
83+
DEPS_collections := std rand debug
8484
DEPS_fourcc := syntax std
8585
DEPS_hexfloat := syntax std
86-
DEPS_num := std
86+
DEPS_num := std rand
8787
DEPS_test := std collections getopts serialize term time regex
8888
DEPS_time := std serialize sync
89-
DEPS_rand := core
89+
DEPS_rand := std
9090
DEPS_url := std collections
9191
DEPS_workcache := std serialize collections log
9292
DEPS_log := std sync
@@ -104,7 +104,6 @@ TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
104104
ONLY_RLIB_core := 1
105105
ONLY_RLIB_rlibc := 1
106106
ONLY_RLIB_alloc := 1
107-
ONLY_RLIB_rand := 1
108107

109108
################################################################################
110109
# You should not need to edit below this line

branches/try2/src/doc/guide-tasks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,10 @@ Here is a small example showing how to use Arcs. We wish to run concurrently sev
329329
a single large vector of floats. Each task needs the full vector to perform its duty.
330330

331331
~~~
332+
extern crate rand;
332333
extern crate sync;
333334
334335
use sync::Arc;
335-
use std::rand;
336336
337337
fn pnorm(nums: &[f64], p: uint) -> f64 {
338338
nums.iter().fold(0.0, |a, b| a + b.powf(p as f64)).powf(1.0 / (p as f64))
@@ -358,7 +358,7 @@ created by the line
358358

359359
~~~
360360
# extern crate sync;
361-
# use std::rand;
361+
# extern crate rand;
362362
# use sync::Arc;
363363
# fn main() {
364364
# let numbers = Vec::from_fn(1000000, |_| rand::random::<f64>());
@@ -372,7 +372,7 @@ reference to the underlying vector as if it were local.
372372

373373
~~~
374374
# extern crate sync;
375-
# use std::rand;
375+
# extern crate rand;
376376
# use sync::Arc;
377377
# fn pnorm(nums: &[f64], p: uint) -> f64 { 4.0 }
378378
# fn main() {

branches/try2/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ let ys = xs;
11121112
11131113
xs = Nil;
11141114
1115-
// `xs` can be used again
1115+
// `xs` can't be used again
11161116
~~~
11171117

11181118
A destructor call will only occur for a variable that has not been moved from,

branches/try2/src/liballoc/arc.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ impl<T: Send + Share + Clone> Arc<T> {
152152
#[inline]
153153
#[experimental]
154154
pub fn make_unique<'a>(&'a mut self) -> &'a mut T {
155-
if self.inner().strong.load(atomics::SeqCst) != 1 {
155+
// Note that we hold a strong reference, which also counts as
156+
// a weak reference, so we only clone if there is an
157+
// additional reference of either kind.
158+
if self.inner().strong.load(atomics::SeqCst) != 1 ||
159+
self.inner().weak.load(atomics::SeqCst) != 1 {
156160
*self = Arc::new(self.deref().clone())
157161
}
158162
// This unsafety is ok because we're guaranteed that the pointer
@@ -356,6 +360,20 @@ mod tests {
356360
assert!(*cow1 == *cow2);
357361
}
358362

363+
#[test]
364+
fn test_cowarc_clone_weak() {
365+
let mut cow0 = Arc::new(75u);
366+
let cow1_weak = cow0.downgrade();
367+
368+
assert!(75 == *cow0);
369+
assert!(75 == *cow1_weak.upgrade().unwrap());
370+
371+
*cow0.make_unique() += 1;
372+
373+
assert!(76 == *cow0);
374+
assert!(cow1_weak.upgrade().is_none());
375+
}
376+
359377
#[test]
360378
fn test_live() {
361379
let x = Arc::new(5);

branches/try2/src/liballoc/rc.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,31 @@ impl<T> Rc<T> {
8686
}
8787
}
8888

89+
impl<T: Clone> Rc<T> {
90+
/// Acquires a mutable pointer to the inner contents by guaranteeing that
91+
/// the reference count is one (no sharing is possible).
92+
///
93+
/// This is also referred to as a copy-on-write operation because the inner
94+
/// data is cloned if the reference count is greater than one.
95+
#[inline]
96+
#[experimental]
97+
pub fn make_unique<'a>(&'a mut self) -> &'a mut T {
98+
// Note that we hold a strong reference, which also counts as
99+
// a weak reference, so we only clone if there is an
100+
// additional reference of either kind.
101+
if self.strong() != 1 || self.weak() != 1 {
102+
*self = Rc::new(self.deref().clone())
103+
}
104+
// This unsafety is ok because we're guaranteed that the pointer
105+
// returned is the *only* pointer that will ever be returned to T. Our
106+
// reference count is guaranteed to be 1 at this point, and we required
107+
// the Rc itself to be `mut`, so we're returning the only possible
108+
// reference to the inner data.
109+
let inner = unsafe { &mut *self._ptr };
110+
&mut inner.value
111+
}
112+
}
113+
89114
impl<T> Deref<T> for Rc<T> {
90115
/// Borrow the value contained in the reference-counted box
91116
#[inline(always)]
@@ -234,6 +259,7 @@ impl<T> RcBoxPtr<T> for Weak<T> {
234259
}
235260

236261
#[cfg(test)]
262+
#[allow(experimental)]
237263
mod tests {
238264
use super::{Rc, Weak};
239265
use std::cell::RefCell;
@@ -304,4 +330,66 @@ mod tests {
304330

305331
// hopefully we don't double-free (or leak)...
306332
}
333+
334+
#[test]
335+
fn test_cowrc_clone_make_unique() {
336+
let mut cow0 = Rc::new(75u);
337+
let mut cow1 = cow0.clone();
338+
let mut cow2 = cow1.clone();
339+
340+
assert!(75 == *cow0.make_unique());
341+
assert!(75 == *cow1.make_unique());
342+
assert!(75 == *cow2.make_unique());
343+
344+
*cow0.make_unique() += 1;
345+
*cow1.make_unique() += 2;
346+
*cow2.make_unique() += 3;
347+
348+
assert!(76 == *cow0);
349+
assert!(77 == *cow1);
350+
assert!(78 == *cow2);
351+
352+
// none should point to the same backing memory
353+
assert!(*cow0 != *cow1);
354+
assert!(*cow0 != *cow2);
355+
assert!(*cow1 != *cow2);
356+
}
357+
358+
#[test]
359+
fn test_cowrc_clone_unique2() {
360+
let mut cow0 = Rc::new(75u);
361+
let cow1 = cow0.clone();
362+
let cow2 = cow1.clone();
363+
364+
assert!(75 == *cow0);
365+
assert!(75 == *cow1);
366+
assert!(75 == *cow2);
367+
368+
*cow0.make_unique() += 1;
369+
370+
assert!(76 == *cow0);
371+
assert!(75 == *cow1);
372+
assert!(75 == *cow2);
373+
374+
// cow1 and cow2 should share the same contents
375+
// cow0 should have a unique reference
376+
assert!(*cow0 != *cow1);
377+
assert!(*cow0 != *cow2);
378+
assert!(*cow1 == *cow2);
379+
}
380+
381+
#[test]
382+
fn test_cowrc_clone_weak() {
383+
let mut cow0 = Rc::new(75u);
384+
let cow1_weak = cow0.downgrade();
385+
386+
assert!(75 == *cow0);
387+
assert!(75 == *cow1_weak.upgrade().unwrap());
388+
389+
*cow0.make_unique() += 1;
390+
391+
assert!(76 == *cow0);
392+
assert!(cow1_weak.upgrade().is_none());
393+
}
394+
307395
}

branches/try2/src/libcollections/bitv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,8 @@ mod tests {
980980
use bitv;
981981

982982
use std::uint;
983-
use std::rand;
984-
use std::rand::Rng;
983+
use rand;
984+
use rand::Rng;
985985

986986
static BENCH_BITS : uint = 1 << 14;
987987

branches/try2/src/libcollections/deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub mod bench {
4444
extern crate test;
4545
use self::test::Bencher;
4646
use std::container::MutableMap;
47-
use std::rand;
48-
use std::rand::Rng;
47+
use rand;
48+
use rand::Rng;
4949

5050
pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
5151
map: &mut M,

branches/try2/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ mod tests {
610610
extern crate test;
611611
use self::test::Bencher;
612612
use deque::Deque;
613-
use std::rand;
613+
use rand;
614614
use super::{DList, Node, ListInsertion};
615615

616616
pub fn check_links<T>(list: &DList<T>) {

branches/try2/src/libcollections/hashmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use std::iter::{range, range_inclusive};
2424
use std::mem::replace;
2525
use std::num;
2626
use std::option::{Option, Some, None};
27-
use std::rand;
28-
use std::rand::Rng;
27+
use rand;
28+
use rand::Rng;
2929
use std::result::{Ok, Err};
3030
use std::slice::ImmutableVector;
3131

branches/try2/src/libcollections/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#![deny(deprecated_owned_vector)]
2626

27+
extern crate rand;
2728
extern crate debug;
2829

2930
#[cfg(test)] extern crate test;

branches/try2/src/libcollections/treemap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,8 @@ impl<T: TotalOrd> Extendable<T> for TreeSet<T> {
10001000
mod test_treemap {
10011001
use super::{TreeMap, TreeNode};
10021002

1003-
use std::rand::Rng;
1004-
use std::rand;
1003+
use rand::Rng;
1004+
use rand;
10051005

10061006
#[test]
10071007
fn find_empty() {

branches/try2/src/libcollections/trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ mod test_map {
915915
mod bench_map {
916916
extern crate test;
917917
use super::TrieMap;
918-
use std::rand::{weak_rng, Rng};
918+
use rand::{weak_rng, Rng};
919919
use self::test::Bencher;
920920

921921
#[bench]

branches/try2/src/libcore/any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mod tests {
119119
use prelude::*;
120120
use super::*;
121121
use realstd::owned::{Box, AnyOwnExt};
122-
use realstd::str::Str;
122+
use realstd::str::{Str, StrAllocating};
123123

124124
#[deriving(Eq, Show)]
125125
struct Test;

branches/try2/src/libcore/char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ mod test {
607607
use slice::ImmutableVector;
608608
use option::{Some, None};
609609
use realstd::string::String;
610-
use realstd::str::Str;
610+
use realstd::str::{Str, StrAllocating};
611611

612612
#[test]
613613
fn test_is_lowercase() {

branches/try2/src/libcore/fmt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
596596
#[cfg(test)]
597597
pub fn format(args: &Arguments) -> ::realstd::string::String {
598598
use str;
599+
use realstd::str::StrAllocating;
599600
use realstd::io::MemWriter;
600601

601602
fn mywrite<T: ::realstd::io::Writer>(t: &mut T, b: &[u8]) {

0 commit comments

Comments
 (0)