@@ -45,9 +45,9 @@ object QuoteContextImpl {
4545
4646}
4747
48- class QuoteContextImpl private (ctx : Context ) extends QuoteContext :
48+ class QuoteContextImpl private (ctx : Context ) extends QuoteContext , scala.internal.quoted. CompilerInterface :
4949
50- object reflect extends scala.tasty.Reflection , scala.internal.tasty. CompilerInterface :
50+ object reflect extends scala.tasty.Reflection :
5151
5252 def rootContext : Context = ctx
5353
@@ -2615,70 +2615,72 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
26152615 private def withDefaultPos [T <: Tree ](fn : Context ?=> T ): T =
26162616 fn(using ctx.withSource(Position .ofMacroExpansion.source)).withSpan(Position .ofMacroExpansion.span)
26172617
2618- def unpickleTerm (pickledQuote : PickledQuote ): Term =
2619- PickledQuotes .unpickleTerm(pickledQuote)
2620-
2621- def unpickleTypeTree (pickledQuote : PickledQuote ): TypeTree =
2622- PickledQuotes .unpickleTypeTree(pickledQuote)
2618+ end reflect
26232619
2624- def termMatch ( scrutinee : Term , pattern : Term ): Option [ Tuple ] =
2625- treeMatch(scrutinee, pattern )
2620+ def unpickleTerm ( pickledQuote : PickledQuote ): reflect. Term =
2621+ PickledQuotes .unpickleTerm(pickledQuote)( using reflect.rootContext )
26262622
2627- def typeTreeMatch ( scrutinee : TypeTree , pattern : TypeTree ): Option [ Tuple ] =
2628- treeMatch(scrutinee, pattern )
2623+ def unpickleTypeTree ( pickledQuote : PickledQuote ): reflect. TypeTree =
2624+ PickledQuotes .unpickleTypeTree(pickledQuote)( using reflect.rootContext )
26292625
2630- private def treeMatch (scrutinee : Tree , pattern : Tree ): Option [Tuple ] = {
2631- def isTypeHoleDef (tree : Tree ): Boolean =
2632- tree match
2633- case tree : TypeDef =>
2634- tree.symbol.hasAnnotation(dotc.core.Symbols .defn.InternalQuotedPatterns_patternTypeAnnot )
2635- case _ => false
2636-
2637- def extractTypeHoles (pat : Term ): (Term , List [Symbol ]) =
2638- pat match
2639- case tpd.Inlined (_, Nil , pat2) => extractTypeHoles(pat2)
2640- case tpd.Block (stats @ ((typeHole : TypeDef ) :: _), expr) if isTypeHoleDef(typeHole) =>
2641- val holes = stats.takeWhile(isTypeHoleDef).map(_.symbol)
2642- val otherStats = stats.dropWhile(isTypeHoleDef)
2643- (tpd.cpy.Block (pat)(otherStats, expr), holes)
2644- case _ =>
2645- (pat, Nil )
2626+ def termMatch (scrutinee : reflect.Term , pattern : reflect.Term ): Option [Tuple ] =
2627+ treeMatch(scrutinee, pattern)
26462628
2647- val (pat1, typeHoles) = extractTypeHoles(pattern)
2629+ def typeTreeMatch (scrutinee : reflect.TypeTree , pattern : reflect.TypeTree ): Option [Tuple ] =
2630+ treeMatch(scrutinee, pattern)
26482631
2649- val ctx1 =
2650- if typeHoles.isEmpty then ctx
2651- else
2652- val ctx1 = ctx.fresh.setFreshGADTBounds.addMode(dotc.core.Mode .GadtConstraintInference )
2653- ctx1.gadt.addToConstraint(typeHoles)
2654- ctx1
2655-
2656- val qctx1 = dotty.tools.dotc.quoted.QuoteContextImpl ()(using ctx1)
2657- .asInstanceOf [QuoteContext { val reflect : QuoteContextImpl .this .reflect.type }]
2632+ private def treeMatch (scrutinee : reflect.Tree , pattern : reflect.Tree ): Option [Tuple ] = {
2633+ import reflect ._
2634+ given Context = rootContext
2635+ def isTypeHoleDef (tree : Tree ): Boolean =
2636+ tree match
2637+ case tree : TypeDef =>
2638+ tree.symbol.hasAnnotation(dotc.core.Symbols .defn.InternalQuotedPatterns_patternTypeAnnot )
2639+ case _ => false
26582640
2659- val matcher = new Matcher .QuoteMatcher [qctx1.type ](qctx1) {
2660- def patternHoleSymbol : Symbol = dotc.core.Symbols .defn.InternalQuotedPatterns_patternHole
2661- def higherOrderHoleSymbol : Symbol = dotc.core.Symbols .defn.InternalQuotedPatterns_higherOrderHole
2662- }
2641+ def extractTypeHoles (pat : Term ): (Term , List [Symbol ]) =
2642+ pat match
2643+ case tpd.Inlined (_, Nil , pat2) => extractTypeHoles(pat2)
2644+ case tpd.Block (stats @ ((typeHole : TypeDef ) :: _), expr) if isTypeHoleDef(typeHole) =>
2645+ val holes = stats.takeWhile(isTypeHoleDef).map(_.symbol)
2646+ val otherStats = stats.dropWhile(isTypeHoleDef)
2647+ (tpd.cpy.Block (pat)(otherStats, expr), holes)
2648+ case _ =>
2649+ (pat, Nil )
2650+
2651+ val (pat1, typeHoles) = extractTypeHoles(pattern)
2652+
2653+ val ctx1 =
2654+ if typeHoles.isEmpty then ctx
2655+ else
2656+ val ctx1 = ctx.fresh.setFreshGADTBounds.addMode(dotc.core.Mode .GadtConstraintInference )
2657+ ctx1.gadt.addToConstraint(typeHoles)
2658+ ctx1
2659+
2660+ val qctx1 = dotty.tools.dotc.quoted.QuoteContextImpl ()(using ctx1)
2661+ .asInstanceOf [QuoteContext & scala.internal.quoted.CompilerInterface ]
2662+
2663+ val matcher = new Matcher .QuoteMatcher [qctx1.type ](qctx1) {
2664+ def patternHoleSymbol : qctx1.reflect.Symbol = dotc.core.Symbols .defn.InternalQuotedPatterns_patternHole .asInstanceOf
2665+ def higherOrderHoleSymbol : qctx1.reflect.Symbol = dotc.core.Symbols .defn.InternalQuotedPatterns_higherOrderHole .asInstanceOf
2666+ }
26632667
2664- val matchings =
2665- if pat1.isType then matcher.termMatch(scrutinee, pat1)
2666- else matcher.termMatch(scrutinee, pat1)
2667-
2668- // val matchings = matcher.termMatch(scrutinee, pattern)
2669- if typeHoles.isEmpty then matchings
2670- else {
2671- // After matching and doing all subtype checks, we have to approximate all the type bindings
2672- // that we have found, seal them in a quoted.Type and add them to the result
2673- def typeHoleApproximation (sym : Symbol ) =
2674- ctx1.gadt.approximation(sym, ! sym.hasAnnotation(dotc.core.Symbols .defn.InternalQuotedPatterns_fromAboveAnnot )).seal
2675- matchings.map { tup =>
2676- Tuple .fromIArray(typeHoles.map(typeHoleApproximation).toArray.asInstanceOf [IArray [Object ]]) ++ tup
2677- }
2668+ val matchings =
2669+ if pat1.isType then matcher.termMatch(scrutinee.asInstanceOf [matcher.qctx.reflect.Term ], pat1.asInstanceOf [matcher.qctx.reflect.Term ])
2670+ else matcher.termMatch(scrutinee.asInstanceOf [matcher.qctx.reflect.Term ], pat1.asInstanceOf [matcher.qctx.reflect.Term ])
2671+
2672+ // val matchings = matcher.termMatch(scrutinee, pattern)
2673+ if typeHoles.isEmpty then matchings
2674+ else {
2675+ // After matching and doing all subtype checks, we have to approximate all the type bindings
2676+ // that we have found, seal them in a quoted.Type and add them to the result
2677+ def typeHoleApproximation (sym : Symbol ) =
2678+ ctx1.gadt.approximation(sym, ! sym.hasAnnotation(dotc.core.Symbols .defn.InternalQuotedPatterns_fromAboveAnnot )).asInstanceOf [qctx1.reflect.TypeRepr ].seal
2679+ matchings.map { tup =>
2680+ Tuple .fromIArray(typeHoles.map(typeHoleApproximation).toArray.asInstanceOf [IArray [Object ]]) ++ tup
26782681 }
26792682 }
2680-
2681- end reflect
2683+ }
26822684
26832685 private [this ] val hash = QuoteContextImpl .scopeId(using ctx)
26842686 override def hashCode : Int = hash
0 commit comments