Skip to content

Commit 0abeb8d

Browse files
committed
Add docs and use foldLeft
1 parent 04212e9 commit 0abeb8d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,12 +1896,14 @@ class KernelImpl(val rootContext: core.Contexts.Context) extends Kernel {
18961896
}
18971897

18981898
def betaReduce(fn: Term, args: List[Term]) given (ctx: Context): Term = {
1899-
val (argVals, argRefs) = args.map(arg => arg.tpe match {
1900-
case tpe: SingletonType if isIdempotentExpr(arg) => (Nil, arg)
1899+
val (argVals0, argRefs0) = args.foldLeft((List.empty[ValDef], List.empty[Tree])) { case ((acc1, acc2), arg) => arg.tpe match {
1900+
case tpe: SingletonType if isIdempotentExpr(arg) => (acc1, arg :: acc2)
19011901
case _ =>
19021902
val argVal = SyntheticValDef(NameKinds.UniqueName.fresh("x".toTermName), arg).withSpan(arg.span)
1903-
(argVal :: Nil, ref(argVal.symbol))
1904-
}).unzip
1903+
(argVal :: acc1, ref(argVal.symbol) :: acc2)
1904+
}}
1905+
val argVals = argVals0.reverse
1906+
val argRefs = argRefs0.reverse
19051907
def rec(fn: Tree): Tree = fn match {
19061908
case Inlined(call, bindings, expansion) =>
19071909
// this case must go before closureDef to avoid dropping the inline node
@@ -1919,7 +1921,7 @@ class KernelImpl(val rootContext: core.Contexts.Context) extends Kernel {
19191921
case _ =>
19201922
fn.select(nme.apply).appliedToArgs(argRefs).withSpan(fn.span)
19211923
}
1922-
seq(argVals.flatten, rec(fn))
1924+
seq(argVals, rec(fn))
19231925
}
19241926

19251927
//

library/src/scala/tasty/reflect/Kernel.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,9 @@ trait Kernel {
15381538
*/
15391539
def searchImplicit(tpe: Type) given (ctx: Context): ImplicitSearchResult
15401540

1541+
/** Inline fn if it is an explicit closure possibly nested inside the expression of a block.
1542+
* Otherwise apply the arguments to the closure.
1543+
*/
15411544
def betaReduce(f: Term, args: List[Term]) given (ctx: Context): Term
15421545

15431546
}

0 commit comments

Comments
 (0)