Skip to content

Commit 9680ef9

Browse files
committed
Space: Avoid creating duplicates in simplify
1 parent ef653b6 commit 9680ef9

File tree

1 file changed

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

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ trait SpaceLogic {
116116
/** Simplify space such that a space equal to `Empty` becomes `Empty` */
117117
def simplify(space: Space)(using Context): Space = trace(s"simplify ${show(space)} --> ", debug, show)(space match {
118118
case Prod(tp, fun, spaces) =>
119-
val sps = spaces.map(simplify(_))
119+
val sps = spaces.mapconserve(simplify)
120120
if (sps.contains(Empty)) Empty
121121
else if (canDecompose(tp) && decompose(tp).isEmpty) Empty
122-
else Prod(tp, fun, sps)
122+
else if sps eq spaces then space else Prod(tp, fun, sps)
123123
case Or(spaces) =>
124-
val spaces2 = spaces.map(simplify(_)).filter(_ != Empty)
124+
val spaces2 = spaces.map(simplify).filter(_ != Empty)
125125
if spaces2.isEmpty then Empty
126-
else if spaces2.lengthCompare(1) == 0 then spaces2.head
127-
else Or(spaces2)
126+
else if spaces2.lengthIs == 1 then spaces2.head
127+
else if spaces2.corresponds(spaces)(_ eq _) then space else Or(spaces2)
128128
case Typ(tp, _) =>
129129
if (canDecompose(tp) && decompose(tp).isEmpty) Empty
130130
else space

0 commit comments

Comments
 (0)