Skip to content

Commit 5a2e79f

Browse files
committed
Address review comments
1 parent e6b2db5 commit 5a2e79f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
366366
// But if we do that the repl/vars test break. Need to figure out why that's the case.
367367
}
368368

369-
/** The purity level of this expression.
369+
/** The purity level of this expression. See docs for PurityLevel for what that means
370370
* @return A possibly combination of
371371
*
372372
* Path if expression is at least idempotent and is a path
@@ -857,16 +857,29 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
857857
}
858858

859859
object TreeInfo {
860+
/** A purity level is represented as a bitset (expressed as an Int) */
860861
class PurityLevel(val x: Int) extends AnyVal {
862+
/** `this` contains the bits of `that` */
861863
def >= (that: PurityLevel): Boolean = (x & that.x) == that.x
864+
865+
/** The intersection of the bits of `this` and `that` */
862866
def min(that: PurityLevel): PurityLevel = new PurityLevel(x & that.x)
863867
}
864868

869+
/** An expression is a stable path. Requires that expression is at least idempotent */
865870
val Path: PurityLevel = new PurityLevel(4)
871+
872+
/** The expression has no side effects */
866873
val Pure: PurityLevel = new PurityLevel(3)
874+
875+
/** Running the expression a second time has no side effects. Implied by `Pure`. */
867876
val Idempotent: PurityLevel = new PurityLevel(1)
877+
868878
val Impure: PurityLevel = new PurityLevel(0)
869879

870-
val PurePath: PurityLevel = new PurityLevel(7)
871-
val IdempotentPath: PurityLevel = new PurityLevel(5)
880+
/** A stable path that is evaluated without side effects */
881+
val PurePath: PurityLevel = new PurityLevel(Pure.x | Path.x)
882+
883+
/** A stable path that is also idempotent */
884+
val IdempotentPath: PurityLevel = new PurityLevel(Idempotent.x | Path.x)
872885
}

0 commit comments

Comments
 (0)