Skip to content

Remove quoted.Lambda extractor #9920

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 0 additions & 40 deletions compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2593,46 +2593,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
case _ =>
None

def lambdaExtractor(fn: Term, paramTypes: List[Type]): Option[List[Term] => Term] = {
def rec(fn: Term, transformBody: Term => Term): Option[List[Term] => Term] = {
fn match {
case tpd.Inlined(call, bindings, expansion) =>
// this case must go before closureDef to avoid dropping the inline node
rec(expansion, tpd.cpy.Inlined(fn)(call, bindings, _))
case tpd.Typed(expr, tpt) =>
val tpe = tpt.tpe.dropDependentRefinement
// we checked that this is a plain Function closure, so there will be an apply method with a MethodType
// and the expected signature based on param types
val expectedSig = Signature(Nil, tpnme.WILDCARD).prependTermParams(paramTypes, false)
val method = tpt.tpe.member(nme.apply).atSignature(expectedSig)
if method.symbol.is(Deferred) then
val methodType = method.info.asInstanceOf[MethodType]
// result might contain paramrefs, so we substitute them with arg termrefs
val resultTypeWithSubst = methodType.resultType.substParams(methodType, paramTypes)
rec(expr, tpd.Typed(_, tpd.TypeTree(resultTypeWithSubst).withSpan(tpt.span)))
else
None
case cl @ tpd.closureDef(ddef) =>
def replace(body: Term, argRefs: List[Term]): Term = {
val paramSyms = ddef.vparamss.head.map(param => param.symbol)
val paramToVals = paramSyms.zip(argRefs).toMap
new dotc.ast.TreeTypeMap(
oldOwners = ddef.symbol :: Nil,
newOwners = ctx.owner :: Nil,
treeMap = tree => paramToVals.get(tree.symbol).map(_.withSpan(tree.span)).getOrElse(tree)
).transform(body)
}
Some(argRefs => replace(transformBody(ddef.rhs), argRefs))
case tpd.Block(stats, expr) =>
// this case must go after closureDef to avoid matching the closure
rec(expr, tpd.cpy.Block(fn)(stats, _))
case _ =>
None
}
}
rec(fn, identity)
}

def compilerId: Int = rootContext.outersIterator.toList.last.hashCode()

end tasty
Expand Down
32 changes: 0 additions & 32 deletions library/src-bootstrapped/scala/quoted/Lambda.scala

This file was deleted.

2 changes: 0 additions & 2 deletions library/src/scala/internal/tasty/CompilerInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ trait CompilerInterface { self: scala.tasty.Reflection =>
/** Returns Some with a beta-reduced application or None */
def betaReduce(tree: Term): Option[Term]

def lambdaExtractor(term: Term, paramTypes: List[Type]): Option[List[Term] => Term]

def compilerId: Int

}
Expand Down
11 changes: 0 additions & 11 deletions tests/run-macros/lambda-extractor-1/Macro_1.scala

This file was deleted.

6 changes: 0 additions & 6 deletions tests/run-macros/lambda-extractor-1/Test_2.scala

This file was deleted.

11 changes: 0 additions & 11 deletions tests/run-macros/lambda-extractor-2/Macro_1.scala

This file was deleted.

5 changes: 0 additions & 5 deletions tests/run-macros/lambda-extractor-2/Test_2.scala

This file was deleted.