Skip to content

Commit f6b48a5

Browse files
committed
Move quoted matcher encoding to internal.quoted.Matcher
1 parent 1d77fbe commit f6b48a5

File tree

9 files changed

+141
-139
lines changed

9 files changed

+141
-139
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ object desugar {
933933
def quotedPatternTypeDef(tree: TypeDef)(implicit ctx: Context): TypeDef = {
934934
assert(ctx.mode.is(Mode.QuotedPattern))
935935
if (tree.name.startsWith("$") && !tree.isBackquoted) {
936-
val patternBindHoleAnnot = New(ref(defn.InternalQuoted_patternTypeAnnot.typeRef)).withSpan(tree.span)
936+
val patternBindHoleAnnot = New(ref(defn.InternalQuotedMatcher_patternTypeAnnot.typeRef)).withSpan(tree.span)
937937
val mods = tree.mods.withAddedAnnotation(patternBindHoleAnnot)
938938
tree.withMods(mods)
939939
}

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,14 @@ class Definitions {
694694
@tu lazy val InternalQuoted_exprSplice : Symbol = InternalQuotedModule.requiredMethod("exprSplice")
695695
@tu lazy val InternalQuoted_exprNestedSplice : Symbol = InternalQuotedModule.requiredMethod("exprNestedSplice")
696696
@tu lazy val InternalQuoted_typeQuote : Symbol = InternalQuotedModule.requiredMethod("typeQuote")
697-
@tu lazy val InternalQuoted_patternHole: Symbol = InternalQuotedModule.requiredMethod("patternHole")
698-
@tu lazy val InternalQuoted_patternHigherOrderHole: Symbol = InternalQuotedModule.requiredMethod("patternHigherOrderHole")
699-
@tu lazy val InternalQuoted_higherOrderHole: Symbol = InternalQuotedModule.requiredMethod("higherOrderHole")
700-
@tu lazy val InternalQuoted_patternTypeAnnot: ClassSymbol = InternalQuotedModule.requiredClass("patternType")
701697
@tu lazy val InternalQuoted_QuoteTypeTagAnnot: ClassSymbol = InternalQuotedModule.requiredClass("quoteTypeTag")
702-
@tu lazy val InternalQuoted_fromAboveAnnot: ClassSymbol = InternalQuotedModule.requiredClass("fromAbove")
703698

699+
@tu lazy val InternalQuotedMatcher: Symbol = ctx.requiredModule("scala.internal.quoted.Matcher")
700+
@tu lazy val InternalQuotedMatcher_patternHole: Symbol = InternalQuotedMatcher.requiredMethod("patternHole")
701+
@tu lazy val InternalQuotedMatcher_patternHigherOrderHole: Symbol = InternalQuotedMatcher.requiredMethod("patternHigherOrderHole")
702+
@tu lazy val InternalQuotedMatcher_higherOrderHole: Symbol = InternalQuotedMatcher.requiredMethod("higherOrderHole")
703+
@tu lazy val InternalQuotedMatcher_patternTypeAnnot: ClassSymbol = InternalQuotedMatcher.requiredClass("patternType")
704+
@tu lazy val InternalQuotedMatcher_fromAboveAnnot: ClassSymbol = InternalQuotedMatcher.requiredClass("fromAbove")
704705

705706
@tu lazy val InternalQuotedExprModule: Symbol = ctx.requiredModule("scala.internal.quoted.Expr")
706707
@tu lazy val InternalQuotedExpr_unapply: Symbol = InternalQuotedExprModule.requiredMethod(nme.unapply)

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,10 +1982,10 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
19821982
def Definitions_TupleClass(arity: Int): Symbol = defn.TupleType(arity).classSymbol.asClass
19831983
def Definitions_isTupleClass(sym: Symbol): Boolean = defn.isTupleClass(sym)
19841984

1985-
def Definitions_InternalQuoted_patternHole: Symbol = defn.InternalQuoted_patternHole
1986-
def Definitions_InternalQuoted_higherOrderHole: Symbol = defn.InternalQuoted_higherOrderHole
1987-
def Definitions_InternalQuoted_patternTypeAnnot: Symbol = defn.InternalQuoted_patternTypeAnnot
1988-
def Definitions_InternalQuoted_fromAboveAnnot: Symbol = defn.InternalQuoted_fromAboveAnnot
1985+
def Definitions_InternalQuotedMatcher_patternHole: Symbol = defn.InternalQuotedMatcher_patternHole
1986+
def Definitions_InternalQuotedMatcher_higherOrderHole: Symbol = defn.InternalQuotedMatcher_higherOrderHole
1987+
def Definitions_InternalQuotedMatcher_patternTypeAnnot: Symbol = defn.InternalQuotedMatcher_patternTypeAnnot
1988+
def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol = defn.InternalQuotedMatcher_fromAboveAnnot
19891989

19901990
// Types
19911991

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ trait QuotesAndSplices {
150150
ctx.error("Missing arguments for open pattern", tree.sourcePos)
151151
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
152152
val typedPat = typedSplice(splice, defn.FunctionOf(argTypes, pt))
153-
ref(defn.InternalQuoted_patternHigherOrderHole).appliedToType(pt).appliedTo(typedPat, SeqLiteral(typedArgs, TypeTree(defn.AnyType)))
153+
ref(defn.InternalQuotedMatcher_patternHigherOrderHole).appliedToType(pt).appliedTo(typedPat, SeqLiteral(typedArgs, TypeTree(defn.AnyType)))
154154
case _ =>
155155
val typedArgs = args.map(arg => typedExpr(arg))
156156
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
@@ -183,7 +183,7 @@ trait QuotesAndSplices {
183183
case pt: TypeBounds => pt
184184
case _ => TypeBounds.empty
185185
val typeSym = ctx.newSymbol(spliceOwner(ctx), name, EmptyFlags, typeSymInfo, NoSymbol, tree.expr.span)
186-
typeSym.addAnnotation(Annotation(New(ref(defn.InternalQuoted_patternTypeAnnot.typeRef)).withSpan(tree.expr.span)))
186+
typeSym.addAnnotation(Annotation(New(ref(defn.InternalQuotedMatcher_patternTypeAnnot.typeRef)).withSpan(tree.expr.span)))
187187
val pat = typedPattern(tree.expr, defn.QuotedTypeClass.typeRef.appliedTo(typeSym.typeRef))(
188188
using spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx)))
189189
pat.select(tpnme.splice)
@@ -253,16 +253,16 @@ trait QuotesAndSplices {
253253
val exprTpt = AppliedTypeTree(TypeTree(defn.QuotedExprClass.typeRef), tpt1 :: Nil)
254254
val newSplice = ref(defn.InternalQuoted_exprSplice).appliedToType(tpt1.tpe).appliedTo(Typed(pat, exprTpt))
255255
transform(newSplice)
256-
case Apply(TypeApply(fn, targs), Apply(sp, pat :: Nil) :: args :: Nil) if fn.symbol == defn.InternalQuoted_patternHigherOrderHole =>
257-
try ref(defn.InternalQuoted_higherOrderHole.termRef).appliedToTypeTrees(targs).appliedTo(args).withSpan(tree.span)
256+
case Apply(TypeApply(fn, targs), Apply(sp, pat :: Nil) :: args :: Nil) if fn.symbol == defn.InternalQuotedMatcher_patternHigherOrderHole =>
257+
try ref(defn.InternalQuotedMatcher_higherOrderHole.termRef).appliedToTypeTrees(targs).appliedTo(args).withSpan(tree.span)
258258
finally {
259259
val patType = pat.tpe.widen
260260
val patType1 = patType.translateFromRepeated(toArray = false)
261261
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
262262
patBuf += pat1
263263
}
264264
case Apply(fn, pat :: Nil) if fn.symbol == defn.InternalQuoted_exprSplice =>
265-
try ref(defn.InternalQuoted_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
265+
try ref(defn.InternalQuotedMatcher_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
266266
finally {
267267
val patType = pat.tpe.widen
268268
val patType1 = patType.translateFromRepeated(toArray = false)
@@ -278,7 +278,7 @@ trait QuotesAndSplices {
278278
else
279279
tree
280280
case tdef: TypeDef =>
281-
if tdef.symbol.hasAnnotation(defn.InternalQuoted_patternTypeAnnot) then
281+
if tdef.symbol.hasAnnotation(defn.InternalQuotedMatcher_patternTypeAnnot) then
282282
transformTypeBindingTypeDef(tdef, typePatBuf)
283283
else if tdef.symbol.isClass then
284284
val kind = if tdef.symbol.is(Module) then "objects" else "classes"
@@ -313,7 +313,7 @@ trait QuotesAndSplices {
313313

314314
private def transformTypeBindingTypeDef(tdef: TypeDef, buff: mutable.Builder[Tree, List[Tree]])(using Context): Tree = {
315315
if (variance == -1)
316-
tdef.symbol.addAnnotation(Annotation(New(ref(defn.InternalQuoted_fromAboveAnnot.typeRef)).withSpan(tdef.span)))
316+
tdef.symbol.addAnnotation(Annotation(New(ref(defn.InternalQuotedMatcher_fromAboveAnnot.typeRef)).withSpan(tdef.span)))
317317
val bindingType = getBinding(tdef.symbol).symbol.typeRef
318318
val bindingTypeTpe = AppliedType(defn.QuotedTypeClass.typeRef, bindingType :: Nil)
319319
val bindName = tdef.name.toString.stripPrefix("$").toTermName

library/src-bootstrapped/scala/internal/quoted/CompileTime.scala

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,6 @@ object CompileTime {
2424
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.typeQuote`")
2525
def typeQuote[T <: AnyKind]: QuoteContext ?=> Type[T] = ???
2626

27-
// TODO move to internal.Quoted.Matcher
28-
/** A splice in a quoted pattern is desugared by the compiler into a call to this method */
29-
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternHole`")
30-
def patternHole[T]: T = ???
31-
32-
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternHigherOrderHole`")
33-
/** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */
34-
def patternHigherOrderHole[U](pat: Any, args: Any*): U = ???
35-
36-
// TODO move to internal.Quoted.Matcher
37-
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.higherOrderHole`")
38-
/** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */
39-
def higherOrderHole[U](args: Any*): U = ???
40-
41-
// TODO remove
42-
/** A splice of a name in a quoted pattern is desugared by wrapping getting this annotation */
43-
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternBindHole`")
44-
class patternBindHole extends Annotation
45-
46-
// TODO move to internal.Quoted.Matcher
47-
/** A splice of a name in a quoted pattern is that marks the definition of a type splice */
48-
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternType`")
49-
class patternType extends Annotation
50-
51-
// TODO move to internal.Quoted.Matcher
52-
/** A type pattern that must be aproximated from above */
53-
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.fromAbove`")
54-
class fromAbove extends Annotation
55-
5627
/** Artifact of pickled type splices
5728
*
5829
* During quote reification a quote `'{ ... F[$t] ... }` will be transformed into

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scala.internal.quoted
22

33
import scala.annotation.internal.sharable
4+
import scala.annotation.{Annotation, compileTimeOnly}
45

56
import scala.quoted._
67

@@ -94,7 +95,36 @@ import scala.quoted._
9495
*
9596
* ```
9697
*/
97-
private[quoted] object Matcher {
98+
object Matcher {
99+
100+
// TODO move to internal.Quoted.Matcher
101+
/** A splice in a quoted pattern is desugared by the compiler into a call to this method */
102+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternHole`")
103+
def patternHole[T]: T = ???
104+
105+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternHigherOrderHole`")
106+
/** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */
107+
def patternHigherOrderHole[U](pat: Any, args: Any*): U = ???
108+
109+
// TODO move to internal.Quoted.Matcher
110+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.higherOrderHole`")
111+
/** A higher order splice in a quoted pattern is desugared by the compiler into a call to this method */
112+
def higherOrderHole[U](args: Any*): U = ???
113+
114+
// TODO remove
115+
/** A splice of a name in a quoted pattern is desugared by wrapping getting this annotation */
116+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternBindHole`")
117+
class patternBindHole extends Annotation
118+
119+
// TODO move to internal.Quoted.Matcher
120+
/** A splice of a name in a quoted pattern is that marks the definition of a type splice */
121+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternType`")
122+
class patternType extends Annotation
123+
124+
// TODO move to internal.Quoted.Matcher
125+
/** A type pattern that must be aproximated from above */
126+
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.fromAbove`")
127+
class fromAbove extends Annotation
98128

99129
class QuoteMatcher[QCtx <: QuoteContext & Singleton](using val qctx: QCtx) {
100130
// TODO improve performance
@@ -164,13 +194,13 @@ private[quoted] object Matcher {
164194
private def hasFromAboveAnnotation(sym: Symbol) = sym.annots.exists(isFromAboveAnnotation)
165195

166196
private def isPatternTypeAnnotation(tree: Tree): Boolean = tree match {
167-
case New(tpt) => tpt.symbol == internal.Definitions_InternalQuoted_patternTypeAnnot
168-
case annot => annot.symbol.owner == internal.Definitions_InternalQuoted_patternTypeAnnot
197+
case New(tpt) => tpt.symbol == internal.Definitions_InternalQuotedMatcher_patternTypeAnnot
198+
case annot => annot.symbol.owner == internal.Definitions_InternalQuotedMatcher_patternTypeAnnot
169199
}
170200

171201
private def isFromAboveAnnotation(tree: Tree): Boolean = tree match {
172-
case New(tpt) => tpt.symbol == internal.Definitions_InternalQuoted_fromAboveAnnot
173-
case annot => annot.symbol.owner == internal.Definitions_InternalQuoted_fromAboveAnnot
202+
case New(tpt) => tpt.symbol == internal.Definitions_InternalQuotedMatcher_fromAboveAnnot
203+
case annot => annot.symbol.owner == internal.Definitions_InternalQuotedMatcher_fromAboveAnnot
174204
}
175205

176206
/** Check that all trees match with `mtch` and concatenate the results with &&& */
@@ -226,15 +256,15 @@ private[quoted] object Matcher {
226256
/* Term hole */
227257
// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
228258
case (scrutinee @ Typed(s, tpt1), Typed(TypeApply(patternHole, tpt :: Nil), tpt2))
229-
if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole &&
259+
if patternHole.symbol == internal.Definitions_InternalQuotedMatcher_patternHole &&
230260
s.tpe <:< tpt.tpe &&
231261
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
232262
matched(scrutinee.seal)
233263

234264
/* Term hole */
235265
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
236266
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
237-
if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole &&
267+
if patternHole.symbol == internal.Definitions_InternalQuotedMatcher_patternHole &&
238268
scrutinee.tpe <:< tpt.tpe =>
239269
matched(scrutinee.seal)
240270

@@ -243,7 +273,7 @@ private[quoted] object Matcher {
243273
// DEPRECATED: replaced with `higherOrderHole`
244274
// TODO: remove case
245275
case (scrutinee, pattern @ Apply(Select(TypeApply(patternHole, List(Inferred())), "apply"), args0 @ IdentArgs(args)))
246-
if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole =>
276+
if patternHole.symbol == internal.Definitions_InternalQuotedMatcher_patternHole =>
247277
def bodyFn(lambdaArgs: List[Tree]): Tree = {
248278
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf[List[Term]]).toMap
249279
new TreeMap {
@@ -262,7 +292,7 @@ private[quoted] object Matcher {
262292
/* Higher order term hole */
263293
// Matches an open term and wraps it into a lambda that provides the free variables
264294
case (scrutinee, pattern @ Apply(TypeApply(Ident("higherOrderHole"), List(Inferred())), Repeated(args, _) :: Nil))
265-
if pattern.symbol == internal.Definitions_InternalQuoted_higherOrderHole =>
295+
if pattern.symbol == internal.Definitions_InternalQuotedMatcher_higherOrderHole =>
266296

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

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,16 +1512,16 @@ trait CompilerInterface {
15121512
def Definitions_isTupleClass(sym: Symbol): Boolean
15131513

15141514
/** Symbol of scala.internal.CompileTime.patternHole */
1515-
def Definitions_InternalQuoted_patternHole: Symbol
1515+
def Definitions_InternalQuotedMatcher_patternHole: Symbol
15161516

15171517
/** Symbol of scala.internal.CompileTime.higherOrderHole */
1518-
def Definitions_InternalQuoted_higherOrderHole: Symbol
1518+
def Definitions_InternalQuotedMatcher_higherOrderHole: Symbol
15191519

15201520
/** Symbol of scala.internal.CompileTime.patternType */
1521-
def Definitions_InternalQuoted_patternTypeAnnot: Symbol
1521+
def Definitions_InternalQuotedMatcher_patternTypeAnnot: Symbol
15221522

15231523
/** Symbol of scala.internal.CompileTime.fromAbove */
1524-
def Definitions_InternalQuoted_fromAboveAnnot: Symbol
1524+
def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol
15251525

15261526
def Definitions_UnitType: Type
15271527
def Definitions_ByteType: Type

0 commit comments

Comments
 (0)