Skip to content

Commit 9a2a1ee

Browse files
committed
Use defn directly
1 parent 66b315d commit 9a2a1ee

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

compiler/src/scala/quoted/runtime/impl/Matcher.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ package runtime.impl
44
import scala.annotation.internal.sharable
55
import scala.annotation.{Annotation, compileTimeOnly}
66

7+
import dotty.tools.dotc
8+
import dotty.tools.dotc.core.Contexts._
9+
710
/** Matches a quoted tree against a quoted pattern tree.
811
* A quoted pattern tree may have type and term holes in addition to normal terms.
912
*
@@ -96,7 +99,7 @@ import scala.annotation.{Annotation, compileTimeOnly}
9699
*/
97100
object Matcher {
98101

99-
abstract class QuoteMatcher[QCtx <: Quotes & Singleton](val qctx: QCtx) {
102+
class QuoteMatcher[QCtx <: Quotes & Singleton](val qctx: QCtx)(using Context) {
100103

101104
// TODO improve performance
102105

@@ -106,9 +109,6 @@ object Matcher {
106109
import qctx.reflect._
107110
import Matching._
108111

109-
def patternHoleSymbol: Symbol
110-
def higherOrderHoleSymbol: Symbol
111-
112112
/** A map relating equivalent symbols from the scrutinee and the pattern
113113
* For example in
114114
* ```
@@ -179,22 +179,22 @@ object Matcher {
179179
/* Term hole */
180180
// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
181181
case (scrutinee @ Typed(s, tpt1), Typed(TypeApply(patternHole, tpt :: Nil), tpt2))
182-
if patternHole.symbol == patternHoleSymbol &&
182+
if patternHole.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole) &&
183183
s.tpe <:< tpt.tpe &&
184184
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
185185
matched(scrutinee.asExpr)
186186

187187
/* Term hole */
188188
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
189189
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
190-
if patternHole.symbol == patternHoleSymbol &&
190+
if patternHole.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole) &&
191191
scrutinee.tpe <:< tpt.tpe =>
192192
matched(scrutinee.asExpr)
193193

194194
/* Higher order term hole */
195195
// Matches an open term and wraps it into a lambda that provides the free variables
196196
case (scrutinee, pattern @ Apply(TypeApply(Ident("higherOrderHole"), List(Inferred())), Repeated(args, _) :: Nil))
197-
if pattern.symbol == higherOrderHoleSymbol =>
197+
if pattern.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_higherOrderHole) =>
198198

199199
def bodyFn(lambdaArgs: List[Tree]): Tree = {
200200
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf[List[Term]]).toMap

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,10 +2937,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
29372937

29382938
val qctx1 = QuotesImpl()(using ctx1)
29392939

2940-
val matcher = new Matcher.QuoteMatcher[qctx1.type](qctx1) {
2941-
def patternHoleSymbol: qctx1.reflect.Symbol = dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole.asInstanceOf
2942-
def higherOrderHoleSymbol: qctx1.reflect.Symbol = dotc.core.Symbols.defn.QuotedRuntimePatterns_higherOrderHole.asInstanceOf
2943-
}
2940+
val matcher = new Matcher.QuoteMatcher[qctx1.type](qctx1)(using ctx1)
29442941

29452942
val matchings =
29462943
if pat1.isType then matcher.termMatch(scrutinee.asInstanceOf[matcher.qctx.reflect.Term], pat1.asInstanceOf[matcher.qctx.reflect.Term])

0 commit comments

Comments
 (0)