about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-07-11 15:00:40 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-07-17 15:46:43 -0700
commitdb020ab63cd51dd4a25cba2d00117f016128762b (patch)
tree2b6f1e99ba4356f3e3bf5338332c278d2a85109b /src/libcore
parentb5729bd60095fb5ca884936775e031cf19900760 (diff)
rustc: Implement and enforce instance coherence
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/core.rs14
-rw-r--r--src/libcore/int-template.rs2
-rw-r--r--src/libcore/iter-trait.rs3
-rw-r--r--src/libcore/iter.rs10
-rw-r--r--src/libcore/option.rs1
-rw-r--r--src/libcore/pipes.rs6
-rw-r--r--src/libcore/ptr.rs1
-rw-r--r--src/libcore/str.rs4
-rw-r--r--src/libcore/uint-template.rs1
-rw-r--r--src/libcore/vec.rs30
10 files changed, 64 insertions, 8 deletions
diff --git a/src/libcore/core.rs b/src/libcore/core.rs
index c70be013fb7..07dac5270b0 100644
--- a/src/libcore/core.rs
+++ b/src/libcore/core.rs
@@ -5,12 +5,15 @@
 import option::{some, none};
 import option = option::option;
 import path = path::path;
-import str::extensions;
 import tuple::extensions;
+import str::{extensions, str_slice, unique_str};
 import vec::extensions;
+import vec::{const_vector, copyable_vector, immutable_vector};
+import vec::{immutable_copyable_vector, iter_trait_extensions, vec_concat};
+import iter::{base_iter, extended_iter, copyable_iter, times};
 import option::extensions;
 import option_iter::extensions;
-import ptr::extensions;
+import ptr::{extensions, ptr};
 import rand::extensions;
 import result::extensions;
 import int::{num, times};
@@ -26,11 +29,18 @@ import u64::{num, times};
 import float::num;
 import f32::num;
 import f64::num;
+import num::num;
 
 export path, option, some, none, unreachable;
 export extensions;
 // The following exports are the extension impls for numeric types
 export num, times;
+// The following exports are the common traits
+export str_slice, unique_str;
+export const_vector, copyable_vector, immutable_vector;
+export immutable_copyable_vector, iter_trait_extensions, vec_concat;
+export base_iter, copyable_iter, extended_iter;
+export ptr;
 
 // Export the log levels as global constants. Higher levels mean
 // more-verbosity. Error is the bottom level, default logging level is
diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs
index 983d1b9968f..d9fb3dae846 100644
--- a/src/libcore/int-template.rs
+++ b/src/libcore/int-template.rs
@@ -233,6 +233,7 @@ fn test_ifaces() {
 
 #[test]
 fn test_times() {
+    import iter::times;
     let ten = 10 as T;
     let mut accum = 0;
     for ten.times { accum += 1; }
@@ -243,5 +244,6 @@ fn test_times() {
 #[should_fail]
 #[ignore(cfg(windows))]
 fn test_times_negative() {
+    import iter::times;
     for (-10).times { log(error, ~"nope!"); }
 }
diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs
index 80b81753af8..e31824d066d 100644
--- a/src/libcore/iter-trait.rs
+++ b/src/libcore/iter-trait.rs
@@ -8,6 +8,9 @@ export extensions;
 impl extensions<A> of iter::base_iter<A> for IMPL_T<A> {
     fn each(blk: fn(A) -> bool) { EACH(self, blk) }
     fn size_hint() -> option<uint> { SIZE_HINT(self) }
+}
+
+impl extensions<A> of iter::extended_iter<A> for IMPL_T<A> {
     fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) }
     fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
     fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index e2a321cde23..2e0c778cd5a 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -3,6 +3,16 @@ iface base_iter<A> {
     fn size_hint() -> option<uint>;
 }
 
+trait extended_iter<A> {
+    fn eachi(blk: fn(uint, A) -> bool);
+    fn all(blk: fn(A) -> bool) -> bool;
+    fn any(blk: fn(A) -> bool) -> bool;
+    fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B;
+    fn contains(x: A) -> bool;
+    fn count(x: A) -> uint;
+    fn position(f: fn(A) -> bool) -> option<uint>;
+}
+
 iface times {
     fn times(it: fn() -> bool);
 }
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index dabfa04ef24..2b9794987ee 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -92,6 +92,7 @@ pure fn iter<T>(opt: option<T>, f: fn(T)) {
     alt opt { none { } some(t) { f(t); } }
 }
 
+#[inline(always)]
 pure fn unwrap<T>(-opt: option<T>) -> T {
     /*!
      * Moves a value out of an option type and returns it.
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index 13a90ac7ae5..33f5fe958a5 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -578,7 +578,11 @@ impl<T: send> of selectable for pipes::port<T> {
 
 type shared_chan<T: send> = arc::exclusive<pipes::chan<T>>;
 
-impl chan<T: send> for shared_chan<T> {
+trait send_on_shared_chan<T> {
+    fn send(+x: T);
+}
+
+impl chan<T: send> of send_on_shared_chan<T> for shared_chan<T> {
     fn send(+x: T) {
         let mut xx = some(x);
         do self.with |_c, chan| {
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 178a68a1c65..ba98fb3c119 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -14,6 +14,7 @@ export memset;
 export buf_len;
 export position;
 export extensions;
+export ptr;
 
 import libc::{c_void, size_t};
 
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index cc5ae30268d..7e83e7aa0ee 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -106,7 +106,9 @@ export
    escape_unicode,
 
    unsafe,
-   extensions;
+   extensions,
+   str_slice,
+   unique_str;
 
 #[abi = "cdecl"]
 extern mod rustrt {
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index 7c4244efd9b..4f35f1a8756 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -278,6 +278,7 @@ fn to_str_radix17() {
 
 #[test]
 fn test_times() {
+    import iter::times;
     let ten = 10 as T;
     let mut accum = 0;
     for ten.times { accum += 1; }
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 60e3373fdbe..1dd4ef5ae43 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -85,6 +85,12 @@ export unpack_const_slice;
 export unsafe;
 export u8;
 export extensions;
+export const_vector;
+export copyable_vector;
+export immutable_vector;
+export immutable_copyable_vector;
+export iter_trait_extensions;
+export vec_concat;
 
 #[abi = "cdecl"]
 extern mod rustrt {
@@ -179,11 +185,12 @@ pure fn len<T>(&&v: &[const T]) -> uint {
  * Creates an immutable vector of size `n_elts` and initializes the elements
  * to the value returned by the function `op`.
  */
-pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> ~[T] {
+pure fn from_fn<T: copy>(n_elts: uint, op: init_op<T>) -> ~[T] {
     let mut v = ~[];
     unchecked{reserve(v, n_elts);}
     let mut i: uint = 0u;
-    while i < n_elts unsafe { push(v, op(i)); i += 1u; }
+    while i < n_elts unsafe { ref_set(v, i, op(i)); i += 1u; }
+    unsafe { unsafe::set_len(v, n_elts); }
     ret v;
 }
 
@@ -197,8 +204,9 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
     let mut v = ~[];
     unchecked{reserve(v, n_elts)}
     let mut i: uint = 0u;
-    unsafe { // because push is impure
-        while i < n_elts { push(v, t); i += 1u; }
+    unsafe { // because ref_set is unsafe
+        while i < n_elts { ref_set(v, i, t); i += 1u; }
+        unsafe { unsafe::set_len(v, n_elts); }
     }
     ret v;
 }
@@ -469,6 +477,16 @@ unsafe fn ref<T: copy>(v: &[const T], i: uint) -> T {
 }
 
 #[inline(always)]
+unsafe fn ref_set<T: copy>(v: &[mut T], i: uint, +val: T) {
+    let mut box = some(val);
+    do unpack_mut_slice(v) |p, _len| {
+        let mut box2 = none;
+        box2 <-> box;
+        rusti::move_val_init(*ptr::mut_offset(p, i), option::unwrap(box2));
+    }
+}
+
+#[inline(always)]
 fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
     reserve(v, v.len() + rhs.len());
 
@@ -1591,6 +1609,9 @@ mod u8 {
 impl extensions/&<A> of iter::base_iter<A> for &[const A] {
     fn each(blk: fn(A) -> bool) { each(self, blk) }
     fn size_hint() -> option<uint> { some(len(self)) }
+}
+
+impl extensions/&<A> of iter::extended_iter<A> for &[const A] {
     fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) }
     fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
     fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
@@ -1599,6 +1620,7 @@ impl extensions/&<A> of iter::base_iter<A> for &[const A] {
     }
     fn contains(x: A) -> bool { iter::contains(self, x) }
     fn count(x: A) -> uint { iter::count(self, x) }
+    fn position(f: fn(A) -> bool) -> option<uint> { iter::position(self, f) }
 }
 
 trait iter_trait_extensions<A> {