Skip to content

Commit 63f07ae

Browse files
committed
Inline Lambda.apply
1 parent 5b0935c commit 63f07ae

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,6 @@ object Matcher {
187187
case _ => None
188188
end TypeTreeTypeTest
189189

190-
object Lambda:
191-
def apply(owner: Symbol, tpe: MethodType, rhsFn: (Symbol, List[Tree]) => Tree): Block =
192-
val meth = newSymbol(owner, nme.ANON_FUN, Synthetic | Method, tpe)
193-
Closure(meth, tss => rhsFn(meth, tss.head))
194-
end Lambda
195-
196190
(scrutinee, pattern) match
197191

198192
/* Term hole */
@@ -214,29 +208,24 @@ object Matcher {
214208
// Matches an open term and wraps it into a lambda that provides the free variables
215209
case (scrutinee, pattern @ Apply(TypeApply(Ident(_), List(TypeTree())), SeqLiteral(args, _) :: Nil))
216210
if pattern.symbol.eq(defn.QuotedRuntimePatterns_higherOrderHole) =>
217-
218-
def bodyFn(lambdaArgs: List[Tree]): Tree = {
219-
val argsMap = args.map(_.symbol).zip(lambdaArgs).toMap
220-
new TreeMap {
211+
val names: List[TermName] = args.map {
212+
case Block(List(DefDef(nme.ANON_FUN, _, _, Apply(Ident(name), _))), _) => name.asTermName
213+
case arg => arg.symbol.name.asTermName
214+
}
215+
val argTypes = args.map(x => x.tpe.widenTermRefExpr)
216+
val methTpe = MethodType(names)(_ => argTypes, _ => pattern.tpe)
217+
val meth = newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, methTpe)
218+
def bodyFn(lambdaArgss: List[List[Tree]]): Tree = {
219+
val argsMap = args.map(_.symbol).zip(lambdaArgss.head).toMap
220+
val body = new TreeMap {
221221
override def transform(tree: Tree)(using Context): Tree =
222222
tree match
223223
case tree: Ident => summon[Env].get(tree.symbol).flatMap(argsMap.get).getOrElse(tree)
224224
case tree => super.transform(tree)
225225
}.transform(scrutinee)
226+
TreeOps(body).changeNonLocalOwners(meth)
226227
}
227-
val names: List[TermName] = args.map {
228-
case Block(List(DefDef(nme.ANON_FUN, _, _, Apply(Ident(name), _))), _) => name.asTermName
229-
case arg => arg.symbol.name.asTermName
230-
}
231-
val argTypes = args.map(x => x.tpe.widenTermRefExpr)
232-
val resType = pattern.tpe
233-
val res =
234-
Lambda(
235-
ctx.owner,
236-
MethodType(names)(
237-
_ => argTypes, _ => resType),
238-
(meth, x) => TreeOps(bodyFn(x)).changeNonLocalOwners(meth))
239-
matched(res)
228+
matched(Closure(meth, bodyFn))
240229

241230
//
242231
// Match two equivalent trees

0 commit comments

Comments
 (0)