@@ -122,7 +122,9 @@ object Matcher {
122
122
@ compileTimeOnly(" Illegal reference to `scala.internal.quoted.CompileTime.fromAbove`" )
123
123
class fromAbove extends Annotation
124
124
125
- class QuoteMatcher [QCtx <: QuoteContext & Singleton ](using val qctx : QCtx ) {
125
+ class QuoteMatcher [QCtx <: QuoteContext & Singleton ](val qctx0 : QCtx ) {
126
+ val qctx = scala.internal.tasty.CompilerInterface .leaked(qctx0)
127
+
126
128
// TODO improve performance
127
129
128
130
// TODO use flag from qctx.tasty.rootContext. Maybe -debug or add -debug-macros
@@ -147,14 +149,14 @@ object Matcher {
147
149
def termMatch (scrutineeTerm : Term , patternTerm : Term , hasTypeSplices : Boolean ): Option [Tuple ] = {
148
150
given Env = Map .empty
149
151
if (hasTypeSplices) {
150
- val ctx : Context = internal .Constraints_init (rootContext)
152
+ val ctx : Context = qctx.tasty .Constraints_init (rootContext)
151
153
given Context = ctx
152
154
val matchings = scrutineeTerm =?= patternTerm
153
155
// After matching and doing all subtype checks, we have to approximate all the type bindings
154
156
// that we have found and seal them in a quoted.Type
155
157
matchings.asOptionOfTuple.map { tup =>
156
158
Tuple .fromArray(tup.toArray.map { // TODO improve performance
157
- case x : SymBinding => internal .Constraints_approximation (summon[Context ])(x.sym, ! x.fromAbove).seal
159
+ case x : SymBinding => qctx.tasty .Constraints_approximation (summon[Context ])(x.sym, ! x.fromAbove).seal
158
160
case x => x
159
161
})
160
162
}
@@ -168,14 +170,14 @@ object Matcher {
168
170
def typeTreeMatch (scrutineeTypeTree : TypeTree , patternTypeTree : TypeTree , hasTypeSplices : Boolean ): Option [Tuple ] = {
169
171
given Env = Map .empty
170
172
if (hasTypeSplices) {
171
- val ctx : Context = internal .Constraints_init (rootContext)
173
+ val ctx : Context = qctx.tasty .Constraints_init (rootContext)
172
174
given Context = ctx
173
175
val matchings = scrutineeTypeTree =?= patternTypeTree
174
176
// After matching and doing all subtype checks, we have to approximate all the type bindings
175
177
// that we have found and seal them in a quoted.Type
176
178
matchings.asOptionOfTuple.map { tup =>
177
179
Tuple .fromArray(tup.toArray.map { // TODO improve performance
178
- case x : SymBinding => internal .Constraints_approximation (summon[Context ])(x.sym, ! x.fromAbove).seal
180
+ case x : SymBinding => qctx.tasty .Constraints_approximation (summon[Context ])(x.sym, ! x.fromAbove).seal
179
181
case x => x
180
182
})
181
183
}
@@ -190,13 +192,13 @@ object Matcher {
190
192
private def hasFromAboveAnnotation (sym : Symbol ) = sym.annots.exists(isFromAboveAnnotation)
191
193
192
194
private def isPatternTypeAnnotation (tree : Tree ): Boolean = tree match {
193
- case New (tpt) => tpt.symbol == internal .Definitions_InternalQuotedMatcher_patternTypeAnnot
194
- case annot => annot.symbol.owner == internal .Definitions_InternalQuotedMatcher_patternTypeAnnot
195
+ case New (tpt) => tpt.symbol == qctx.tasty .Definitions_InternalQuotedMatcher_patternTypeAnnot
196
+ case annot => annot.symbol.owner == qctx.tasty .Definitions_InternalQuotedMatcher_patternTypeAnnot
195
197
}
196
198
197
199
private def isFromAboveAnnotation (tree : Tree ): Boolean = tree match {
198
- case New (tpt) => tpt.symbol == internal .Definitions_InternalQuotedMatcher_fromAboveAnnot
199
- case annot => annot.symbol.owner == internal .Definitions_InternalQuotedMatcher_fromAboveAnnot
200
+ case New (tpt) => tpt.symbol == qctx.tasty .Definitions_InternalQuotedMatcher_fromAboveAnnot
201
+ case annot => annot.symbol.owner == qctx.tasty .Definitions_InternalQuotedMatcher_fromAboveAnnot
200
202
}
201
203
202
204
/** Check that all trees match with `mtch` and concatenate the results with &&& */
@@ -250,22 +252,22 @@ object Matcher {
250
252
/* Term hole */
251
253
// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
252
254
case (scrutinee @ Typed (s, tpt1), Typed (TypeApply (patternHole, tpt :: Nil ), tpt2))
253
- if patternHole.symbol == internal .Definitions_InternalQuotedMatcher_patternHole &&
255
+ if patternHole.symbol == qctx.tasty .Definitions_InternalQuotedMatcher_patternHole &&
254
256
s.tpe <:< tpt.tpe &&
255
257
tpt2.tpe.derivesFrom(defn.RepeatedParamClass ) =>
256
258
matched(scrutinee.seal)
257
259
258
260
/* Term hole */
259
261
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
260
262
case (ClosedPatternTerm (scrutinee), TypeApply (patternHole, tpt :: Nil ))
261
- if patternHole.symbol == internal .Definitions_InternalQuotedMatcher_patternHole &&
263
+ if patternHole.symbol == qctx.tasty .Definitions_InternalQuotedMatcher_patternHole &&
262
264
scrutinee.tpe <:< tpt.tpe =>
263
265
matched(scrutinee.seal)
264
266
265
267
/* Higher order term hole */
266
268
// Matches an open term and wraps it into a lambda that provides the free variables
267
269
case (scrutinee, pattern @ Apply (TypeApply (Ident (" higherOrderHole" ), List (Inferred ())), Repeated (args, _) :: Nil ))
268
- if pattern.symbol == internal .Definitions_InternalQuotedMatcher_higherOrderHole =>
270
+ if pattern.symbol == qctx.tasty .Definitions_InternalQuotedMatcher_higherOrderHole =>
269
271
270
272
def bodyFn (lambdaArgs : List [Tree ]): Tree = {
271
273
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf [List [Term ]]).toMap
@@ -323,7 +325,7 @@ object Matcher {
323
325
fn1 =?= fn2 &&& args1 =?= args2
324
326
325
327
case (Block (stats1, expr1), Block (binding :: stats2, expr2)) if isTypeBinding(binding) =>
326
- qctx.tasty.internal. Constraints_add (summon[Context ])(binding.symbol :: Nil )
328
+ qctx.tasty.Constraints_add (summon[Context ])(binding.symbol :: Nil )
327
329
matched(new SymBinding (binding.symbol, hasFromAboveAnnotation(binding.symbol))) &&& Block (stats1, expr1) =?= Block (stats2, expr2)
328
330
329
331
/* Match block */
@@ -340,7 +342,7 @@ object Matcher {
340
342
341
343
case (scrutinee, Block (typeBindings, expr2)) if typeBindings.forall(isTypeBinding) =>
342
344
val bindingSymbols = typeBindings.map(_.symbol)
343
- qctx.tasty.internal. Constraints_add (summon[Context ])(bindingSymbols)
345
+ qctx.tasty.Constraints_add (summon[Context ])(bindingSymbols)
344
346
bindingSymbols.foldRight(scrutinee =?= expr2)((x, acc) => matched(new SymBinding (x, hasFromAboveAnnotation(x))) &&& acc)
345
347
346
348
/* Match if */
0 commit comments