Skip to content

Commit 07fa260

Browse files
committed
Improve documentation
1 parent 2aca3be commit 07fa260

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

compiler/src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,23 @@ class TailRec extends MiniPhase {
175175
).transform(rhsSemiTransformed)
176176
}
177177

178-
// Is a simple this a simple recursive tail call, possibly with swapped or modified pure arguments
178+
/** Is the RHS a direct recursive tailcall, possibly with swapped arguments or modified pure arguments.
179+
* ```
180+
* def f(<params>): T = f(<args>)
181+
* ```
182+
* where `<args>` are pure arguments or references to parameters in `<params>`.
183+
*/
179184
def isInfiniteRecCall(tree: Tree): Boolean = {
180-
def statOk(stat: Tree): Boolean = stat match {
181-
case stat: ValDef if stat.name.is(TailTempName) || !stat.symbol.is(Mutable) => statOk(stat.rhs)
182-
case Assign(lhs: Ident, rhs) if lhs.symbol.name.is(TailLocalName) => statOk(rhs)
185+
def tailArgOrPureExpr(stat: Tree): Boolean = stat match {
186+
case stat: ValDef if stat.name.is(TailTempName) || !stat.symbol.is(Mutable) => tailArgOrPureExpr(stat.rhs)
187+
case Assign(lhs: Ident, rhs) if lhs.symbol.name.is(TailLocalName) => tailArgOrPureExpr(rhs)
183188
case stat: Ident if stat.symbol.name.is(TailLocalName) => true
184189
case _ => tpd.isPureExpr(stat)
185190
}
186191
tree match {
187192
case Typed(expr, _) => isInfiniteRecCall(expr)
188193
case Return(Literal(Constant(())), label) => label.symbol == transformer.continueLabel
189-
case Block(stats, expr) => stats.forall(statOk) && isInfiniteRecCall(expr)
194+
case Block(stats, expr) => stats.forall(tailArgOrPureExpr) && isInfiniteRecCall(expr)
190195
case _ => false
191196
}
192197
}

0 commit comments

Comments
 (0)