Skip to content

Commit 4c30784

Browse files
committed
Use LinkedHashMaps and LinkedHashSets everywhere.
1 parent 522c1f2 commit 4c30784

22 files changed

+41
-41
lines changed

src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import scala.tools.nsc.backend.jvm.opt.LocalOpt
3333

3434
class GenBCode extends Phase {
3535
def phaseName: String = "genBCode"
36-
private val entryPoints = new mutable.HashSet[Symbol]()
36+
private val entryPoints = new mutable.LinkedHashSet[Symbol]()
3737
def registerEntryPoint(sym: Symbol) = entryPoints += sym
3838

3939

src/dotty/tools/backend/jvm/LabelDefs.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class LabelDefs extends MiniPhaseTransform {
8080
def phaseName: String = "labelDef"
8181

8282
val queue = new ArrayBuffer[Tree]()
83-
val beingAppended = new mutable.HashSet[Symbol]()
83+
val beingAppended = new mutable.LinkedHashSet[Symbol]()
8484
var labelLevel = 0
8585

8686
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
@@ -95,7 +95,7 @@ class LabelDefs extends MiniPhaseTransform {
9595

9696
// make sure that for every label there's a single location it should return and single entry point
9797
// if theres already a location that it returns to that's a failure
98-
val disallowed = new mutable.HashMap[Symbol, Tree]()
98+
val disallowed = new mutable.LinkedHashMap[Symbol, Tree]()
9999
queue.sizeHint(labelCalls.size + entryPoints.size)
100100

101101
def putLabelDefsNearCallees = new TreeMap() {
@@ -118,7 +118,7 @@ class LabelDefs extends MiniPhaseTransform {
118118
def moveLabels(entryPoint: Apply): List[Tree] = {
119119
val entrySym = entryPoint.symbol
120120
if ((entrySym is Flags.Label) && labelDefs.contains(entrySym)) {
121-
val visitedNow = new mutable.HashMap[Symbol, Tree]()
121+
val visitedNow = new mutable.LinkedHashMap[Symbol, Tree]()
122122
val treesToAppend = new ArrayBuffer[Tree]() // order matters. parents should go first
123123
treesToAppend += labelDefs(entrySym)
124124
queue.clear()
@@ -167,15 +167,15 @@ class LabelDefs extends MiniPhaseTransform {
167167
object collectLabelDefs extends TreeMap() {
168168

169169
// label calls from this DefDef
170-
var parentLabelCalls: mutable.Set[Tree] = new mutable.HashSet[Tree]()
171-
var callCounts: mutable.Map[Symbol, Int] = new mutable.HashMap[Symbol, Int]().withDefaultValue(0)
170+
var parentLabelCalls: mutable.Set[Tree] = new mutable.LinkedHashSet[Tree]()
171+
var callCounts: mutable.Map[Symbol, Int] = new mutable.LinkedHashMap[Symbol, Int]().withDefaultValue(0)
172172

173173
def shouldMoveLabel = true
174174

175175
// labelSymbol -> Defining tree
176-
val labelDefs = new mutable.HashMap[Symbol, Tree]()
176+
val labelDefs = new mutable.LinkedHashMap[Symbol, Tree]()
177177
// owner -> all calls by this owner
178-
val labelCalls = new mutable.HashMap[Symbol, mutable.Set[Tree]]()
178+
val labelCalls = new mutable.LinkedHashMap[Symbol, mutable.Set[Tree]]()
179179
var owner: Symbol = null
180180

181181
def clear = {
@@ -196,7 +196,7 @@ class LabelDefs extends MiniPhaseTransform {
196196
assert(t.symbol is Flags.Label)
197197

198198
val st = parentLabelCalls
199-
parentLabelCalls = new mutable.HashSet[Tree]()
199+
parentLabelCalls = new mutable.LinkedHashSet[Tree]()
200200
val symt = owner
201201
owner = t.symbol
202202

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ object Contexts {
583583

584584
/** The set of named types on which a currently active invocation
585585
* of underlying during a controlled operation exists. */
586-
private[core] val pendingUnderlying = new mutable.HashSet[Type]
586+
private[core] val pendingUnderlying = new mutable.LinkedHashSet[Type]
587587

588588

589589
private[core] var phasesPlan: List[List[Phase]] = _

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ object SymDenotations {
12941294
/** Invalidate baseTypeRefCache, baseClasses and superClassBits on new run */
12951295
private def checkBasesUpToDate()(implicit ctx: Context) =
12961296
if (baseTypeRefValid != ctx.runId) {
1297-
baseTypeRefCache = new java.util.HashMap[CachedType, Type]
1297+
baseTypeRefCache = new java.util.LinkedHashMap[CachedType, Type]
12981298
myBaseClasses = null
12991299
mySuperClassBits = null
13001300
baseTypeRefValid = ctx.runId
@@ -1538,7 +1538,7 @@ object SymDenotations {
15381538
raw.filterExcluded(excluded).asSeenFrom(pre).toDenot(pre)
15391539
}
15401540

1541-
private[this] var baseTypeRefCache: java.util.HashMap[CachedType, Type] = null
1541+
private[this] var baseTypeRefCache: java.util.LinkedHashMap[CachedType, Type] = null
15421542
private[this] var baseTypeRefValid: RunId = NoRunId
15431543

15441544
/** Compute tp.baseTypeRef(this) */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
120120

121121
private def monitoredIsSubType(tp1: Type, tp2: Type) = {
122122
if (pendingSubTypes == null) {
123-
pendingSubTypes = new mutable.HashSet[(Type, Type)]
123+
pendingSubTypes = new mutable.LinkedHashSet[(Type, Type)]
124124
ctx.log(s"!!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.constraint.show}")
125125
ctx.log(s"!!! constraint = ${constraint.show}")
126126
if (ctx.settings.YnoDeepSubtypes.value) throw new Error("deep subtype")

src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ class ClassfileParser(
762762
originalName + " in " + outerName + "(" + externalName + ")"
763763
}
764764

765-
object innerClasses extends scala.collection.mutable.HashMap[Name, InnerClassEntry] {
765+
object innerClasses extends scala.collection.mutable.LinkedHashMap[Name, InnerClassEntry] {
766766
/** Return the Symbol of the top level class enclosing `name`,
767767
* or 'name's symbol if no entry found for `name`.
768768
*/

src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import collection.mutable
99
import TastyBuffer.Addr
1010

1111
object PositionUnpickler {
12-
type AddrToPosition = mutable.HashMap[Addr, Position]
12+
type AddrToPosition = mutable.LinkedHashMap[Addr, Position]
1313
}
1414

1515
/** Unpickler for tree positions */
@@ -18,7 +18,7 @@ class PositionUnpickler(reader: TastyReader) {
1818
import reader._
1919

2020
def unpickle(): (Position, AddrToPosition) = {
21-
val positions = new mutable.HashMap[Addr, Position] // Dotty deviation: Can't use new AddrToPosition here. TODO: fix this!
21+
val positions = new mutable.LinkedHashMap[Addr, Position] // Dotty deviation: Can't use new AddrToPosition here. TODO: fix this!
2222
val sourceLength = readNat()
2323
def readDelta() = if (isAtEnd) 0 else readInt()
2424
var curIndex: Addr = Addr(readDelta())

src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TastyUnpickler(reader: TastyReader) {
2222

2323
def this(bytes: Array[Byte]) = this(new TastyReader(bytes))
2424

25-
private val sectionReader = new mutable.HashMap[String, TastyReader]
25+
private val sectionReader = new mutable.LinkedHashMap[String, TastyReader]
2626
val tastyName = new TastyName.Table
2727

2828
def check(cond: Boolean, msg: => String) =

src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class TreePickler(pickler: TastyPickler) {
1717
import pickler.nameBuffer.{nameIndex, fullNameIndex}
1818
import ast.tpd._
1919

20-
private val symRefs = new mutable.HashMap[Symbol, Addr]
21-
private val forwardSymRefs = new mutable.HashMap[Symbol, List[Addr]]
20+
private val symRefs = new mutable.LinkedHashMap[Symbol, Addr]
21+
private val forwardSymRefs = new mutable.LinkedHashMap[Symbol, List[Addr]]
2222
private val pickledTypes = new java.util.IdentityHashMap[Type, Any] // Value type is really Addr, but that's not compatible with null
2323

2424
private def withLength(op: => Unit) = {

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
4040
this.positions = positions
4141
}
4242

43-
private val symAtAddr = new mutable.HashMap[Addr, Symbol]
44-
private val treeAtAddr = new mutable.HashMap[Addr, Tree]
45-
private val typeAtAddr = new mutable.HashMap[Addr, Type] // currently populated only for types that are known to be SHAREd.
43+
private val symAtAddr = new mutable.LinkedHashMap[Addr, Symbol]
44+
private val treeAtAddr = new mutable.LinkedHashMap[Addr, Tree]
45+
private val typeAtAddr = new mutable.LinkedHashMap[Addr, Type] // currently populated only for types that are known to be SHAREd.
4646
private var stubs: Set[Symbol] = Set()
4747

4848
private var roots: Set[SymDenotation] = null

src/dotty/tools/dotc/printing/Disambiguation.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ object Disambiguation {
1010

1111
private class State {
1212
var hasConflicts = false
13-
val symString = new mutable.HashMap[Symbol, String]
14-
val variants = new mutable.HashMap[String, mutable.ListBuffer[Symbol]]
13+
val symString = new mutable.LinkedHashMap[Symbol, String]
14+
val variants = new mutable.LinkedHashMap[String, mutable.ListBuffer[Symbol]]
1515
}
1616

1717
def newPrinter: Context => Printer = {

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ abstract class Reporter {
224224
*/
225225
def errorsReported = hasErrors
226226

227-
val unreportedWarnings = new mutable.HashMap[String, Int] {
227+
val unreportedWarnings = new mutable.LinkedHashMap[String, Int] {
228228
override def default(key: String) = 0
229229
}
230230

src/dotty/tools/dotc/reporting/UniqueMessagePositions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import core.Contexts.Context
1313
*/
1414
trait UniqueMessagePositions extends Reporter {
1515

16-
private val positions = new mutable.HashMap[(SourceFile, Int), Int]
16+
private val positions = new mutable.LinkedHashMap[(SourceFile, Int), Int]
1717

1818
/** Logs a position and returns true if it was already logged.
1919
* @note Two positions are considered identical for logging if they have the same point.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisTransfo
4949
}
5050

5151
private class CollectCaptured(implicit ctx: Context) extends EnclosingMethodTraverser {
52-
private val captured = mutable.HashSet[Symbol]()
52+
private val captured = mutable.LinkedHashSet[Symbol]()
5353
def traverse(enclMeth: Symbol, tree: Tree)(implicit ctx: Context) = tree match {
5454
case id: Ident =>
5555
val sym = id.symbol

src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
6161
private val called = new LinkedHashMap[Symbol, SymSet]
6262

6363
/** Symbols that are called from an inner class. */
64-
private val calledFromInner = new HashSet[Symbol]
64+
private val calledFromInner = new LinkedHashSet[Symbol]
6565

6666
/** A map from local methods and classes to the owners to which they will be lifted as members.
6767
* For methods and classes that do not have any dependencies this will be the enclosing package.
6868
* symbols with packages as lifted owners will subsequently represented as static
6969
* members of their toplevel class, unless their enclosing class was already static.
7070
*/
71-
private val liftedOwner = new HashMap[Symbol, Symbol]
71+
private val liftedOwner = new mutable.LinkedHashMap[Symbol, Symbol]
7272

7373
/** Buffers for lifted out classes and methods, indexed by owner */
74-
private val liftedDefs = new HashMap[Symbol, mutable.ListBuffer[Tree]]
74+
private val liftedDefs = new mutable.LinkedHashMap[Symbol, mutable.ListBuffer[Tree]]
7575

7676
/** A flag to indicate whether new free variables have been found */
7777
private var changedFreeVars: Boolean = _

src/dotty/tools/dotc/transform/OverridingPairs.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ object OverridingPairs {
6464
}
6565

6666
private val subParents = {
67-
val subParents = new mutable.HashMap[Symbol, BitSet]
67+
val subParents = new mutable.LinkedHashMap[Symbol, BitSet]
6868
for (bc <- base.info.baseClasses)
6969
subParents(bc) = BitSet(parents.indices.filter(parents(_).derivesFrom(bc)): _*)
7070
subParents
@@ -77,7 +77,7 @@ object OverridingPairs {
7777
* (maybe excluded because of hasCommonParentAsSubclass).
7878
* These will not appear as overriding
7979
*/
80-
private val visited = new mutable.HashSet[Symbol]
80+
private val visited = new mutable.LinkedHashSet[Symbol]
8181

8282
/** The current entry candidate for overriding
8383
*/

src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
465465
if (!emitVars) in
466466
else {
467467
// binders in `subPatBindersStored` that are referenced by tree `in`
468-
val usedBinders = new collection.mutable.HashSet[Symbol]()
468+
val usedBinders = new collection.mutable.LinkedHashSet[Symbol]()
469469
// all potentially stored subpat binders
470470
val potentiallyStoredBinders = stored.unzip._1.toSet
471471
// compute intersection of all symbols in the tree `in` and all potentially stored subpat binders

src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Pickler extends Phase {
2626
s.close
2727
}
2828

29-
private val beforePickling = new mutable.HashMap[ClassSymbol, String]
29+
private val beforePickling = new mutable.LinkedHashMap[ClassSymbol, String]
3030

3131
/** Drop any elements of this list that are linked module classes of other elements in the list */
3232
private def dropCompanionModuleClasses(clss: List[ClassSymbol])(implicit ctx: Context): List[ClassSymbol] = {

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class TreeChecker extends Phase with SymTransformer {
4141
import ast.tpd._
4242

4343

44-
private val seenClasses = collection.mutable.HashMap[String, Symbol]()
45-
private val seenModuleVals = collection.mutable.HashMap[String, Symbol]()
44+
private val seenClasses = collection.mutable.LinkedHashMap[String, Symbol]()
45+
private val seenModuleVals = collection.mutable.LinkedHashMap[String, Symbol]()
4646

4747
def isValidJVMName(name: Name) =
4848
!name.exists(c => c == '.' || c == ';' || c =='[' || c == '/')
@@ -135,8 +135,8 @@ class TreeChecker extends Phase with SymTransformer {
135135

136136
class Checker(phasesToCheck: Seq[Phase]) extends ReTyper {
137137

138-
val nowDefinedSyms = new mutable.HashSet[Symbol]
139-
val everDefinedSyms = new mutable.HashMap[Symbol, Tree]
138+
val nowDefinedSyms = new mutable.LinkedHashSet[Symbol]
139+
val everDefinedSyms = new mutable.LinkedHashMap[Symbol, Tree]
140140

141141
def withDefinedSym[T](tree: untpd.Tree)(op: => T)(implicit ctx: Context): T = tree match {
142142
case tree: DefTree =>

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ trait Checking {
349349

350350
/** Check that class does not define same symbol twice */
351351
def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = {
352-
val seen = new mutable.HashMap[Name, List[Symbol]] {
352+
val seen = new mutable.LinkedHashMap[Name, List[Symbol]] {
353353
override def default(key: Name) = Nil
354354
}
355355
typr.println(i"check no double defs $cls")

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ trait ImplicitRunInfo { self: RunInfo =>
367367
}
368368

369369
/** A map that counts the number of times an implicit ref was picked */
370-
val useCount = new mutable.HashMap[TermRef, Int] {
370+
val useCount = new mutable.LinkedHashMap[TermRef, Int] {
371371
override def default(key: TermRef) = 0
372372
}
373373

src/dotty/tools/dotc/util/Stats.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import collection.mutable
1414

1515
@volatile private var stack: List[String] = Nil
1616

17-
val hits = new mutable.HashMap[String, Int] {
17+
val hits = new mutable.LinkedHashMap[String, Int] {
1818
override def default(key: String): Int = 0
1919
}
2020

0 commit comments

Comments
 (0)