@@ -366,7 +366,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
366
366
// But if we do that the repl/vars test break. Need to figure out why that's the case.
367
367
}
368
368
369
- /** The purity level of this expression.
369
+ /** The purity level of this expression. See docs for PurityLevel for what that means
370
370
* @return A possibly combination of
371
371
*
372
372
* Path if expression is at least idempotent and is a path
@@ -857,16 +857,29 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
857
857
}
858
858
859
859
object TreeInfo {
860
+ /** A purity level is represented as a bitset (expressed as an Int) */
860
861
class PurityLevel (val x : Int ) extends AnyVal {
862
+ /** `this` contains the bits of `that` */
861
863
def >= (that : PurityLevel ): Boolean = (x & that.x) == that.x
864
+
865
+ /** The intersection of the bits of `this` and `that` */
862
866
def min (that : PurityLevel ): PurityLevel = new PurityLevel (x & that.x)
863
867
}
864
868
869
+ /** An expression is a stable path. Requires that expression is at least idempotent */
865
870
val Path : PurityLevel = new PurityLevel (4 )
871
+
872
+ /** The expression has no side effects */
866
873
val Pure : PurityLevel = new PurityLevel (3 )
874
+
875
+ /** Running the expression a second time has no side effects. Implied by `Pure`. */
867
876
val Idempotent : PurityLevel = new PurityLevel (1 )
877
+
868
878
val Impure : PurityLevel = new PurityLevel (0 )
869
879
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)
872
885
}
0 commit comments