summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2010-12-07 11:36:23 +0000
committerPhilipp Haller <hallerp@gmail.com>2010-12-07 11:36:23 +0000
commit0f188e1b47932b05d65d699dba88dd98dd191c17 (patch)
treec95d5e8e5c3c968bfc52172159c70f0120eb344d /src
parentef89729e20aee4f5397792425e344339fe1e7094 (diff)
downloadscala-0f188e1b47932b05d65d699dba88dd98dd191c17.tar.gz
scala-0f188e1b47932b05d65d699dba88dd98dd191c17.tar.bz2
scala-0f188e1b47932b05d65d699dba88dd98dd191c17.zip
Added uniqueness annotations. Review by rytz.
Diffstat (limited to 'src')
-rw-r--r--src/actors/scala/actors/CanReply.scala10
-rw-r--r--src/actors/scala/actors/OutputChannel.scala8
-rw-r--r--src/library/scala/annotation/unique/package.scala31
-rw-r--r--src/library/scala/annotation/unique/peer.scala18
-rw-r--r--src/library/scala/annotation/unique/transient.scala19
-rw-r--r--src/library/scala/annotation/unique/unique.scala17
6 files changed, 96 insertions, 7 deletions
diff --git a/src/actors/scala/actors/CanReply.scala b/src/actors/scala/actors/CanReply.scala
index eaaaef1a29..6e240e4476 100644
--- a/src/actors/scala/actors/CanReply.scala
+++ b/src/actors/scala/actors/CanReply.scala
@@ -9,6 +9,8 @@
package scala.actors
+import scala.annotation.unique.unique
+
/**
* The <code>CanReply</code> trait defines result-bearing message send operations.
*
@@ -27,7 +29,7 @@ trait CanReply[-T, +R] {
* @param msg the message to be sent
* @return the reply
*/
- def !?(msg: T): R
+ def !?(msg: T @unique): R
/**
* Sends <code>msg</code> to this $actor and
@@ -39,7 +41,7 @@ trait CanReply[-T, +R] {
* @return <code>None</code> in case of timeout, otherwise
* <code>Some(x)</code> where <code>x</code> is the reply
*/
- def !?(msec: Long, msg: T): Option[R]
+ def !?(msec: Long, msg: T @unique): Option[R]
/**
* Sends <code>msg</code> to this $actor and
@@ -48,7 +50,7 @@ trait CanReply[-T, +R] {
* @param msg the message to be sent
* @return the future
*/
- def !!(msg: T): Future[R]
+ def !!(msg: T @unique): Future[R]
/**
* Sends <code>msg</code> to this $actor and
@@ -61,6 +63,6 @@ trait CanReply[-T, +R] {
* @param handler the function to be applied to the response
* @return the future
*/
- def !![P](msg: T, handler: PartialFunction[R, P]): Future[P]
+ def !![P](msg: T @unique, handler: PartialFunction[R, P]): Future[P]
}
diff --git a/src/actors/scala/actors/OutputChannel.scala b/src/actors/scala/actors/OutputChannel.scala
index c86cfbad32..3a3a1f8384 100644
--- a/src/actors/scala/actors/OutputChannel.scala
+++ b/src/actors/scala/actors/OutputChannel.scala
@@ -9,6 +9,8 @@
package scala.actors
+import scala.annotation.unique.unique
+
/**
* The <code>OutputChannel</code> trait provides a common interface
* for all channels to which values can be sent.
@@ -24,7 +26,7 @@ trait OutputChannel[-Msg] {
*
* @param msg the message to send
*/
- def !(msg: Msg): Unit
+ def !(msg: Msg @unique): Unit
/**
* Sends <code>msg</code> to this $actor (asynchronous) supplying
@@ -33,14 +35,14 @@ trait OutputChannel[-Msg] {
* @param msg the message to send
* @param replyTo the reply destination
*/
- def send(msg: Msg, replyTo: OutputChannel[Any]): Unit
+ def send(msg: Msg @unique, replyTo: OutputChannel[Any]): Unit
/**
* Forwards <code>msg</code> to this $actor (asynchronous).
*
* @param msg the message to forward
*/
- def forward(msg: Msg): Unit
+ def forward(msg: Msg @unique): Unit
/**
* Returns the <code>Actor</code> that is receiving from this $actor.
diff --git a/src/library/scala/annotation/unique/package.scala b/src/library/scala/annotation/unique/package.scala
new file mode 100644
index 0000000000..a57a2bdfda
--- /dev/null
+++ b/src/library/scala/annotation/unique/package.scala
@@ -0,0 +1,31 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.annotation
+
+/**
+ * An object that provides methods for capturing unique references, and
+ * for accessing unique fields.
+ *
+ * @author Philipp Haller
+ * @since 2.9
+ */
+package object unique {
+
+ trait Captured[A] {
+ def captured: A
+ def capturedBy[B](other: B): A = captured
+ }
+
+ implicit def mkCaptured[A](x: A) = new Captured[A] {
+ def captured: A = x
+ }
+
+ def swap[A, B <: A](to: A, from: B): A = to
+
+}
diff --git a/src/library/scala/annotation/unique/peer.scala b/src/library/scala/annotation/unique/peer.scala
new file mode 100644
index 0000000000..9159fd318c
--- /dev/null
+++ b/src/library/scala/annotation/unique/peer.scala
@@ -0,0 +1,18 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.annotation.unique
+
+/**
+ * An annotation that indicates that the annotated parameter is in the
+ * same region as the parameter that is the argument of the annotation.
+ *
+ * @author Philipp Haller
+ * @since 2.9
+ */
+final class peer(x: AnyRef) extends annotation.StaticAnnotation
diff --git a/src/library/scala/annotation/unique/transient.scala b/src/library/scala/annotation/unique/transient.scala
new file mode 100644
index 0000000000..95f30758bb
--- /dev/null
+++ b/src/library/scala/annotation/unique/transient.scala
@@ -0,0 +1,19 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.annotation.unique
+
+/**
+ * An annotation that indicates that the annotated parameter is transient.
+ * A transient parameter is borrowed in the sense that it is unique but it
+ * cannot be consumed.
+ *
+ * @author Philipp Haller
+ * @since 2.9
+ */
+final class transient extends annotation.StaticAnnotation
diff --git a/src/library/scala/annotation/unique/unique.scala b/src/library/scala/annotation/unique/unique.scala
new file mode 100644
index 0000000000..d2bf88a908
--- /dev/null
+++ b/src/library/scala/annotation/unique/unique.scala
@@ -0,0 +1,17 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.annotation.unique
+
+/**
+ * An annotation that indicates that the annotated parameter or field is unique.
+ *
+ * @author Philipp Haller
+ * @since 2.9
+ */
+final class unique extends annotation.StaticAnnotation