@@ -7,7 +7,7 @@ import scala.quoted.matching.Sym
7
7
8
8
private [quoted] object Matcher {
9
9
10
- class QuoteMatcher [QCtx <: QuoteContext & Singleton ](given val qctx : QCtx ) {
10
+ class QuoteMatcher [QCtx <: QuoteContext & Singleton ](using val qctx : QCtx ) {
11
11
// TODO improve performance
12
12
13
13
// TODO use flag from qctx.tasty.rootContext. Maybe -debug or add -debug-macros
@@ -25,7 +25,7 @@ private[quoted] object Matcher {
25
25
*/
26
26
private type Env = Map [Symbol , Symbol ]
27
27
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 )
29
29
30
30
class SymBinding (val sym : Symbol , val fromAbove : Boolean )
31
31
@@ -98,7 +98,7 @@ private[quoted] object Matcher {
98
98
99
99
private given treeListOps : extension (scrutinees : List [Tree ]) {
100
100
/** 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 =
102
102
matchLists(scrutinees, patterns)(_ =?= _)
103
103
}
104
104
@@ -112,7 +112,7 @@ private[quoted] object Matcher {
112
112
* @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`.
113
113
* @return `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
114
114
*/
115
- def =?= (pattern0 : Tree )(given Context , Env ): Matching = {
115
+ def =?= (pattern0 : Tree )(using Context , Env ): Matching = {
116
116
117
117
/** Normalize the tree */
118
118
def normalize (tree : Tree ): Tree = tree match {
@@ -157,7 +157,7 @@ private[quoted] object Matcher {
157
157
def bodyFn (lambdaArgs : List [Tree ]): Tree = {
158
158
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf [List [Term ]]).toMap
159
159
new TreeMap {
160
- override def transformTerm (tree : Term )(given ctx : Context ): Term =
160
+ override def transformTerm (tree : Term )(using ctx : Context ): Term =
161
161
tree match
162
162
case tree : Ident => summon[Env ].get(tree.symbol).flatMap(argsMap.get).getOrElse(tree)
163
163
case tree => super .transformTerm(tree)
@@ -313,13 +313,13 @@ private[quoted] object Matcher {
313
313
314
314
private object ClosedPatternTerm {
315
315
/** 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 ] =
317
317
if freePatternVars(term).isEmpty then Some (term) else None
318
318
319
319
/** 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 ] =
321
321
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 ] =
323
323
tree match
324
324
case tree : Ident if env.contains(tree.symbol) => foldOverTree(x + tree.symbol, tree)
325
325
case _ => foldOverTree(x, tree)
@@ -328,7 +328,7 @@ private[quoted] object Matcher {
328
328
}
329
329
330
330
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 ]] =
332
332
args.foldRight(Option (List .empty[Ident ])) {
333
333
case (id : Ident , Some (acc)) => Some (id :: acc)
334
334
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 {
338
338
}
339
339
}
340
340
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 = {
342
342
(scrutinee, pattern) match {
343
343
case (Some (x), Some (y)) => x =?= y
344
344
case (None , None ) => matched
345
345
case _ => notMatched
346
346
}
347
347
}
348
348
349
- private def caseMatches (scrutinee : CaseDef , pattern : CaseDef )(given Context , Env ): Matching = {
349
+ private def caseMatches (scrutinee : CaseDef , pattern : CaseDef )(using Context , Env ): Matching = {
350
350
val (caseEnv, patternMatch) = patternsMatches(scrutinee.pattern, pattern.pattern)
351
351
withEnv(caseEnv) {
352
352
patternMatch &&
@@ -366,7 +366,7 @@ private[quoted] object Matcher {
366
366
* @return The new environment containing the bindings defined in this pattern tuppled with
367
367
* `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
368
368
*/
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 {
370
370
case (v1 : Term , Unapply (TypeApply (Select (patternHole @ Ident (" patternHole" ), " unapply" ), List (tpt)), Nil , Nil ))
371
371
if patternHole.symbol.owner == summon[Context ].requiredModule(" scala.runtime.quoted.Matcher" ) =>
372
372
(summon[Env ], matched(v1.seal))
@@ -412,7 +412,7 @@ private[quoted] object Matcher {
412
412
(summon[Env ], notMatched)
413
413
}
414
414
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 ) = {
416
416
if (patterns1.size != patterns2.size) (summon[Env ], notMatched)
417
417
else patterns1.zip(patterns2).foldLeft((summon[Env ], matched)) { (acc, x) =>
418
418
val (env, res) = patternsMatches(x._1, x._2)(given summon [Context ], acc._1)
0 commit comments