@@ -1016,24 +1016,27 @@ object Trees {
1016
1016
1017
1017
// ----- Lazy trees and tree sequences
1018
1018
1019
- /** A tree that can have a lazy field
1020
- * The field is represented by some private `var` which is
1021
- * accessed by `unforced` and `force`. Forcing the field will
1022
- * set the `var` to the underlying value.
1019
+ /** A base trait for lazy tree fields.
1020
+ * These can be instantiated with Lazy instances which
1021
+ * can delay tree construction until the field is first demanded.
1022
+ */
1023
+ trait Lazy [+ T <: AnyRef ]:
1024
+ def complete (using Context ): T
1025
+
1026
+ /** A tree that can have a lazy fields.
1027
+ * Such fields are variables of type `T | Lazy[T]`, for some tyope `T`.
1023
1028
*/
1024
1029
trait WithLazyFields :
1030
+
1031
+ /** If `x` is lazy, computes the underlying value */
1025
1032
protected def force [T <: AnyRef ](x : T | Lazy [T ])(using Context ): T = x match
1026
1033
case x : Lazy [T ] @ unchecked => x.complete
1027
1034
case x : T @ unchecked => x
1035
+
1036
+ /** Assigns all lazy fields their underlying non-lazy value. */
1028
1037
def forceFields ()(using Context ): Unit
1029
1038
1030
- /** A base trait for lazy tree fields.
1031
- * These can be instantiated with Lazy instances which
1032
- * can delay tree construction until the field is first demanded.
1033
- */
1034
- trait Lazy [+ T <: AnyRef ] {
1035
- def complete (using Context ): T
1036
- }
1039
+ end WithLazyFields
1037
1040
1038
1041
// ----- Generic Tree Instances, inherited from `tpt` and `untpd`.
1039
1042
0 commit comments