Skip to content

Commit ba3e667

Browse files
committed
Clenup QuoteMatcher intterface
1 parent 78dfd29 commit ba3e667

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,13 @@ import dotty.tools.dotc.core.StdNames.nme
103103
object Matcher {
104104
import tpd.*
105105

106-
class QuoteMatcher[QCtx <: Quotes & Singleton](val qctx: QCtx)(using Context) {
106+
class QuoteMatcher(val quotes: Quotes)(using Context) {
107107

108108
// TODO improve performance
109109

110-
// TODO use flag from qctx.reflect. Maybe -debug or add -debug-macros
110+
// TODO use flag from Context. Maybe -debug or add -debug-macros
111111
private inline val debug = false
112112

113-
import qctx.reflect._
114113
import Matching._
115114

116115
/** A map relating equivalent symbols from the scrutinee and the pattern
@@ -124,11 +123,11 @@ object Matcher {
124123

125124
inline private def withEnv[T](env: Env)(inline body: Env ?=> T): T = body(using env)
126125

127-
def termMatch(scrutineeTerm: Term, patternTerm: Term): Option[Tuple] =
126+
def termMatch(scrutineeTerm: tpd.Tree, patternTerm: tpd.Tree): Option[Tuple] =
128127
given Env = Map.empty
129128
scrutineeTerm =?= patternTerm
130129

131-
def typeTreeMatch(scrutineeTypeTree: TypeTree, patternTypeTree: TypeTree): Option[Tuple] =
130+
def typeTreeMatch(scrutineeTypeTree: tpd.Tree, patternTypeTree: tpd.Tree): Option[Tuple] =
132131
given Env = Map.empty
133132
scrutineeTypeTree =?= patternTypeTree
134133

@@ -139,9 +138,6 @@ object Matcher {
139138
case _ => notMatched
140139
}
141140

142-
extension (scrutinee: Tree)
143-
private def =?= (pattern: Tree)(using Env): Matching =
144-
scrutinee.asInstanceOf[tpd.Tree] =?= pattern.asInstanceOf[tpd.Tree]
145141
extension (scrutinees: List[tpd.Tree])
146142
private def =?= (patterns: List[tpd.Tree])(using Env)(using DummyImplicit): Matching =
147143
matchLists(scrutinees, patterns)(_ =?= _)
@@ -206,14 +202,14 @@ object Matcher {
206202
if patternHole.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole) &&
207203
s.tpe <:< tpt.tpe &&
208204
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
209-
matched(qctx.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[qctx.reflect.Tree]))
205+
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
210206

211207
/* Term hole */
212208
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
213209
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
214210
if patternHole.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole) &&
215211
scrutinee.tpe <:< tpt.tpe =>
216-
matched(qctx.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[qctx.reflect.Tree]))
212+
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
217213

218214
/* Higher order term hole */
219215
// Matches an open term and wraps it into a lambda that provides the free variables
@@ -241,7 +237,7 @@ object Matcher {
241237
MethodType(names)(
242238
_ => argTypes, _ => resType),
243239
(meth, x) => tpd.TreeOps(bodyFn(x)).changeNonLocalOwners(meth.asInstanceOf))
244-
matched(qctx.reflect.TreeMethods.asExpr(res.asInstanceOf[qctx.reflect.Tree]))
240+
matched(quotes.reflect.TreeMethods.asExpr(res.asInstanceOf[quotes.reflect.Tree]))
245241

246242
//
247243
// Match two equivalent trees
@@ -369,8 +365,8 @@ object Matcher {
369365
|
370366
|with environment: ${summon[Env]}
371367
|
372-
|Scrutinee: ${Printer.TreeStructure.show(scrutinee.asInstanceOf)}
373-
|Pattern: ${Printer.TreeStructure.show(pattern.asInstanceOf)}
368+
|Scrutinee: ${quotes.reflect.Printer.TreeStructure.show(scrutinee.asInstanceOf)}
369+
|Pattern: ${quotes.reflect.Printer.TreeStructure.show(pattern.asInstanceOf)}
374370
|
375371
|""".stripMargin)
376372
notMatched

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,11 +2937,11 @@ 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)(using ctx1)
2940+
val matcher = new Matcher.QuoteMatcher(qctx1)(using ctx1)
29412941

29422942
val matchings =
2943-
if pat1.isType then matcher.termMatch(scrutinee.asInstanceOf[matcher.qctx.reflect.Term], pat1.asInstanceOf[matcher.qctx.reflect.Term])
2944-
else matcher.termMatch(scrutinee.asInstanceOf[matcher.qctx.reflect.Term], pat1.asInstanceOf[matcher.qctx.reflect.Term])
2943+
if pat1.isType then matcher.termMatch(scrutinee, pat1)
2944+
else matcher.termMatch(scrutinee, pat1)
29452945

29462946
// val matchings = matcher.termMatch(scrutinee, pattern)
29472947
if typeHoles.isEmpty then matchings

0 commit comments

Comments
 (0)