summaryrefslogtreecommitdiff
path: root/src/library
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/library
parentef89729e20aee4f5397792425e344339fe1e7094 (diff)
downloadscala-0f188e1b47932b05d65d699dba88dd98dd191c17.tar.gz
scala-0f188e1b47932b05d65d699dba88dd98dd191c17.tar.bz2
scala-0f188e1b47932b05d65d699dba88dd98dd191c17.zip
Added uniqueness annotations. Review by rytz.
Diffstat (limited to 'src/library')
-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
4 files changed, 85 insertions, 0 deletions
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