@@ -66,6 +66,12 @@ sealed trait Space:
66
66
else trace(s " isSubspace( ${show(this )}, ${show(b)}) " , debug) {
67
67
isSubspaceCache.getOrElseUpdate(b, computeIsSubspace(this , b))
68
68
}
69
+
70
+ private var mySimplify : Space = _
71
+
72
+ def simplify (using Context ): Space =
73
+ if mySimplify == null then mySimplify = SpaceEngine .computeSimplify(this )
74
+ mySimplify
69
75
end Space
70
76
71
77
/** Empty space */
@@ -98,8 +104,13 @@ case class Or(spaces: Seq[Space]) extends Space
98
104
object SpaceEngine {
99
105
import tpd ._
100
106
107
+ def simplify (space : Space )(using Context ): Space = space.simplify
108
+ def isSubspace (a : Space , b : Space )(using Context ): Boolean = a.isSubspace(b)
109
+ def canDecompose (typ : Typ )(using Context ): Boolean = typ.canDecompose
110
+ def decompose (typ : Typ )(using Context ): List [Typ ] = typ.decompose
111
+
101
112
/** Simplify space such that a space equal to `Empty` becomes `Empty` */
102
- def simplify (space : Space )(using Context ): Space = trace(s " simplify ${show(space)} --> " , debug, show)(space match {
113
+ def computeSimplify (space : Space )(using Context ): Space = trace(s " simplify ${show(space)} --> " , debug, show)(space match {
103
114
case Prod (tp, fun, spaces) =>
104
115
val sps = spaces.mapconserve(simplify)
105
116
if sps.contains(Empty ) then Empty
@@ -150,8 +161,6 @@ object SpaceEngine {
150
161
}
151
162
152
163
/** Is `a` a subspace of `b`? Equivalent to `simplify(simplify(a) - simplify(b)) == Empty`, but faster */
153
- def isSubspace (a : Space , b : Space )(using Context ): Boolean = a.isSubspace(b)
154
-
155
164
def computeIsSubspace (a : Space , b : Space )(using Context ): Boolean = {
156
165
val a2 = simplify(a)
157
166
val b2 = simplify(b)
@@ -578,9 +587,6 @@ object SpaceEngine {
578
587
scrutineeTp <:< tp
579
588
}
580
589
581
- def canDecompose (typ : Typ )(using Context ): Boolean = typ.canDecompose
582
- def decompose (typ : Typ )(using Context ): List [Typ ] = typ.decompose
583
-
584
590
/** Decompose a type into subspaces -- assume the type can be decomposed */
585
591
def decompose (tp : Type )(using Context ): List [Type ] = trace(i " decompose( $tp) " , debug) {
586
592
def rec (tp : Type , mixins : List [Type ]): List [Type ] = tp.dealias match
0 commit comments