Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port scala.quoted.runtime.impl.QuoteMatcher #12402

Merged
merged 21 commits into from
May 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve Matching.matched
  • Loading branch information
nicolasstucki committed May 10, 2021
commit 2362c8f38b2b37a862d9e68932a514a68034c7c9
13 changes: 8 additions & 5 deletions compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala
Original file line number Diff line number Diff line change
@@ -201,14 +201,14 @@ object Matcher {
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
s.tpe <:< tpt.tpe &&
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
matched(scrutinee)

/* Term hole */
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
scrutinee.tpe <:< tpt.tpe =>
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
matched(scrutinee)

/* Higher order term hole */
// Matches an open term and wraps it into a lambda that provides the free variables
@@ -235,8 +235,8 @@ object Matcher {
ctx.owner,
MethodType(names)(
_ => argTypes, _ => resType),
(meth, x) => TreeOps(bodyFn(x)).changeNonLocalOwners(meth.asInstanceOf))
matched(quotes.reflect.TreeMethods.asExpr(res.asInstanceOf[quotes.reflect.Tree]))
(meth, x) => TreeOps(bodyFn(x)).changeNonLocalOwners(meth))
matched(res)

//
// Match two equivalent trees
@@ -421,8 +421,11 @@ object Matcher {
private object Matching {

def notMatched: Matching = None

val matched: Matching = Some(Tuple())
def matched(x: Any): Matching = Some(Tuple1(x))

def matched(tree: Tree)(using Context): Matching =
Some(Tuple1(new ExprImpl(tree, SpliceScope.getCurrent)))

extension (self: Matching)
def asOptionOfTuple: Option[Tuple] = self