Skip to content

Commit 9ef3cd2

Browse files
authored
Merge pull request #484 from Atry/legacy-annotations
Remove legacy annotations
2 parents 63b9434 + cd74b26 commit 9ef3cd2

File tree

9 files changed

+80
-84
lines changed

9 files changed

+80
-84
lines changed

Dsl/src/main/scala/com/thoughtworks/dsl/Dsl.scala

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -123,80 +123,7 @@ object Dsl extends LowPriorityDsl0 {
123123
)
124124
}
125125

126-
type Continuation[R, +A] = (A => R) => R
127-
128-
// TODO: Move to a separate library ( domains-continuation? )
129-
object Continuation {
130-
@inline
131-
def now[R, A](a: A): R !! A = _(a)
132-
133-
@inline
134-
def empty[R, A](r: R): R !! A = Function.const(r)
135-
136-
@inline
137-
def delay[R, A](a: () => A): R !! A = _(a())
138-
139-
// TODO: turn it into an inline def
140-
// TODO: Think about package object in Scala 3
141-
@inline
142-
def apply[R, A](a: => A): (R !! A) = delay(() => a)
143-
144-
def toTryContinuation[LeftDomain, Value](
145-
task: LeftDomain !! Throwable !! Value
146-
)(handler: Try[Value] => LeftDomain): LeftDomain = {
147-
task { a => failureHandler =>
148-
handler(Success(a))
149-
} { e =>
150-
handler(Failure(e))
151-
}
152-
}
153-
154-
def fromTryContinuation[LeftDomain, Value](
155-
continuation: LeftDomain !! Try[Value]
156-
)(successHandler: Value => LeftDomain !! Throwable)(failureHandler: Throwable => LeftDomain): LeftDomain = {
157-
continuation(
158-
new (Try[Value] => LeftDomain) {
159-
def apply(result: Try[Value]): LeftDomain = {
160-
result match {
161-
case Success(a) =>
162-
val protectedContinuation =
163-
try {
164-
successHandler(a)
165-
} catch {
166-
case NonFatal(e) =>
167-
return failureHandler(e)
168-
}
169-
protectedContinuation(failureHandler)
170-
case Failure(e) =>
171-
failureHandler(e)
172-
}
173-
}
174-
}
175-
)
176-
}
177-
178-
}
179-
180-
type !![R, +A] = Continuation[R, A]
181-
val !! = Continuation
182-
183-
@deprecated("Use bangnotation.reset instead", "Dsl.scala 2.0.0")
184-
private[dsl] /* sealed */ trait ResetAnnotation extends Annotation with StaticAnnotation
185-
@deprecated("Use bangnotation.reset instead", "Dsl.scala 2.0.0")
186-
private[dsl] final class nonTypeConstraintReset extends ResetAnnotation with StaticAnnotation
187-
188-
/** An annotation to explicitly perform reset control operator on a code block.
189-
*
190-
* @note
191-
* This annotation can be automatically added if [[compilerplugins.ResetEverywhere ResetEverywhere]] compiler
192-
* plug-in is enabled.
193-
*/
194-
@deprecated("Use bangnotation.reset instead", "Dsl.scala 2.0.0")
195-
final class reset extends ResetAnnotation with StaticAnnotation with TypeConstraint
196-
197-
/** An annotation to mark a method is a shift control operator. */
198-
@deprecated("Use bangnotation.reset instead", "Dsl.scala 2.0.0")
199-
final class shift extends StaticAnnotation
126+
private[dsl] type !![R, +A] = (A => R) => R
200127

201128
def apply[Keyword, Domain, Value](implicit typeClass: Dsl[Keyword, Domain, Value]): Dsl[Keyword, Domain, Value] =
202129
typeClass

build.sbt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ lazy val bangnotation =
2121
`keywords-While`
2222
)
2323

24+
lazy val `domains-Continuation` =
25+
crossProject(JSPlatform, JVMPlatform)
26+
.crossType(CrossType.Pure)
27+
.dependsOn(bangnotation)
28+
2429
lazy val `domains-Task` =
2530
crossProject(JSPlatform, JVMPlatform)
2631
.crossType(CrossType.Pure)
2732
.dependsOn(
2833
`keywords-Shift`,
2934
bangnotation,
35+
`domains-Continuation`,
3036
`keywords-In` % Test,
3137
`keywords-Fork` % Test,
3238
`keywords-Each` % Test,
@@ -170,6 +176,7 @@ lazy val `keywords-Await` =
170176
.crossType(CrossType.Pure)
171177
.dependsOn(
172178
Dsl,
179+
`domains-Continuation`,
173180
comprehension % Test,
174181
bangnotation % Test,
175182
`domains-Task` % Test,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.thoughtworks.dsl
2+
package domains
3+
4+
import bangnotation._
5+
import scala.util._
6+
import scala.util.control.NonFatal
7+
8+
type Continuation[R, +A] = (A => R) => R
9+
10+
object Continuation {
11+
val !! = this
12+
type !![R, +A] = Continuation[R, A]
13+
14+
15+
@inline
16+
def now[R, A](a: A): R !! A = _(a)
17+
18+
@inline
19+
def empty[R, A](r: R): R !! A = Function.const(r)
20+
21+
@inline
22+
def delay[R, A](a: () => A): R !! A = _(a())
23+
24+
inline def apply[R, A](inline a: A): R !! A = { handler =>
25+
reset(handler(a))
26+
}
27+
28+
def toTryContinuation[LeftDomain, Value](
29+
task: LeftDomain !! Throwable !! Value
30+
)(handler: Try[Value] => LeftDomain): LeftDomain = {
31+
task { a => failureHandler =>
32+
handler(Success(a))
33+
} { e =>
34+
handler(Failure(e))
35+
}
36+
}
37+
38+
def fromTryContinuation[LeftDomain, Value](
39+
continuation: LeftDomain !! Try[Value]
40+
)(successHandler: Value => LeftDomain !! Throwable)(failureHandler: Throwable => LeftDomain): LeftDomain = {
41+
continuation(
42+
new (Try[Value] => LeftDomain) {
43+
def apply(result: Try[Value]): LeftDomain = {
44+
result match {
45+
case Success(a) =>
46+
val protectedContinuation =
47+
try {
48+
successHandler(a)
49+
} catch {
50+
case NonFatal(e) =>
51+
return failureHandler(e)
52+
}
53+
protectedContinuation(failureHandler)
54+
case Failure(e) =>
55+
failureHandler(e)
56+
}
57+
}
58+
}
59+
)
60+
}
61+
62+
}

domains-Task/.jvm/src/main/scala/com/thoughtworks/dsl/domains/TaskPlatformSpecificFunctions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.concurrent.SyncVar
44
import scala.util.Try
55
import scala.util.control.TailCalls
66
import scala.concurrent.duration.Duration
7-
import com.thoughtworks.dsl.Dsl.Continuation
7+
import com.thoughtworks.dsl.domains.Continuation
88
private[domains] trait TaskPlatformSpecificFunctions { this: Task.type =>
99

1010
def blockingAwait[A](task: Task[A], timeout: Duration = Duration.Inf): A = {

domains-Task/.jvm/src/test/scala/com/thoughtworks/dsl/domains/RaiiSpec.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.thoughtworks.dsl
22
package domains
33

4-
import com.thoughtworks.dsl.Dsl.{!!, Continuation}
54
import com.thoughtworks.dsl.keywords.{Shift, Yield}
6-
import com.thoughtworks.dsl.domains._
5+
import com.thoughtworks.dsl.domains._, Continuation.!!
76
import com.thoughtworks.dsl.bangnotation._
87

98
import scala.util.control.NonFatal

domains-Task/.jvm/src/test/scala/com/thoughtworks/dsl/domains/UsingSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.thoughtworks.dsl
22
package domains
33

4-
import com.thoughtworks.dsl.Dsl.{!!, Continuation}
4+
import Continuation.!!
55
import com.thoughtworks.dsl.bangnotation._
66
import com.thoughtworks.dsl.keywords.{Using, Yield}
77
import org.scalatest.Assertion

domains-Task/src/main/scala/com/thoughtworks/dsl/domains/Task.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.thoughtworks.dsl
22
package domains
33

4-
import com.thoughtworks.dsl.Dsl.{!!, Continuation}
4+
import com.thoughtworks.dsl.domains.Continuation, Continuation.!!
55
import com.thoughtworks.dsl.keywords.Shift
66
import com.thoughtworks.dsl.bangnotation._
77

keywords-Await/src/main/scala/com/thoughtworks/dsl/keywords/Await.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package keywords
33
import Dsl.IsKeyword
44
import Dsl.Typed
55
import com.thoughtworks.dsl.Dsl
6-
import com.thoughtworks.dsl.Dsl.!!
6+
import com.thoughtworks.dsl.domains.Continuation.!!
77
import scala.concurrent.Await.result
88
import scala.concurrent.duration.Duration
99
import scala.concurrent.{ExecutionContext, Future}

keywords-Shift/src/main/scala/com/thoughtworks/dsl/keywords/Shift.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Dsl.IsKeyword
44
import Dsl.Typed
55

66
import com.thoughtworks.dsl.Dsl
7-
import com.thoughtworks.dsl.Dsl.{!!, Continuation}
87
import com.thoughtworks.dsl.keywords.Shift.{SameDomainStackSafeShiftDsl, StackSafeShiftDsl}
98

109
import scala.annotation.tailrec
@@ -15,7 +14,7 @@ import scala.util.control.TailCalls.TailRec
1514
/** @author
1615
* 杨博 (Yang Bo)
1716
*/
18-
opaque type Shift[R, A] = Dsl.Continuation[R, A]
17+
opaque type Shift[R, A] = (A => R) => R
1918

2019
private[keywords] trait LowPriorityShift1 {
2120

@@ -151,8 +150,10 @@ object Shift extends LowPriorityShift0 {
151150
taskFlatMap(keyword.continuation, handler)
152151
}
153152

154-
def apply[R, A](continuation: Continuation[R, A]): Shift[R, A] = continuation
153+
private[keywords] type !![R, +A] = (A => R) => R
155154

156-
extension [R, A](shift: Shift[R, A]) def continuation: Continuation[R, A] = shift
155+
def apply[R, A](continuation: R !! A): Shift[R, A] = continuation
156+
157+
extension [R, A](shift: Shift[R, A]) def continuation: R !! A = shift
157158

158159
}

0 commit comments

Comments
 (0)