Skip to content

Commit ac5f608

Browse files
committed
Convert more sets to util.HashSet
1 parent 09d0cb0 commit ac5f608

File tree

7 files changed

+42
-28
lines changed

7 files changed

+42
-28
lines changed

compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package dotc.classpath
77
import java.net.URL
88
import scala.collection.mutable.ArrayBuffer
99
import scala.collection.immutable.ArraySeq
10+
import dotc.util
1011

1112
import dotty.tools.io.{ AbstractFile, ClassPath, ClassRepresentation, EfficientClassPath }
1213

@@ -132,7 +133,7 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
132133
}
133134

134135
private def getDistinctEntries[EntryType <: ClassRepresentation](getEntries: ClassPath => Seq[EntryType]): Seq[EntryType] = {
135-
val seenNames = collection.mutable.HashSet[String]()
136+
val seenNames = util.HashSet[String]()
136137
val entriesBuffer = new ArrayBuffer[EntryType](1024)
137138
for {
138139
cp <- aggregates

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Uniques._
1414
import ast.Trees._
1515
import ast.untpd
1616
import Flags.GivenOrImplicit
17-
import util.{NoSource, SimpleIdentityMap, SourceFile}
17+
import util.{NoSource, SimpleIdentityMap, SourceFile, HashSet}
1818
import typer.{Implicits, ImportInfo, Inliner, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
1919
import Nullables.{NotNullInfo, given _}
2020
import Implicits.ContextualImplicits
@@ -534,7 +534,7 @@ object Contexts {
534534
def settings: ScalaSettings = base.settings
535535
def definitions: Definitions = base.definitions
536536
def platform: Platform = base.platform
537-
def pendingUnderlying: mutable.HashSet[Type] = base.pendingUnderlying
537+
def pendingUnderlying: util.HashSet[Type] = base.pendingUnderlying
538538
def uniqueNamedTypes: Uniques.NamedTypeUniques = base.uniqueNamedTypes
539539
def uniques: util.HashSet[Type] = base.uniques
540540

@@ -869,7 +869,7 @@ object Contexts {
869869

870870
/** The set of named types on which a currently active invocation
871871
* of underlying during a controlled operation exists. */
872-
private[core] val pendingUnderlying: mutable.HashSet[Type] = new mutable.HashSet[Type]
872+
private[core] val pendingUnderlying: util.HashSet[Type] = util.HashSet[Type]()
873873

874874
/** A map from ErrorType to associated message. We use this map
875875
* instead of storing messages directly in ErrorTypes in order

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
4949
needsGc = false
5050
if Config.checkTypeComparerReset then checkReset()
5151

52-
private var pendingSubTypes: mutable.Set[(Type, Type)] = null
52+
private var pendingSubTypes: util.MutableSet[(Type, Type)] = null
5353
private var recCount = 0
5454
private var monitored = false
5555

@@ -202,7 +202,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
202202

203203
def monitoredIsSubType = {
204204
if (pendingSubTypes == null) {
205-
pendingSubTypes = new mutable.HashSet[(Type, Type)]
205+
pendingSubTypes = util.HashSet[(Type, Type)]()
206206
report.log(s"!!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.constraint.show}")
207207
report.log(s"!!! constraint = ${constraint.show}")
208208
//if (ctx.settings.YnoDeepSubtypes.value) {
@@ -231,7 +231,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
231231
}
232232
}
233233
val p = (normalize(tp1), normalize(tp2))
234-
!pendingSubTypes(p) && {
234+
!pendingSubTypes.contains(p) && {
235235
try {
236236
pendingSubTypes += p
237237
firstTry

compiler/src/dotty/tools/dotc/plugins/Plugin.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ object Plugin {
162162
case Failure(e) => Failure(e)
163163
})
164164

165-
val seen = mutable.HashSet[String]()
165+
val seen = util.HashSet[String]()
166166
val enabled = (fromPaths ::: fromDirs) map(_.flatMap {
167167
case (classname, loader) =>
168168
Plugin.load(classname, loader).flatMap { clazz =>
169169
val plugin = instantiate(clazz)
170-
if (seen(classname)) // a nod to scala/bug#7494, take the plugin classes distinctly
170+
if (seen.contains(classname)) // a nod to scala/bug#7494, take the plugin classes distinctly
171171
Failure(new PluginLoadException(plugin.name, s"Ignoring duplicate plugin ${plugin.name} (${classname})"))
172172
else if (ignoring contains plugin.name)
173173
Failure(new PluginLoadException(plugin.name, s"Disabling plugin ${plugin.name}"))

compiler/src/dotty/tools/dotc/transform/CapturedVars.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
2626
override def runsAfterGroupsOf: Set[String] = Set(LiftTry.name)
2727
// lifting tries changes what variables are considered to be captured
2828

29-
private[this] var Captured: Store.Location[collection.Set[Symbol]] = _
29+
private[this] var Captured: Store.Location[util.ReadOnlySet[Symbol]] = _
3030
private def captured(using Context) = ctx.store(Captured)
3131

3232
override def initContext(ctx: FreshContext): Unit =
33-
Captured = ctx.addLocation(Set.empty)
33+
Captured = ctx.addLocation(util.ReadOnlySet.empty[Symbol])
3434

3535
private class RefInfo(using Context) {
3636
/** The classes for which a Ref type exists. */
@@ -54,7 +54,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
5454
}
5555

5656
private class CollectCaptured extends TreeTraverser {
57-
private val captured = mutable.HashSet[Symbol]()
57+
private val captured = util.HashSet[Symbol]()
5858
def traverse(tree: Tree)(using Context) = tree match {
5959
case id: Ident =>
6060
val sym = id.symbol
@@ -68,7 +68,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
6868
case _ =>
6969
traverseChildren(tree)
7070
}
71-
def runOver(tree: Tree)(using Context): collection.Set[Symbol] = {
71+
def runOver(tree: Tree)(using Context): util.ReadOnlySet[Symbol] = {
7272
traverse(tree)
7373
captured
7474
}

compiler/src/dotty/tools/dotc/util/MutableSet.scala

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package dotty.tools.dotc.util
22

33
/** A common class for lightweight mutable sets.
44
*/
5-
abstract class MutableSet[T] {
6-
7-
/** The entry in the set such that `isEqual(x, entry)`, or else `null`. */
8-
def lookup(x: T): T | Null
5+
abstract class MutableSet[T] extends ReadOnlySet[T]:
96

107
/** Add element `x` to the set */
118
def +=(x: T): Unit
@@ -15,16 +12,8 @@ abstract class MutableSet[T] {
1512
*/
1613
def put(x: T): T
1714

18-
def clear(): Unit
19-
20-
def size: Int
21-
22-
def iterator: Iterator[T]
15+
/** Remove element `x` from the set */
16+
def -=(x: T): Unit
2317

24-
def contains(x: T): Boolean = lookup(x) != null
25-
26-
def foreach[U](f: T => U): Unit = iterator foreach f
27-
28-
def toList: List[T] = iterator.toList
18+
def clear(): Unit
2919

30-
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dotty.tools.dotc.util
2+
3+
/** A class for the readonly part of mutable sets.
4+
*/
5+
abstract class ReadOnlySet[T]:
6+
7+
/** The entry in the set such that `isEqual(x, entry)`, or else `null`. */
8+
def lookup(x: T): T | Null
9+
10+
def size: Int
11+
12+
def iterator: Iterator[T]
13+
14+
def contains(x: T): Boolean = lookup(x) != null
15+
16+
def foreach[U](f: T => U): Unit = iterator.foreach(f)
17+
18+
def toList: List[T] = iterator.toList
19+
20+
def isEmpty = size == 0
21+
22+
object ReadOnlySet:
23+
def empty[T]: ReadOnlySet[T] = HashSet[T](4)
24+

0 commit comments

Comments
 (0)