@@ -7,7 +7,7 @@ import scala.quoted.matching.Sym
77
88private [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)
0 commit comments