Skip to content

Commit

Permalink
Make QuoteMatcher to hold debug option
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptometer committed Jul 5, 2023
1 parent 9e379d1 commit 9729d35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ import dotty.tools.dotc.util.optional
*
* ```
*/
object QuoteMatcher {
class QuoteMatcher(private val debug: Boolean) {
import tpd.*

/** Sequence of matched expressions.
Expand Down Expand Up @@ -131,7 +131,6 @@ object QuoteMatcher {
given Env = Map.empty
scrutinee =?= pat1
}.map { matchings =>
import QuoteMatcher.MatchResult.*
lazy val spliceScope = SpliceScope.getCurrent
// After matching and doing all subtype checks, we have to approximate all the type bindings
// that we have found, seal them in a quoted.Type and add them to the result
Expand Down Expand Up @@ -462,7 +461,7 @@ object QuoteMatcher {
notMatched
end runMatch

if ctx.settings.YdebugMacros.value then
if debug then
try {
runMatch()
} catch {
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ object QuotesImpl {
class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler, QuoteMatching:

private val xCheckMacro: Boolean = ctx.settings.XcheckMacros.value
private val quoteMatcher: QuoteMatcher = QuoteMatcher(ctx.settings.YdebugMacros.value)

extension [T](self: scala.quoted.Expr[T])
def show: String =
reflect.Printer.TreeCode.show(reflect.asTerm(self))

def matches(that: scala.quoted.Expr[Any]): Boolean =
QuoteMatcher.treeMatch(reflect.asTerm(self), reflect.asTerm(that)).nonEmpty
quoteMatcher.treeMatch(reflect.asTerm(self), reflect.asTerm(that)).nonEmpty

def valueOrAbort(using fromExpr: FromExpr[T]): T =
def reportError =
Expand Down Expand Up @@ -3159,14 +3160,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def unapply[TypeBindings, Tup <: Tuple](scrutinee: scala.quoted.Expr[Any])(using pattern: scala.quoted.Expr[Any]): Option[Tup] =
val scrutineeTree = reflect.asTerm(scrutinee)
val patternTree = reflect.asTerm(pattern)
QuoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
quoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
end ExprMatch

object TypeMatch extends TypeMatchModule:
def unapply[TypeBindings, Tup <: Tuple](scrutinee: scala.quoted.Type[?])(using pattern: scala.quoted.Type[?]): Option[Tup] =
val scrutineeTree = reflect.TypeTree.of(using scrutinee)
val patternTree = reflect.TypeTree.of(using pattern)
QuoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
quoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
end TypeMatch

end QuotesImpl

0 comments on commit 9729d35

Please sign in to comment.