Skip to content

Commit 0bff3af

Browse files
committed
Use ListSet to avoid explosion due to duplicate entries
It can be demonstrated by tests/init/neg/inherit-non-hot.scala.
1 parent 7919c42 commit 0bff3af

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Errors.*
1919
import Trace.*
2020
import Util.*
2121

22+
import scala.collection.immutable.ListSet
2223
import scala.collection.mutable
2324
import scala.annotation.tailrec
2425

@@ -127,15 +128,15 @@ object Objects:
127128
*
128129
* It comes from `if` expressions.
129130
*/
130-
case class RefSet(refs: List[Value]) extends Value:
131+
case class RefSet(refs: ListSet[Value]) extends Value:
131132
assert(refs.forall(!_.isInstanceOf[RefSet]))
132133
def show(using Context) = refs.map(_.show).mkString("[", ",", "]")
133134

134135
/** A cold alias which should not be used during initialization. */
135136
case object Cold extends Value:
136137
def show(using Context) = "Cold"
137138

138-
val Bottom = RefSet(Nil)
139+
val Bottom = RefSet(ListSet.empty)
139140

140141
/** Checking state */
141142
object State:
@@ -269,9 +270,9 @@ object Objects:
269270
case (Bottom, b) => b
270271
case (a, Bottom) => a
271272
case (RefSet(refs1), RefSet(refs2)) => RefSet(refs1 ++ refs2)
272-
case (a, RefSet(refs)) => RefSet(a :: refs)
273-
case (RefSet(refs), b) => RefSet(b :: refs)
274-
case (a, b) => RefSet(a :: b :: Nil)
273+
case (a, RefSet(refs)) => RefSet(refs + a)
274+
case (RefSet(refs), b) => RefSet(refs + b)
275+
case (a, b) => RefSet(ListSet(a, b))
275276

276277
def widen(height: Int)(using Context): Value =
277278
a match
@@ -294,7 +295,7 @@ object Objects:
294295
case _ => a
295296

296297

297-
extension (values: Seq[Value])
298+
extension (values: Iterable[Value])
298299
def join: Value = if values.isEmpty then Bottom else values.reduce { (v1, v2) => v1.join(v2) }
299300

300301
def widen(height: Int): Contextual[List[Value]] = values.map(_.widen(height)).toList

0 commit comments

Comments
 (0)