From a78eb9cf0c212dbf1933de9ce4b0f160310231a6 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 6 Oct 2020 09:30:55 +0200 Subject: [PATCH] Remove Quoted patterns from tasty.CompilerInterface --- compiler/src/dotty/tools/dotc/quoted/Matcher.scala | 12 +++++++----- .../dotty/tools/dotc/quoted/QuoteContextImpl.scala | 8 ++++---- .../src/scala/internal/tasty/CompilerInterface.scala | 6 ------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/quoted/Matcher.scala b/compiler/src/dotty/tools/dotc/quoted/Matcher.scala index 1a969ce322e2..d28bffff22f0 100644 --- a/compiler/src/dotty/tools/dotc/quoted/Matcher.scala +++ b/compiler/src/dotty/tools/dotc/quoted/Matcher.scala @@ -98,8 +98,7 @@ import scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface */ object Matcher { - class QuoteMatcher[QCtx <: QuoteContext & Singleton](val qctx0: QCtx) { - val qctx = qctx0.asInstanceOf[qctx0.type { val tasty: qctx0.tasty.type & scala.internal.tasty.CompilerInterface }] + abstract class QuoteMatcher[QCtx <: QuoteContext { val tasty: scala.internal.tasty.CompilerInterface } & Singleton](val qctx: QCtx) { // TODO improve performance @@ -109,6 +108,9 @@ object Matcher { import qctx.tasty._ import Matching._ + def patternHoleSymbol: Symbol + def higherOrderHoleSymbol: Symbol + /** A map relating equivalent symbols from the scrutinee and the pattern * For example in * ``` @@ -179,7 +181,7 @@ object Matcher { /* Term hole */ // Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree case (scrutinee @ Typed(s, tpt1), Typed(TypeApply(patternHole, tpt :: Nil), tpt2)) - if patternHole.symbol == qctx.tasty.Definitions_InternalQuotedPatterns_patternHole && + if patternHole.symbol == patternHoleSymbol && s.tpe <:< tpt.tpe && tpt2.tpe.derivesFrom(defn.RepeatedParamClass) => matched(scrutinee.seal) @@ -187,14 +189,14 @@ object Matcher { /* Term hole */ // Match a scala.internal.Quoted.patternHole and return the scrutinee tree case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil)) - if patternHole.symbol == qctx.tasty.Definitions_InternalQuotedPatterns_patternHole && + if patternHole.symbol == patternHoleSymbol && scrutinee.tpe <:< tpt.tpe => matched(scrutinee.seal) /* Higher order term hole */ // Matches an open term and wraps it into a lambda that provides the free variables case (scrutinee, pattern @ Apply(TypeApply(Ident("higherOrderHole"), List(Inferred())), Repeated(args, _) :: Nil)) - if pattern.symbol == qctx.tasty.Definitions_InternalQuotedPatterns_higherOrderHole => + if pattern.symbol == higherOrderHoleSymbol => def bodyFn(lambdaArgs: List[Tree]): Tree = { val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf[List[Term]]).toMap diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala index 988b7f45a08b..c1b6da19adca 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala @@ -2646,7 +2646,10 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext: val qctx1 = dotty.tools.dotc.quoted.QuoteContextImpl()(using ctx1) .asInstanceOf[QuoteContext { val tasty: QuoteContextImpl.this.tasty.type }] - val matcher = new Matcher.QuoteMatcher[qctx1.type](qctx1) + val matcher = new Matcher.QuoteMatcher[qctx1.type](qctx1) { + def patternHoleSymbol: Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_patternHole + def higherOrderHoleSymbol: Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_higherOrderHole + } val matchings = if pat1.isType then matcher.termMatch(scrutinee, pat1) @@ -2665,9 +2668,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext: } } - def Definitions_InternalQuotedPatterns_patternHole: Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_patternHole - def Definitions_InternalQuotedPatterns_higherOrderHole: Symbol = dotc.core.Symbols.defn.InternalQuotedPatterns_higherOrderHole - end tasty private[this] val hash = QuoteContextImpl.scopeId(using ctx) diff --git a/library/src/scala/internal/tasty/CompilerInterface.scala b/library/src/scala/internal/tasty/CompilerInterface.scala index a8925a0ab3b9..d9ce3f9e9932 100644 --- a/library/src/scala/internal/tasty/CompilerInterface.scala +++ b/library/src/scala/internal/tasty/CompilerInterface.scala @@ -51,12 +51,6 @@ trait CompilerInterface { self: scala.tasty.Reflection => */ def typeTreeMatch(scrutinee: TypeTree, pattern: TypeTree): Option[Tuple] - /** Symbol of scala.internal.quoted.Patterns.patternHole */ - def Definitions_InternalQuotedPatterns_patternHole: Symbol // TODO remove - - /** Symbol of scala.internal.quoted.Patterns.higherOrderHole */ - def Definitions_InternalQuotedPatterns_higherOrderHole: Symbol // TODO remove - }