Skip to content

Commit 89e84d2

Browse files
committed
Fix #6341: Revise purity checking
There is some confusion on terms that needs to be fixed. Step 1: Make `SimplyPure apply to paths only. The only point where it is used is in eta expansion to answer the question whether in a partial application `f(e, _)` the expression `e` should be lifted out, giving `{ val x = e; y => f(x, y) }` instead of `y => f(e, y)`. With the change, closures and new expressions are never simply pure, so are always lifted out. This can reduce the number of allocations, if the lambda is applied several times.
1 parent 22ba798 commit 89e84d2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
367367
}
368368

369369
/** The purity level of this expression.
370-
* @return SimplyPure if expression has no side effects and cannot contain local definitions
370+
* @return SimplyPure if expression has no side effects is a path
371371
* Pure if expression has no side effects
372372
* Idempotent if running the expression a second time has no side effects
373373
* Impure otherwise
@@ -381,16 +381,15 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
381381
case EmptyTree
382382
| This(_)
383383
| Super(_, _)
384-
| Literal(_)
385-
| Closure(_, _, _) =>
384+
| Literal(_) =>
386385
SimplyPure
387386
case Ident(_) =>
388387
refPurity(tree)
389388
case Select(qual, _) =>
390389
if (tree.symbol.is(Erased)) Pure
391390
else refPurity(tree).min(exprPurity(qual))
392-
case New(_) =>
393-
SimplyPure
391+
case New(_) | Closure(_, _, _) =>
392+
Pure
394393
case TypeApply(fn, _) =>
395394
if (fn.symbol.is(Erased)) Pure else exprPurity(fn)
396395
case Apply(fn, args) =>

0 commit comments

Comments
 (0)