diff options
-rw-r--r-- | src/actors/scala/actors/CanReply.scala | 10 | ||||
-rw-r--r-- | src/actors/scala/actors/OutputChannel.scala | 8 | ||||
-rw-r--r-- | src/library/scala/annotation/unique/package.scala | 31 | ||||
-rw-r--r-- | src/library/scala/annotation/unique/peer.scala | 18 | ||||
-rw-r--r-- | src/library/scala/annotation/unique/transient.scala | 19 | ||||
-rw-r--r-- | src/library/scala/annotation/unique/unique.scala | 17 | ||||
-rw-r--r-- | test/files/jvm/replyablereactor4.scala | 4 |
7 files changed, 98 insertions, 9 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 diff --git a/test/files/jvm/replyablereactor4.scala b/test/files/jvm/replyablereactor4.scala index 7679a5adf8..8776cf63f0 100644 --- a/test/files/jvm/replyablereactor4.scala +++ b/test/files/jvm/replyablereactor4.scala @@ -33,9 +33,9 @@ object Test { loop { i += 1 val msg = r !? (500, 'hello) - if (i % 10000 == 0) + if (i % 200000 == 0) println(msg) - if (i >= 50000) { + if (i >= 1000000) { r ! 'stop exit() } |