Skip to content

Commit 9219ec2

Browse files
committed
Cleanup imports
1 parent 9b0c172 commit 9219ec2

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

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

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import scala.annotation.{Annotation, compileTimeOnly}
66

77
import dotty.tools.dotc
88
import dotty.tools.dotc.ast.tpd
9-
import dotty.tools.dotc.core.Contexts._
9+
import dotty.tools.dotc.core.Contexts.*
10+
import dotty.tools.dotc.core.Flags.*
1011
import dotty.tools.dotc.core.Names.*
12+
import dotty.tools.dotc.core.Types.*
1113
import dotty.tools.dotc.core.StdNames.nme
14+
import dotty.tools.dotc.core.Symbols.*
1215

1316
/** Matches a quoted tree against a quoted pattern tree.
1417
* A quoted pattern tree may have type and term holes in addition to normal terms.
@@ -119,15 +122,15 @@ object Matcher {
119122
* ```
120123
* when matching `a * a` with `x * x` the environment will contain `Map(a -> x)`.
121124
*/
122-
private type Env = Map[dotc.core.Symbols.Symbol, dotc.core.Symbols.Symbol]
125+
private type Env = Map[Symbol, Symbol]
123126

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

126-
def termMatch(scrutineeTerm: tpd.Tree, patternTerm: tpd.Tree): Option[Tuple] =
129+
def termMatch(scrutineeTerm: Tree, patternTerm: Tree): Option[Tuple] =
127130
given Env = Map.empty
128131
scrutineeTerm =?= patternTerm
129132

130-
def typeTreeMatch(scrutineeTypeTree: tpd.Tree, patternTypeTree: tpd.Tree): Option[Tuple] =
133+
def typeTreeMatch(scrutineeTypeTree: Tree, patternTypeTree: Tree): Option[Tuple] =
131134
given Env = Map.empty
132135
scrutineeTypeTree =?= patternTypeTree
133136

@@ -138,11 +141,11 @@ object Matcher {
138141
case _ => notMatched
139142
}
140143

141-
extension (scrutinees: List[tpd.Tree])
142-
private def =?= (patterns: List[tpd.Tree])(using Env)(using DummyImplicit): Matching =
144+
extension (scrutinees: List[Tree])
145+
private def =?= (patterns: List[Tree])(using Env)(using DummyImplicit): Matching =
143146
matchLists(scrutinees, patterns)(_ =?= _)
144147

145-
extension (scrutinee0: tpd.Tree)
148+
extension (scrutinee0: Tree)
146149

147150
/** Check that the trees match and return the contents from the pattern holes.
148151
* Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes.
@@ -152,11 +155,7 @@ object Matcher {
152155
* @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`.
153156
* @return `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
154157
*/
155-
private def =?= (pattern0: tpd.Tree)(using Env): Matching =
156-
import tpd.* // TODO remove
157-
import dotc.core.Flags.* // TODO remove
158-
import dotc.core.Types.* // TODO remove
159-
import dotc.core.Symbols.* // TODO remove
158+
private def =?= (pattern0: Tree)(using Env): Matching =
160159

161160
/* Match block flattening */ // TODO move to cases
162161
/** Normalize the tree */
@@ -183,38 +182,38 @@ object Matcher {
183182
// TODO remove
184183
object TypeTreeTypeTest:
185184
def unapply(x: Tree): Option[Tree & x.type] = x match
186-
case x: (tpd.TypeBoundsTree & x.type) => None
187-
case x: (tpd.Tree & x.type) if x.isType => Some(x)
185+
case x: (TypeBoundsTree & x.type) => None
186+
case x: (Tree & x.type) if x.isType => Some(x)
188187
case _ => None
189188
end TypeTreeTypeTest
190189

191190
object Lambda:
192191
def apply(owner: Symbol, tpe: MethodType, rhsFn: (Symbol, List[Tree]) => Tree): Block =
193-
val meth = dotc.core.Symbols.newSymbol(owner, nme.ANON_FUN, Synthetic | Method, tpe)
194-
tpd.Closure(meth, tss => rhsFn(meth, tss.head))
192+
val meth = newSymbol(owner, nme.ANON_FUN, Synthetic | Method, tpe)
193+
Closure(meth, tss => rhsFn(meth, tss.head))
195194
end Lambda
196195

197196
(scrutinee, pattern) match
198197

199198
/* Term hole */
200199
// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
201200
case (scrutinee @ Typed(s, tpt1), Typed(TypeApply(patternHole, tpt :: Nil), tpt2))
202-
if patternHole.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole) &&
201+
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
203202
s.tpe <:< tpt.tpe &&
204203
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
205204
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
206205

207206
/* Term hole */
208207
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
209208
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
210-
if patternHole.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole) &&
209+
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
211210
scrutinee.tpe <:< tpt.tpe =>
212211
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
213212

214213
/* Higher order term hole */
215214
// Matches an open term and wraps it into a lambda that provides the free variables
216215
case (scrutinee, pattern @ Apply(TypeApply(Ident(_), List(TypeTree())), SeqLiteral(args, _) :: Nil))
217-
if pattern.symbol.eq(dotc.core.Symbols.defn.QuotedRuntimePatterns_higherOrderHole) =>
216+
if pattern.symbol.eq(defn.QuotedRuntimePatterns_higherOrderHole) =>
218217

219218
def bodyFn(lambdaArgs: List[Tree]): Tree = {
220219
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf[List[Tree]]).toMap
@@ -236,7 +235,7 @@ object Matcher {
236235
ctx.owner,
237236
MethodType(names)(
238237
_ => argTypes, _ => resType),
239-
(meth, x) => tpd.TreeOps(bodyFn(x)).changeNonLocalOwners(meth.asInstanceOf))
238+
(meth, x) => TreeOps(bodyFn(x)).changeNonLocalOwners(meth.asInstanceOf))
240239
matched(quotes.reflect.TreeMethods.asExpr(res.asInstanceOf[quotes.reflect.Tree]))
241240

242241
//
@@ -323,20 +322,20 @@ object Matcher {
323322

324323
/* Match val */
325324
case (scrutinee @ ValDef(_, tpt1, _), pattern @ ValDef(_, tpt2, _)) if checkValFlags() =>
326-
def rhsEnv = summon[Env] + (scrutinee.symbol.asInstanceOf[dotc.core.Symbols.Symbol] -> pattern.symbol.asInstanceOf[dotc.core.Symbols.Symbol])
325+
def rhsEnv = summon[Env] + (scrutinee.symbol.asInstanceOf[Symbol] -> pattern.symbol.asInstanceOf[Symbol])
327326
tpt1 =?= tpt2 &&& withEnv(rhsEnv)(scrutinee.rhs =?= pattern.rhs)
328327

329328
/* Match def */
330329
case (scrutinee @ DefDef(_, paramss1, tpt1, _), pattern @ DefDef(_, paramss2, tpt2, _)) =>
331330
def rhsEnv: Env =
332-
val paramSyms: List[(dotc.core.Symbols.Symbol, dotc.core.Symbols.Symbol)] =
331+
val paramSyms: List[(Symbol, Symbol)] =
333332
for
334333
(clause1, clause2) <- paramss1.zip(paramss2)
335334
(param1, param2) <- clause1.zip(clause2)
336335
yield
337-
param1.symbol.asInstanceOf[dotc.core.Symbols.Symbol] -> param2.symbol.asInstanceOf[dotc.core.Symbols.Symbol]
336+
param1.symbol.asInstanceOf[Symbol] -> param2.symbol.asInstanceOf[Symbol]
338337
val oldEnv: Env = summon[Env]
339-
val newEnv: List[(dotc.core.Symbols.Symbol, dotc.core.Symbols.Symbol)] = (scrutinee.symbol.asInstanceOf[dotc.core.Symbols.Symbol] -> pattern.symbol.asInstanceOf[dotc.core.Symbols.Symbol]) :: paramSyms
338+
val newEnv: List[(Symbol, Symbol)] = (scrutinee.symbol.asInstanceOf[Symbol] -> pattern.symbol.asInstanceOf[Symbol]) :: paramSyms
340339
oldEnv ++ newEnv
341340

342341
matchLists(paramss1, paramss2)(_ =?= _)
@@ -373,18 +372,17 @@ object Matcher {
373372

374373
end extension
375374

376-
/** Does the scrutenne symbol match the pattern symbol? It matches if:
375+
/** Does the scrutinee symbol match the pattern symbol? It matches if:
377376
* - They are the same symbol
378377
* - The scrutinee has is in the environment and they are equivalent
379378
* - The scrutinee overrides the symbol of the pattern
380379
*/
381-
private def symbolMatch(scrutineeTree: tpd.Tree, patternTree: tpd.Tree)(using Env): Boolean =
382-
import tpd.* // TODO remove
380+
private def symbolMatch(scrutineeTree: Tree, patternTree: Tree)(using Env): Boolean =
383381
val scrutinee = scrutineeTree.symbol
384382

385-
def overridingSymbol(ofclazz: dotc.core.Symbols.Symbol): dotc.core.Symbols.Symbol =
383+
def overridingSymbol(ofclazz: Symbol): Symbol =
386384
if ofclazz.isClass then scrutinee.denot.overridingSymbol(ofclazz.asClass)
387-
else dotc.core.Symbols.NoSymbol
385+
else NoSymbol
388386

389387
val devirtualizedScrutinee = scrutineeTree match
390388
case Select(qual, _) =>
@@ -401,13 +399,11 @@ object Matcher {
401399

402400
private object ClosedPatternTerm {
403401
/** Matches a term that does not contain free variables defined in the pattern (i.e. not defined in `Env`) */
404-
def unapply(term: tpd.Tree)(using Env): Option[term.type] =
402+
def unapply(term: Tree)(using Env): Option[term.type] =
405403
if freePatternVars(term).isEmpty then Some(term) else None
406404

407405
/** Return all free variables of the term defined in the pattern (i.e. defined in `Env`) */
408-
def freePatternVars(term: dotc.ast.tpd.Tree)(using env: Env): Set[dotc.core.Symbols.Symbol] =
409-
import dotc.ast.tpd.* // TODO remove
410-
import dotc.core.Symbols.* // TODO remove
406+
def freePatternVars(term: Tree)(using env: Env): Set[Symbol] =
411407
val accumulator = new TreeAccumulator[Set[Symbol]] {
412408
def apply(x: Set[Symbol], tree: Tree)(using Context): Set[Symbol] =
413409
tree match

0 commit comments

Comments
 (0)