Skip to content

Commit 05e33df

Browse files
committed
Remove quoted.Lambda extractor
This extractor is by nature unsound because it ignores argument semantics. `Expr.betaReduce` provides a sound version of this conversion with a slightly diferent API. The error messages for this extractors where never good due to the complexity of its signature. This kind of unsafe transformations should be performed on the reflection API instead.
1 parent be6bcaf commit 05e33df

File tree

7 files changed

+0
-107
lines changed

7 files changed

+0
-107
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,46 +2593,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
25932593
case _ =>
25942594
None
25952595

2596-
def lambdaExtractor(fn: Term, paramTypes: List[Type]): Option[List[Term] => Term] = {
2597-
def rec(fn: Term, transformBody: Term => Term): Option[List[Term] => Term] = {
2598-
fn match {
2599-
case tpd.Inlined(call, bindings, expansion) =>
2600-
// this case must go before closureDef to avoid dropping the inline node
2601-
rec(expansion, tpd.cpy.Inlined(fn)(call, bindings, _))
2602-
case tpd.Typed(expr, tpt) =>
2603-
val tpe = tpt.tpe.dropDependentRefinement
2604-
// we checked that this is a plain Function closure, so there will be an apply method with a MethodType
2605-
// and the expected signature based on param types
2606-
val expectedSig = Signature(Nil, tpnme.WILDCARD).prependTermParams(paramTypes, false)
2607-
val method = tpt.tpe.member(nme.apply).atSignature(expectedSig)
2608-
if method.symbol.is(Deferred) then
2609-
val methodType = method.info.asInstanceOf[MethodType]
2610-
// result might contain paramrefs, so we substitute them with arg termrefs
2611-
val resultTypeWithSubst = methodType.resultType.substParams(methodType, paramTypes)
2612-
rec(expr, tpd.Typed(_, tpd.TypeTree(resultTypeWithSubst).withSpan(tpt.span)))
2613-
else
2614-
None
2615-
case cl @ tpd.closureDef(ddef) =>
2616-
def replace(body: Term, argRefs: List[Term]): Term = {
2617-
val paramSyms = ddef.vparamss.head.map(param => param.symbol)
2618-
val paramToVals = paramSyms.zip(argRefs).toMap
2619-
new dotc.ast.TreeTypeMap(
2620-
oldOwners = ddef.symbol :: Nil,
2621-
newOwners = ctx.owner :: Nil,
2622-
treeMap = tree => paramToVals.get(tree.symbol).map(_.withSpan(tree.span)).getOrElse(tree)
2623-
).transform(body)
2624-
}
2625-
Some(argRefs => replace(transformBody(ddef.rhs), argRefs))
2626-
case tpd.Block(stats, expr) =>
2627-
// this case must go after closureDef to avoid matching the closure
2628-
rec(expr, tpd.cpy.Block(fn)(stats, _))
2629-
case _ =>
2630-
None
2631-
}
2632-
}
2633-
rec(fn, identity)
2634-
}
2635-
26362596
def compilerId: Int = rootContext.outersIterator.toList.last.hashCode()
26372597

26382598
end tasty

library/src-bootstrapped/scala/quoted/Lambda.scala

Lines changed: 0 additions & 32 deletions
This file was deleted.

library/src/scala/internal/tasty/CompilerInterface.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ trait CompilerInterface { self: scala.tasty.Reflection =>
6464
/** Returns Some with a beta-reduced application or None */
6565
def betaReduce(tree: Term): Option[Term]
6666

67-
def lambdaExtractor(term: Term, paramTypes: List[Type]): Option[List[Term] => Term]
68-
6967
def compilerId: Int
7068

7169
}

tests/run-macros/lambda-extractor-1/Macro_1.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/run-macros/lambda-extractor-1/Test_2.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/run-macros/lambda-extractor-2/Macro_1.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/run-macros/lambda-extractor-2/Test_2.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)