about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Holk <eric.holk@gmail.com>2012-05-22 14:10:32 -0700
committerEric Holk <eric.holk@gmail.com>2012-05-22 14:10:32 -0700
commit0b2f2cabbe3fbe6e18cbf0f8a174b7d4789fc938 (patch)
treece84fbb044a908ff5c98fd1fa0e6990159126177 /src
parentf213c1f3a817ba2c0a43c0b27215146b7a279f65 (diff)
downloadrust-0b2f2cabbe3fbe6e18cbf0f8a174b7d4789fc938.tar.gz
rust-0b2f2cabbe3fbe6e18cbf0f8a174b7d4789fc938.zip
Send is no longer a subkind of copy. This allows for sendable, but non-copyable resources. Closes #2420.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/future.rs2
-rw-r--r--src/libstd/timer.rs6
-rw-r--r--src/rustc/middle/kind.rs10
-rw-r--r--src/rustc/middle/ty.rs12
-rw-r--r--src/rustdoc/fold.rs4
-rw-r--r--src/test/compile-fail/kindck-nonsendable-2.rs17
-rw-r--r--src/test/compile-fail/pinned-deep-copy.rs16
-rw-r--r--src/test/run-pass/alignment-gep-tup-like-2.rs2
-rw-r--r--src/test/run-pass/generic-alias-unique.rs2
-rw-r--r--src/test/run-pass/send-resource.rs20
10 files changed, 43 insertions, 48 deletions
diff --git a/src/libcore/future.rs b/src/libcore/future.rs
index ba11138d9ae..e0321b45287 100644
--- a/src/libcore/future.rs
+++ b/src/libcore/future.rs
@@ -28,7 +28,7 @@ enum future<A> = {
 };
 
 #[doc = "Methods on the `future` type"]
-impl future<A:send> for future<A> {
+impl future<A:copy send> for future<A> {
 
     fn get() -> A {
         #[doc = "Get the value of the future"];
diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs
index 524accf6f1a..cf2c10aa998 100644
--- a/src/libstd/timer.rs
+++ b/src/libstd/timer.rs
@@ -20,7 +20,7 @@ for *at least* that period of time.
 * ch - a channel of type T to send a `val` on
 * val - a value of type T to send over the provided `ch`
 "]
-fn delayed_send<T: send>(msecs: uint, ch: comm::chan<T>, val: T) {
+fn delayed_send<T: copy send>(msecs: uint, ch: comm::chan<T>, val: T) {
     task::spawn() {||
         unsafe {
             let timer_done_po = comm::port::<()>();
@@ -94,7 +94,9 @@ An `option<T>` representing the outcome of the call. If the call `recv`'d on
 the provided port in the allotted timeout period, then the result will be a
 `some(T)`. If not, then `none` will be returned.
 "]
-fn recv_timeout<T: send>(msecs: uint, wait_po: comm::port<T>) -> option<T> {
+fn recv_timeout<T: copy send>(msecs: uint, wait_po: comm::port<T>)
+    -> option<T> {
+
     let timeout_po = comm::port::<()>();
     let timeout_ch = comm::chan(timeout_po);
     delayed_send(msecs, timeout_ch, ());
diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs
index e7c318b7da5..effa593109c 100644
--- a/src/rustc/middle/kind.rs
+++ b/src/rustc/middle/kind.rs
@@ -24,10 +24,12 @@ import freevars::freevar_entry;
 // types.
 
 fn kind_to_str(k: kind) -> str {
-    if k == kind_sendable() { "sendable" }
-    else if k == kind_copyable() { "copyable" }
-    else if k == kind_noncopyable() { "noncopyable" }
-    else { fail "unknown kind" }
+    alt (ty::kind_can_be_copied(k), ty::kind_can_be_sent(k)) {
+      (false, false) { "noncopyable" }
+      (false, true)  { "sendable" }
+      (true,  false) { "copyable" }
+      (true,  true)  { "copy-sendable" }
+    }
 }
 
 type rval_map = std::map::hashmap<node_id, ()>;
diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs
index 998dc9d5951..52cee2fd07b 100644
--- a/src/rustc/middle/ty.rs
+++ b/src/rustc/middle/ty.rs
@@ -425,9 +425,9 @@ fn param_bounds_to_kind(bounds: param_bounds) -> kind {
     for vec::each(*bounds) {|bound|
         alt bound {
           bound_copy {
-            if kind != kind_sendable() { kind = kind_copyable(); }
+            kind = lower_kind(kind, kind_copyable());
           }
-          bound_send { kind = kind_sendable(); }
+          bound_send { kind = lower_kind(kind, kind_send_only()); }
           _ {}
         }
     }
@@ -1277,6 +1277,10 @@ fn kind_sendable() -> kind {
     kind_(KIND_MASK_COPY | KIND_MASK_SEND)
 }
 
+fn kind_send_only() -> kind {
+    kind_(KIND_MASK_SEND)
+}
+
 // Using these query functons is preferable to direct comparison or matching
 // against the kind constants, as we may modify the kind hierarchy in the
 // future.
@@ -1303,7 +1307,7 @@ fn kind_lteq(a: kind, b: kind) -> bool {
 }
 
 fn lower_kind(a: kind, b: kind) -> kind {
-    if kind_lteq(a, b) { a } else { b }
+    kind_(*a | *b)
 }
 
 #[test]
@@ -1402,7 +1406,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
         }
         lowest
       }
-      ty_res(did, inner, tps) { kind_noncopyable() }
+      ty_res(did, inner, tps) { kind_send_only() }
       ty_param(_, did) {
           param_bounds_to_kind(cx.ty_param_bounds.get(did.node))
       }
diff --git a/src/rustdoc/fold.rs b/src/rustdoc/fold.rs
index 87b9d85637c..b4921771e04 100644
--- a/src/rustdoc/fold.rs
+++ b/src/rustdoc/fold.rs
@@ -85,7 +85,7 @@ fn mk_fold<T:copy>(
     })
 }
 
-fn default_any_fold<T:send>(ctxt: T) -> fold<T> {
+fn default_any_fold<T:send copy>(ctxt: T) -> fold<T> {
     mk_fold(
         ctxt,
         {|f, d| default_seq_fold_doc(f, d)},
@@ -121,7 +121,7 @@ fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
     )
 }
 
-fn default_par_fold<T:send>(ctxt: T) -> fold<T> {
+fn default_par_fold<T:send copy>(ctxt: T) -> fold<T> {
     mk_fold(
         ctxt,
         {|f, d| default_seq_fold_doc(f, d)},
diff --git a/src/test/compile-fail/kindck-nonsendable-2.rs b/src/test/compile-fail/kindck-nonsendable-2.rs
deleted file mode 100644
index 3e5a501e691..00000000000
--- a/src/test/compile-fail/kindck-nonsendable-2.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-fn foo(_x: r) {}
-
-resource r(_x: ()) {}
-
-fn main() {
-    let x = r(());
-    let _ = fn~() {
-        // Error even though this is the last use:
-        foo(x); //! ERROR not a sendable value
-    };
-
-    let x = r(());
-    let _ = fn@() {
-        // OK in fn@ because this is the last use:
-        foo(x);
-    };
-}
\ No newline at end of file
diff --git a/src/test/compile-fail/pinned-deep-copy.rs b/src/test/compile-fail/pinned-deep-copy.rs
deleted file mode 100644
index 1a07b3f1de0..00000000000
--- a/src/test/compile-fail/pinned-deep-copy.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-// error-pattern: copying a noncopyable value
-
-resource r(i: @mut int) {
-    *i = *i + 1;
-}
-
-fn main() {
-    let i = @mut 0;
-    {
-        // Can't do this copy
-        let x = ~~~{y: r(i)};
-        let z = x;
-        log(debug, x);
-    }
-    log(error, *i);
-}
\ No newline at end of file
diff --git a/src/test/run-pass/alignment-gep-tup-like-2.rs b/src/test/run-pass/alignment-gep-tup-like-2.rs
index 641aceb9b16..ab599a44c0b 100644
--- a/src/test/run-pass/alignment-gep-tup-like-2.rs
+++ b/src/test/run-pass/alignment-gep-tup-like-2.rs
@@ -13,7 +13,7 @@ fn make_cycle<A:copy>(a: A) {
     g.rec = some(g);
 }
 
-fn f<A:send,B:send>(a: A, b: B) -> fn@() -> (A, B) {
+fn f<A:send copy, B:send copy>(a: A, b: B) -> fn@() -> (A, B) {
     fn@() -> (A, B) { (a, b) }
 }
 
diff --git a/src/test/run-pass/generic-alias-unique.rs b/src/test/run-pass/generic-alias-unique.rs
index 0af9855de0d..4d2811da7b1 100644
--- a/src/test/run-pass/generic-alias-unique.rs
+++ b/src/test/run-pass/generic-alias-unique.rs
@@ -1,6 +1,6 @@
 
 
-fn id<T: send>(t: T) -> T { ret t; }
+fn id<T: copy send>(t: T) -> T { ret t; }
 
 fn main() {
     let expected = ~100;
diff --git a/src/test/run-pass/send-resource.rs b/src/test/run-pass/send-resource.rs
new file mode 100644
index 00000000000..666f253c9a1
--- /dev/null
+++ b/src/test/run-pass/send-resource.rs
@@ -0,0 +1,20 @@
+import task::*;
+import comm::*;
+
+resource test(_f: int) {
+    // Do nothing
+}
+
+fn main() {
+    let p = port();
+    let c = chan(p);
+
+    spawn() {||
+        let p = port();
+        c.send(chan(p));
+
+        let _r = p.recv();
+    }
+
+    p.recv().send(test(42));
+}
\ No newline at end of file