Skip to content

Commit

Permalink
Merge pull request #9920 from dotty-staging/remove-quoted-Lambda-extr…
Browse files Browse the repository at this point in the history
…actor

Remove quoted.Lambda extractor
  • Loading branch information
liufengyun authored Sep 30, 2020
2 parents 68e34fc + 05e33df commit c40ef6e
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 107 deletions.
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 @@ -2668,46 +2668,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.

0 comments on commit c40ef6e

Please sign in to comment.