Skip to content

Commit 091b8f3

Browse files
committed
Update given syntax
1 parent 9479f54 commit 091b8f3

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

library/src/scala/internal/quoted/CompileTime.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ object CompileTime {
88

99
/** A term quote is desugared by the compiler into a call to this method */
1010
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprQuote`")
11-
def exprQuote[T](x: T): (given QuoteContext) => Expr[T] = ???
11+
def exprQuote[T](x: T): QuoteContext ?=> Expr[T] = ???
1212

1313
/** A term splice is desugared by the compiler into a call to this method */
1414
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprSplice`")
15-
def exprSplice[T](x: (given QuoteContext) => Expr[T]): T = ???
15+
def exprSplice[T](x: QuoteContext ?=> Expr[T]): T = ???
1616

1717
/** A type quote is desugared by the compiler into a call to this method */
1818
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.typeQuote`")

library/src/scala/internal/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Expr {
3232
* @param qctx the current QuoteContext
3333
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Expr[Ti]``
3434
*/
35-
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeExpr: scala.quoted.Expr[_])(implicit patternExpr: scala.quoted.Expr[_],
35+
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeExpr: scala.quoted.Expr[_])(using patternExpr: scala.quoted.Expr[_],
3636
hasTypeSplices: Boolean, qctx: QuoteContext): Option[Tup] = {
3737
import qctx.tasty.{_, given}
3838
new Matcher.QuoteMatcher[qctx.type].termMatch(scrutineeExpr.unseal, patternExpr.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.quoted.matching.Sym
77

88
private[quoted] object Matcher {
99

10-
class QuoteMatcher[QCtx <: QuoteContext & Singleton](given val qctx: QCtx) {
10+
class QuoteMatcher[QCtx <: QuoteContext & Singleton](using val qctx: QCtx) {
1111
// TODO improve performance
1212

1313
// TODO use flag from qctx.tasty.rootContext. Maybe -debug or add -debug-macros
@@ -25,7 +25,7 @@ private[quoted] object Matcher {
2525
*/
2626
private type Env = Map[Symbol, Symbol]
2727

28-
inline private def withEnv[T](env: Env)(body: => (given Env) => T): T = body(given env)
28+
inline private def withEnv[T](env: Env)(body: => Env ?=> T): T = body(given env)
2929

3030
class SymBinding(val sym: Symbol, val fromAbove: Boolean)
3131

@@ -98,7 +98,7 @@ private[quoted] object Matcher {
9898

9999
private given treeListOps: extension (scrutinees: List[Tree]) {
100100
/** Check that all trees match with =?= and concatenate the results with && */
101-
def =?= (patterns: List[Tree])(given Context, Env): Matching =
101+
def =?= (patterns: List[Tree])(using Context, Env): Matching =
102102
matchLists(scrutinees, patterns)(_ =?= _)
103103
}
104104

@@ -112,7 +112,7 @@ private[quoted] object Matcher {
112112
* @param `summon[Env]` Set of tuples containing pairs of symbols (s, p) where s defines a symbol in `scrutinee` which corresponds to symbol p in `pattern`.
113113
* @return `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
114114
*/
115-
def =?= (pattern0: Tree)(given Context, Env): Matching = {
115+
def =?= (pattern0: Tree)(using Context, Env): Matching = {
116116

117117
/** Normalize the tree */
118118
def normalize(tree: Tree): Tree = tree match {
@@ -157,7 +157,7 @@ private[quoted] object Matcher {
157157
def bodyFn(lambdaArgs: List[Tree]): Tree = {
158158
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf[List[Term]]).toMap
159159
new TreeMap {
160-
override def transformTerm(tree: Term)(given ctx: Context): Term =
160+
override def transformTerm(tree: Term)(using ctx: Context): Term =
161161
tree match
162162
case tree: Ident => summon[Env].get(tree.symbol).flatMap(argsMap.get).getOrElse(tree)
163163
case tree => super.transformTerm(tree)
@@ -313,13 +313,13 @@ private[quoted] object Matcher {
313313

314314
private object ClosedPatternTerm {
315315
/** Matches a term that does not contain free variables defined in the pattern (i.e. not defined in `Env`) */
316-
def unapply(term: Term)(given Context, Env): Option[term.type] =
316+
def unapply(term: Term)(using Context, Env): Option[term.type] =
317317
if freePatternVars(term).isEmpty then Some(term) else None
318318

319319
/** Return all free variables of the term defined in the pattern (i.e. defined in `Env`) */
320-
def freePatternVars(term: Term)(given ctx: Context, env: Env): Set[Symbol] =
320+
def freePatternVars(term: Term)(using ctx: Context, env: Env): Set[Symbol] =
321321
val accumulator = new TreeAccumulator[Set[Symbol]] {
322-
def foldTree(x: Set[Symbol], tree: Tree)(given ctx: Context): Set[Symbol] =
322+
def foldTree(x: Set[Symbol], tree: Tree)(using ctx: Context): Set[Symbol] =
323323
tree match
324324
case tree: Ident if env.contains(tree.symbol) => foldOverTree(x + tree.symbol, tree)
325325
case _ => foldOverTree(x, tree)
@@ -328,7 +328,7 @@ private[quoted] object Matcher {
328328
}
329329

330330
private object IdentArgs {
331-
def unapply(args: List[Term])(given Context): Option[List[Ident]] =
331+
def unapply(args: List[Term])(using Context): Option[List[Ident]] =
332332
args.foldRight(Option(List.empty[Ident])) {
333333
case (id: Ident, Some(acc)) => Some(id :: acc)
334334
case (Block(List(DefDef("$anonfun", Nil, List(params), Inferred(), Some(Apply(id: Ident, args)))), Closure(Ident("$anonfun"), None)), Some(acc))
@@ -338,15 +338,15 @@ private[quoted] object Matcher {
338338
}
339339
}
340340

341-
private def treeOptMatches(scrutinee: Option[Tree], pattern: Option[Tree])(given Context, Env): Matching = {
341+
private def treeOptMatches(scrutinee: Option[Tree], pattern: Option[Tree])(using Context, Env): Matching = {
342342
(scrutinee, pattern) match {
343343
case (Some(x), Some(y)) => x =?= y
344344
case (None, None) => matched
345345
case _ => notMatched
346346
}
347347
}
348348

349-
private def caseMatches(scrutinee: CaseDef, pattern: CaseDef)(given Context, Env): Matching = {
349+
private def caseMatches(scrutinee: CaseDef, pattern: CaseDef)(using Context, Env): Matching = {
350350
val (caseEnv, patternMatch) = patternsMatches(scrutinee.pattern, pattern.pattern)
351351
withEnv(caseEnv) {
352352
patternMatch &&
@@ -366,7 +366,7 @@ private[quoted] object Matcher {
366366
* @return The new environment containing the bindings defined in this pattern tuppled with
367367
* `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
368368
*/
369-
private def patternsMatches(scrutinee: Tree, pattern: Tree)(given Context, Env): (Env, Matching) = (scrutinee, pattern) match {
369+
private def patternsMatches(scrutinee: Tree, pattern: Tree)(using Context, Env): (Env, Matching) = (scrutinee, pattern) match {
370370
case (v1: Term, Unapply(TypeApply(Select(patternHole @ Ident("patternHole"), "unapply"), List(tpt)), Nil, Nil))
371371
if patternHole.symbol.owner == summon[Context].requiredModule("scala.runtime.quoted.Matcher") =>
372372
(summon[Env], matched(v1.seal))
@@ -412,7 +412,7 @@ private[quoted] object Matcher {
412412
(summon[Env], notMatched)
413413
}
414414

415-
private def foldPatterns(patterns1: List[Tree], patterns2: List[Tree])(given Context, Env): (Env, Matching) = {
415+
private def foldPatterns(patterns1: List[Tree], patterns2: List[Tree])(using Context, Env): (Env, Matching) = {
416416
if (patterns1.size != patterns2.size) (summon[Env], notMatched)
417417
else patterns1.zip(patterns2).foldLeft((summon[Env], matched)) { (acc, x) =>
418418
val (env, res) = patternsMatches(x._1, x._2)(given summon[Context], acc._1)

library/src/scala/internal/quoted/Type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Type {
2424
* @param qctx the current QuoteContext
2525
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Type[Ti]``
2626
*/
27-
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeType: scala.quoted.Type[_])(implicit patternType: scala.quoted.Type[_],
27+
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeType: scala.quoted.Type[_])(using patternType: scala.quoted.Type[_],
2828
hasTypeSplices: Boolean, qctx: QuoteContext): Option[Tup] = {
2929
import qctx.tasty.{_, given}
3030
new Matcher.QuoteMatcher[qctx.type].typeTreeMatch(scrutineeType.unseal, patternType.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]

library/src/scala/internal/quoted/Unpickler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import scala.quoted.{Expr, QuoteContext, Type}
66
object Unpickler {
77

88
type PickledQuote = List[String]
9-
type PickledExprArgs = Seq[Seq[Any] => (((given QuoteContext) => Expr[Any]) | Type[_])]
9+
type PickledExprArgs = Seq[Seq[Any] => ((QuoteContext ?=> Expr[Any]) | Type[_])]
1010
type PickledTypeArgs = Seq[Seq[Any] => Type[_]]
1111

1212
/** Unpickle `repr` which represents a pickled `Expr` tree,
1313
* replacing splice nodes with `args`
1414
*/
15-
def unpickleExpr[T](repr: PickledQuote, args: PickledExprArgs): (given QuoteContext) => Expr[T] =
15+
def unpickleExpr[T](repr: PickledQuote, args: PickledExprArgs): QuoteContext ?=> Expr[T] =
1616
summon[QuoteContext].tasty.internal.unpickleExpr(repr, args).asInstanceOf[Expr[T]]
1717

1818
/** Unpickle `repr` which represents a pickled `Type` tree,
1919
* replacing splice nodes with `args`
2020
*/
21-
def unpickleType[T](repr: PickledQuote, args: PickledTypeArgs): (given QuoteContext) => Type[T] =
21+
def unpickleType[T](repr: PickledQuote, args: PickledTypeArgs): QuoteContext ?=> Type[T] =
2222
summon[QuoteContext].tasty.internal.unpickleType(repr, args).asInstanceOf[Type[T]]
2323

2424
}

tests/run-macros/quote-matcher-runtime/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macros {
99
private def impl[A, B](a: Expr[A], b: Expr[B])(using qctx: QuoteContext) : Expr[Unit] = {
1010
import qctx.tasty.{Bind => _, given, _}
1111

12-
val res = scala.internal.quoted.Expr.unapply[Tuple, Tuple](a)(b, true, qctx).map { tup =>
12+
val res = scala.internal.quoted.Expr.unapply[Tuple, Tuple](a)(given b, true, qctx).map { tup =>
1313
tup.toArray.toList.map {
1414
case r: Expr[_] =>
1515
s"Expr(${r.unseal.show})"

tests/run-macros/quote-type-matcher/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macros {
99
private def matchesExpr[A, B](a: Type[A], b: Type[B])(using qctx: QuoteContext) : Expr[Unit] = {
1010
import qctx.tasty.{Bind => _, given, _}
1111

12-
val res = scala.internal.quoted.Type.unapply[Tuple, Tuple](a)(b, true, qctx).map { tup =>
12+
val res = scala.internal.quoted.Type.unapply[Tuple, Tuple](a)(given b, true, qctx).map { tup =>
1313
tup.toArray.toList.map {
1414
case r: quoted.Type[_] =>
1515
s"Type(${r.unseal.show})"

0 commit comments

Comments
 (0)