Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross build for Scala 3.2.1 #640

Merged
merged 3 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
scala:
- 3.1.2
- 3.2.1

steps:
- uses: actions/checkout@v2
Expand Down
182 changes: 90 additions & 92 deletions Dsl/src/main/scala/com/thoughtworks/dsl/Dsl.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.thoughtworks.dsl
import com.thoughtworks.dsl.Dsl.!!

private type !![R, +A] = (A => R) => R

import scala.annotation._
import scala.collection._
Expand Down Expand Up @@ -40,6 +41,54 @@ opaque type Dsl[-Keyword, Domain, +Value] <: (

private[dsl] trait LowPriorityDsl1 { this: Dsl.type =>

opaque type Searching[-Keyword, Domain, +Value] <: Dsl[
Keyword,
Domain,
Value
] = Dsl[Keyword, Domain, Value]
object Searching
extends Searching.AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived:
private[Searching] trait StackUnsafeDerived:
given [Keyword, UnsafeDomain, Value](using
dsl: Dsl.Derived.StackUnsafe[Keyword, UnsafeDomain, Value]
): Searching[Keyword, UnsafeDomain, Value] = dsl
private[Searching] trait StackSafeDerivedThenStackUnsafeDerived
extends Searching.StackUnsafeDerived:
given [Keyword, DerivedDomain, Value](using
dsl: Dsl.Derived.StackSafe[Keyword, DerivedDomain, Value]
): Searching[Keyword, DerivedDomain, Value] = dsl
private[Searching] trait ComposedThenStackSafeDerivedThenStackUnsafeDerived
extends Searching.StackSafeDerivedThenStackUnsafeDerived:
given [ComposedKeyword, Domain, Value](using
dsl: Dsl.Composed[ComposedKeyword, Domain, Value]
): Searching[ComposedKeyword, Domain, Value] = dsl
private[Searching] trait AtomicThenComposedThenStackSafeDerivedThenStackUnsafeDerived
extends Searching.ComposedThenStackSafeDerivedThenStackUnsafeDerived:
given [Keyword, Domain, Value](using
dsl: Dsl.Original[Keyword, Domain, Value]
): Searching[Keyword, Domain, Value] = dsl
object AtomicThenComposedThenStackSafeDerivedThenStackUnsafeDerived
extends AtomicThenComposedThenStackSafeDerivedThenStackUnsafeDerived

private[Searching] trait ComposedThenStackUnsafeDerived
extends Searching.StackUnsafeDerived:
given [ComposedKeyword, Domain, Value](using
dsl: Dsl.Composed[ComposedKeyword, Domain, Value]
): Searching[ComposedKeyword, Domain, Value] = dsl
private[Searching] trait StackSafeDerivedThenComposedThenStackUnsafeDerived
extends Searching.ComposedThenStackUnsafeDerived:
given [Keyword, DerivedDomain, Value](using
dsl: Dsl.Derived.StackSafe[Keyword, DerivedDomain, Value]
): Searching[Keyword, DerivedDomain, Value] = dsl
private[Searching] trait AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived
extends Searching.StackSafeDerivedThenComposedThenStackUnsafeDerived:
given [Keyword, Domain, Value](using
dsl: Dsl.Original[Keyword, Domain, Value]
): Searching[Keyword, Domain, Value] = dsl
object AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived
extends AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived
end Searching

private def deriveFunction1Dsl[Keyword, State, Domain, Value](using
restDsl: Dsl.Searching[Keyword, Domain, Value]
): Dsl[Keyword, State => Domain, Value] = Dsl {
Expand Down Expand Up @@ -94,14 +143,18 @@ private[dsl] trait LowPriorityDsl0 extends LowPriorityDsl1 { this: Dsl.type =>

}

inline def Dsl[Keyword, Domain, Value](using
dummyImplicit: DummyImplicit = DummyImplicit.dummyImplicit
): (
(
Keyword,
(Value => Domain)
) => Domain
) =:= Dsl[Keyword, Domain, Value] =
summon

object Dsl extends LowPriorityDsl0 {
def apply[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= Dsl[Keyword, Domain, Value] =
summon

private[dsl] abstract class TrampolineFunction1[-A, +R] extends (A => R) {
protected def step(): A => R
@tailrec
Expand Down Expand Up @@ -163,14 +216,13 @@ object Dsl extends LowPriorityDsl0 {
Value
] =
Dsl[Keyword, Domain, Value]
object StackSafe:
def apply[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= StackSafe[Keyword, Domain, Value] =
summon
def StackSafe[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= StackSafe[Keyword, Domain, Value] =
summon

/** A [[Dsl]] derived from a stack-unsafe domain, e.g.
* [[scala.concurrent.Future]]
Expand All @@ -181,14 +233,13 @@ object Dsl extends LowPriorityDsl0 {
Value
] =
Dsl[Keyword, Domain, Value]
object StackUnsafe:
def apply[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= StackUnsafe[Keyword, Domain, Value] =
summon
def StackUnsafe[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= StackUnsafe[Keyword, Domain, Value] =
summon

/** An [[Dsl]] for a control flow [[Keyword]], composed of other [[Dsl]]s for
* subtree of the [[Keyword]]. For example, a [[Dsl.Composed]] for
Expand All @@ -200,14 +251,13 @@ object Dsl extends LowPriorityDsl0 {
Domain,
Value
] = Dsl[Keyword, Domain, Value]
object Composed:
def apply[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= Composed[Keyword, Domain, Value] =
summon
def Composed[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= Composed[Keyword, Domain, Value] =
summon

/** An original [[Dsl]] for a [[Keyword]], i.e. neither [[Derived.StackSafe]]
* nor [[Derived.StackUnsafe]] nor [[Composed]].
Expand All @@ -218,61 +268,14 @@ object Dsl extends LowPriorityDsl0 {
Value
] =
Dsl[Keyword, Domain, Value]
object Original:
def apply[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= Original[Keyword, Domain, Value] =
summon

opaque type Searching[-Keyword, Domain, +Value] <: Dsl[
Keyword,
Domain,
Value
] = Dsl[Keyword, Domain, Value]
object Searching
extends Searching.AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived:
private[Searching] trait StackUnsafeDerived:
given [Keyword, UnsafeDomain, Value](using
dsl: Dsl.Derived.StackUnsafe[Keyword, UnsafeDomain, Value]
): Dsl.Searching[Keyword, UnsafeDomain, Value] = dsl
private[Searching] trait StackSafeDerivedThenStackUnsafeDerived
extends Searching.StackUnsafeDerived:
given [Keyword, DerivedDomain, Value](using
dsl: Dsl.Derived.StackSafe[Keyword, DerivedDomain, Value]
): Dsl.Searching[Keyword, DerivedDomain, Value] = dsl
private[Searching] trait ComposedThenStackSafeDerivedThenStackUnsafeDerived
extends Searching.StackSafeDerivedThenStackUnsafeDerived:
given [ComposedKeyword, Domain, Value](using
dsl: Dsl.Composed[ComposedKeyword, Domain, Value]
): Dsl.Searching[ComposedKeyword, Domain, Value] = dsl
private[Searching] trait AtomicThenComposedThenStackSafeDerivedThenStackUnsafeDerived
extends Searching.ComposedThenStackSafeDerivedThenStackUnsafeDerived:
given [Keyword, Domain, Value](using
dsl: Dsl.Original[Keyword, Domain, Value]
): Dsl.Searching[Keyword, Domain, Value] = dsl
object AtomicThenComposedThenStackSafeDerivedThenStackUnsafeDerived
extends AtomicThenComposedThenStackSafeDerivedThenStackUnsafeDerived

private[Searching] trait ComposedThenStackUnsafeDerived
extends Searching.StackUnsafeDerived:
given [ComposedKeyword, Domain, Value](using
dsl: Dsl.Composed[ComposedKeyword, Domain, Value]
): Dsl.Searching[ComposedKeyword, Domain, Value] = dsl
private[Searching] trait StackSafeDerivedThenComposedThenStackUnsafeDerived
extends Searching.ComposedThenStackUnsafeDerived:
given [Keyword, DerivedDomain, Value](using
dsl: Dsl.Derived.StackSafe[Keyword, DerivedDomain, Value]
): Dsl.Searching[Keyword, DerivedDomain, Value] = dsl
private[Searching] trait AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived
extends Searching.StackSafeDerivedThenComposedThenStackUnsafeDerived:
given [Keyword, Domain, Value](using
dsl: Dsl.Original[Keyword, Domain, Value]
): Dsl.Searching[Keyword, Domain, Value] = dsl
object AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived
extends AtomicThenStackSafeDerivedThenComposedThenStackUnsafeDerived
def Original[Keyword, Domain, Value]: (
(
Keyword,
(Value => Domain)
) => Domain
) =:= Original[Keyword, Domain, Value] =
summon

extension [Keyword, Value](
inline from: Keyword
Expand Down Expand Up @@ -411,8 +414,6 @@ object Dsl extends LowPriorityDsl0 {
] !! Throwable, TailRecValue] =
Dsl.Derived.StackUnsafe(derivedThrowableTailRecDsl)

private[dsl] type !![R, +A] = (A => R) => R

@FunctionalInterface
trait Lift[From, +To] extends (From => To)
private[dsl] trait LowPriorityLift0 { this: Lift.type =>
Expand Down Expand Up @@ -452,7 +453,6 @@ object Dsl extends LowPriorityDsl0 {

object OneStep extends LowPriorityOneStep0 {

import Dsl.!!
given [LeftDomain, RightDomain]
: OneStep[RightDomain, LeftDomain !! RightDomain] = r => _(r)

Expand Down Expand Up @@ -491,9 +491,7 @@ object Dsl extends LowPriorityDsl0 {
opaque type Opaque = Any
object Opaque {
opaque type Of[+Self] <: Self & Opaque = Self
object Of {
def apply[Self]: Self =:= Of[Self] = summon
}
def Of[Self]: Self =:= Of[Self] = summon
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package domains

import com.thoughtworks.dsl.macros.Reset
import com.thoughtworks.dsl.macros.Reset.Default.*
import com.thoughtworks.dsl.Dsl.{!!}
import org.scalatest.Assertion
import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.thoughtworks.dsl
package domains

import com.thoughtworks.dsl.Dsl
import com.thoughtworks.dsl.Dsl.!!

import scala.language.higherKinds
import scala.language.implicitConversions
Expand Down Expand Up @@ -217,7 +216,7 @@ object scalaz extends scalaz.LowPriority0 {
lift: Dsl.Lift[G[A], F[A]]
): Dsl.Original[Monadic[G[A]], F[B], A] =
Dsl.Original { (keyword: Monadic[G[A]], handler: A => F[B]) =>
monad.bind(lift(Monadic.apply.flip(keyword)))(
monad.bind(lift(Monadic.flip(keyword)))(
handler
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.thoughtworks.dsl
package domains

import com.thoughtworks.dsl.macros.Reset.Default.*
import com.thoughtworks.dsl.Dsl.!!

import _root_.scalaz.\/
import _root_.scalaz.\/-
import _root_.scalaz.OptionT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.net.SocketAddress
import java.nio.ByteBuffer
import java.nio.channels._

import com.thoughtworks.dsl.Dsl.{!!, IsKeyword}
import com.thoughtworks.dsl.Dsl.IsKeyword

import scala.util.control.NonFatal
import scala.annotation.unchecked.uncheckedVariance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ private trait AwaitJS { this: Await.type =>
given [JsPromiseResult, That]: Dsl.Original[Await[
js.Promise[JsPromiseResult]
], js.Promise[That], JsPromiseResult] =
Await.apply
Await
.liftCo[[X] =>> Dsl.Original[X, js.Promise[That], JsPromiseResult]](
Dsl.Original(_ `then` _)
)

given [JsPromiseResult, That](using ExecutionContext): Dsl.Original[Await[
js.Promise[JsPromiseResult]
], Future[That], JsPromiseResult] =
Await.apply.liftCo[[X] =>> Dsl.Original[X, Future[That], JsPromiseResult]](
Await.liftCo[[X] =>> Dsl.Original[X, Future[That], JsPromiseResult]](
Dsl.Original { (promise, handler) =>
promise.toFuture.flatMap(handler)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ import scala.language.implicitConversions
*/
opaque type Await[+AwaitableValue] <: Dsl.Keyword.Opaque =
Dsl.Keyword.Opaque.Of[AwaitableValue]
@inline def Await[AwaitableValue](using
dummyImplicit: DummyImplicit = DummyImplicit.dummyImplicit
): AwaitableValue =:= Await[AwaitableValue] =
Dsl.Keyword.Opaque.Of
object Await extends AwaitJS {
@inline def apply[AwaitableValue]: AwaitableValue =:= Await[AwaitableValue] =
Dsl.Keyword.Opaque.Of.apply
given [FutureResult]: IsKeyword[Await[Future[FutureResult]], FutureResult]
with {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.thoughtworks.dsl
package keywords

import com.thoughtworks.dsl.macros.Reset.Default.*
import Dsl.!!
import Dsl.Run
import Dsl.IsKeyword
import keywords._, Match._
Expand Down Expand Up @@ -145,23 +144,23 @@ class AwaitTest extends AsyncFreeSpec with Matchers with Inside {
"test1" in {
val reified = reify[1](1)
summon[reified.type <:< Typed[Suspend[Pure[1]], 1]]
Suspend.apply.flip(Typed.apply.flip(reified))() should be(1)
Suspend.flip(Typed.flip(reified))() should be(1)
}
"test2" in {
val reified = reify[1] { 1 }
summon[reified.type <:< Typed[Suspend[Pure[1]], 1]]
Suspend.apply.flip(Typed.apply.flip(reified))() should be(1)
Suspend.flip(Typed.flip(reified))() should be(1)

val reified2 = reify[1](!reified)
summon[reified2.type <:< Typed[Suspend[Typed[Suspend[Pure[1]], 1]], 1]]
Suspend.apply.flip(
Typed.apply.flip(Suspend.apply.flip(Typed.apply.flip(reified2))())
Suspend.flip(
Typed.flip(Suspend.flip(Typed.flip(reified2))())
)() should be(1)
}
"test3" in {
val reified = reify {}
summon[reified.type <:< Typed[Suspend[Pure[Unit]], Unit]]
Suspend.apply.flip(Typed.apply.flip(reified))() should be(())
Suspend.flip(Typed.flip(reified))() should be(())
}
"test4" in {
val reified = reify {
Expand Down
Loading