Skip to content

Commit 45c7ac8

Browse files
committed
Fix #8922: Performance tweak for space computation
We first substract the last pattern, usually it's a wildcard, thus speeds up computation. In computing `Prod(K, a1, a2, ..) - Prod(K, b1, b2, ..)`, if there exists one dimension that is not reducible, i.e. `a_i < a_i - b_i`, then the result is just `Prod(K, a1, a2, ..)`.
1 parent b9ec1d5 commit 45c7ac8

File tree

1 file changed

+4
-4
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+4
-4
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ trait SpaceLogic {
263263
a // approximation
264264
case (Prod(tp1, fun1, ss1, full), Prod(tp2, fun2, ss2, _)) =>
265265
if (!isSameUnapply(fun1, fun2)) a
266-
else if (ss1.zip(ss2).exists(p => simplify(intersect(p._1, p._2)) == Empty)) a
266+
else if (ss1.zip(ss2).exists(p => isSubspace(p._1, minus(p._1, p._2)))) a
267267
else if (ss1.zip(ss2).forall((isSubspace _).tupled)) Empty
268268
else
269269
// `(_, _, _) - (Some, None, _)` becomes `(None, _, _) | (_, Some, _) | (_, _, Empty)`
@@ -812,16 +812,16 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
812812
}.apply(false, tp)
813813

814814
def checkExhaustivity(_match: Match): Unit = {
815-
val Match(sel, cases) = _match
815+
val Match(sel, cases :+ last) = _match
816816
val selTyp = sel.tpe.widen.dealias
817817

818818
if (!exhaustivityCheckable(sel)) return
819819

820-
val patternSpace = cases.map({ x =>
820+
val patternSpace = Or((last :: cases).map({ x =>
821821
val space = if (x.guard.isEmpty) project(x.pat) else Empty
822822
debug.println(s"${x.pat.show} ====> ${show(space)}")
823823
space
824-
}).reduce((a, b) => Or(List(a, b)))
824+
}))
825825

826826
val checkGADTSAT = shouldCheckExamples(selTyp)
827827

0 commit comments

Comments
 (0)