@@ -16,14 +16,14 @@ class Expr[+T] private[scala] {
16
16
* Returns `None` if the expression does not contain a value or contains side effects.
17
17
* Otherwise returns the `Some` of the value.
18
18
*/
19
- final def getValue [U >: T ](given qctx : QuoteContext , valueOf : ValueOfExpr [U ]): Option [U ] = valueOf(this )
19
+ final def getValue [U >: T ](using qctx : QuoteContext , valueOf : ValueOfExpr [U ]): Option [U ] = valueOf(this )
20
20
21
21
/** Return the value of this expression.
22
22
*
23
23
* Emits an error error and throws if the expression does not contain a value or contains side effects.
24
24
* Otherwise returns the value.
25
25
*/
26
- final def value [U >: T ](given qctx : QuoteContext , valueOf : ValueOfExpr [U ]): U =
26
+ final def value [U >: T ](using qctx : QuoteContext , valueOf : ValueOfExpr [U ]): U =
27
27
valueOf(this ).getOrElse(qctx.throwError(s " Expected a known value. \n\n The value of: $show\n could not be recovered using $valueOf" , this ))
28
28
29
29
/** Pattern matches `this` against `that`. Effectively performing a deep equality check.
@@ -34,15 +34,15 @@ class Expr[+T] private[scala] {
34
34
* case _ => false
35
35
* ```
36
36
*/
37
- final def matches (that : Expr [Any ])(given qctx : QuoteContext ): Boolean =
37
+ final def matches (that : Expr [Any ])(using qctx : QuoteContext ): Boolean =
38
38
! scala.internal.quoted.Expr .unapply[Unit , Unit ](this )(given that , false , qctx).isEmpty
39
39
40
40
}
41
41
42
42
object Expr {
43
43
44
44
/** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
45
- type TupleOfExpr [Tup <: Tuple ] = Tuple .Map [Tup , [X ] =>> ( given QuoteContext ) => Expr [X ]]
45
+ type TupleOfExpr [Tup <: Tuple ] = Tuple .Map [Tup , [X ] =>> QuoteContext ? => Expr [X ]]
46
46
47
47
/** `Expr.betaReduce(f)(x1, ..., xn)` is functionally the same as `'{($f)($x1, ..., $xn)}`, however it optimizes this call
48
48
* by returning the result of beta-reducing `f(x1, ..., xn)` if `f` is a known lambda expression.
@@ -52,7 +52,7 @@ object Expr {
52
52
* Expr.betaReduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
53
53
* ```
54
54
*/
55
- def betaReduce [F , Args <: Tuple , R , G ](f : Expr [F ])(given tf : TupledFunction [F , Args => R ], tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]], qctx : QuoteContext ): G = {
55
+ def betaReduce [F , Args <: Tuple , R , G ](f : Expr [F ])(using tf : TupledFunction [F , Args => R ], tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]], qctx : QuoteContext ): G = {
56
56
import qctx .tasty .{_ , given }
57
57
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
58
58
}
@@ -62,22 +62,22 @@ object Expr {
62
62
*
63
63
* `Expr.betaReduceGiven` distributes applications of `Expr` over function arrows
64
64
* ```scala
65
- * Expr.betaReduceGiven(_): Expr[(given T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
65
+ * Expr.betaReduceGiven(_): Expr[(T1, ..., Tn) ? => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
66
66
* ```
67
67
*/
68
- def betaReduceGiven [F , Args <: Tuple , R , G ](f : Expr [F ])(given tf : TupledFunction [F , ( given Args ) => R ], tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]], qctx : QuoteContext ): G = {
68
+ def betaReduceGiven [F , Args <: Tuple , R , G ](f : Expr [F ])(using tf : TupledFunction [F , Args ? => R ], tg : TupledFunction [G , TupleOfExpr [Args ] => Expr [R ]], qctx : QuoteContext ): G = {
69
69
import qctx .tasty .{_ , given }
70
70
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf [QuoteContext => Expr [_]](qctx).unseal)).seal.asInstanceOf [Expr [R ]])
71
71
}
72
72
73
73
/** Returns a null expresssion equivalent to `'{null}` */
74
- def nullExpr : ( given QuoteContext ) => Expr [Null ] = ( given qctx ) => {
74
+ def nullExpr : QuoteContext ? => Expr [Null ] = qctx ? => {
75
75
import qctx .tasty .{_ , given }
76
76
Literal (Constant (null )).seal.asInstanceOf [Expr [Null ]]
77
77
}
78
78
79
79
/** Returns a unit expresssion equivalent to `'{}` or `'{()}` */
80
- def unitExpr : ( given QuoteContext ) => Expr [Unit ] = ( given qctx ) => {
80
+ def unitExpr : QuoteContext ? => Expr [Unit ] = qctx ? => {
81
81
import qctx .tasty .{_ , given }
82
82
Literal (Constant (())).seal.asInstanceOf [Expr [Unit ]]
83
83
}
@@ -86,13 +86,13 @@ object Expr {
86
86
* Given list of statements `s1 :: s2 :: ... :: Nil` and an expression `e` the resulting expression
87
87
* will be equivalent to `'{ $s1; $s2; ...; $e }`.
88
88
*/
89
- def block [T ](statements : List [Expr [_]], expr : Expr [T ])(given qctx : QuoteContext ): Expr [T ] = {
89
+ def block [T ](statements : List [Expr [_]], expr : Expr [T ])(using qctx : QuoteContext ): Expr [T ] = {
90
90
import qctx .tasty .{_ , given }
91
91
Block (statements.map(_.unseal), expr.unseal).seal.asInstanceOf [Expr [T ]]
92
92
}
93
93
94
94
/** Lift a value into an expression containing the construction of that value */
95
- def apply [T : Liftable ](x : T )(given QuoteContext ): Expr [T ] = summon[Liftable [T ]].toExpr(x)
95
+ def apply [T : Liftable ](x : T )(using qctx : QuoteContext ): Expr [T ] = summon[Liftable [T ]].toExpr(x)
96
96
97
97
/** Lifts this sequence of expressions into an expression of a sequence
98
98
*
@@ -106,7 +106,7 @@ object Expr {
106
106
* '{ List(${Expr.ofSeq(List(1, 2, 3))}: _*) } // equvalent to '{ List(1, 2, 3) }
107
107
* ```
108
108
*/
109
- def ofSeq [T ](xs : Seq [Expr [T ]])(given tp : Type [T ], qctx : QuoteContext ): Expr [Seq [T ]] = {
109
+ def ofSeq [T ](xs : Seq [Expr [T ]])(using tp : Type [T ], qctx : QuoteContext ): Expr [Seq [T ]] = {
110
110
import qctx .tasty .{_ , given }
111
111
Repeated (xs.map(_.unseal).toList, tp.unseal).seal.asInstanceOf [Expr [Seq [T ]]]
112
112
}
@@ -119,7 +119,7 @@ object Expr {
119
119
* to an expression equivalent to
120
120
* `'{ List($e1, $e2, ...) }` typed as an `Expr[List[T]]`
121
121
*/
122
- def ofList [T ](xs : Seq [Expr [T ]])(given Type [T ], QuoteContext ): Expr [List [T ]] =
122
+ def ofList [T ](xs : Seq [Expr [T ]])(using Type [T ], QuoteContext ): Expr [List [T ]] =
123
123
if (xs.isEmpty) ' { Nil } else ' { List ($ {ofSeq(xs)}: _* ) }
124
124
125
125
/** Lifts this sequence of expressions into an expression of a tuple
@@ -129,7 +129,7 @@ object Expr {
129
129
* to an expression equivalent to
130
130
* `'{ ($e1, $e2, ...) }` typed as an `Expr[Tuple]`
131
131
*/
132
- def ofTuple (seq : Seq [Expr [_]])(given QuoteContext ): Expr [Tuple ] = {
132
+ def ofTuple (seq : Seq [Expr [_]])(using qctx : QuoteContext ): Expr [Tuple ] = {
133
133
seq match {
134
134
case Seq () =>
135
135
unitExpr
@@ -183,7 +183,7 @@ object Expr {
183
183
}
184
184
185
185
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
186
- def ofTuple [T <: Tuple : Tuple .IsMappedBy [Expr ]: Type ](tup : T ) ( given qctx : QuoteContext ): Expr [Tuple .InverseMap [T , Expr ]] = {
186
+ def ofTuple [T <: Tuple : Tuple .IsMappedBy [Expr ]: Type ](tup : T )( using qctx : QuoteContext ): Expr [Tuple .InverseMap [T , Expr ]] = {
187
187
import qctx .tasty .{_ , given }
188
188
val elems : Seq [Expr [_]] = tup.asInstanceOf [Product ].productIterator.toSeq.asInstanceOf [Seq [Expr [_]]]
189
189
ofTuple(elems).cast[Tuple .InverseMap [T , Expr ]]
0 commit comments