Skip to content

Commit ab35a35

Browse files
committed
Avoid creating a mutable hashmap in typedStats
1 parent b51e188 commit ab35a35

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import EtaExpansion.etaExpand
2929
import TypeComparer.CompareResult
3030
import util.Spans._
3131
import util.common._
32-
import util.Property
32+
import util.{Property, SimpleIdentityMap}
3333
import Applications.{ExtMethodApply, IntegratedTypeArgs, productSelectorTypes, wrapDefs}
3434

3535
import collection.mutable
@@ -2567,7 +2567,7 @@ class Typer extends Namer
25672567

25682568
def typedStats(stats: List[untpd.Tree], exprOwner: Symbol)(using Context): (List[Tree], Context) = {
25692569
val buf = new mutable.ListBuffer[Tree]
2570-
val enumContexts = new mutable.HashMap[Symbol, Context]
2570+
var enumContexts: SimpleIdentityMap[Symbol, Context] = SimpleIdentityMap.Empty
25712571
val initialNotNullInfos = ctx.notNullInfos
25722572
// A map from `enum` symbols to the contexts enclosing their definitions
25732573
@tailrec def traverse(stats: List[untpd.Tree])(using Context): (List[Tree], Context) = stats match {
@@ -2589,7 +2589,7 @@ class Typer extends Namer
25892589
// replace body with expansion, because it will be used as inlined body
25902590
// from separately compiled files - the original BodyAnnotation is not kept.
25912591
case mdef1: TypeDef if mdef1.symbol.is(Enum, butNot = Case) =>
2592-
enumContexts(mdef1.symbol) = ctx
2592+
enumContexts = enumContexts.updated(mdef1.symbol, ctx)
25932593
buf += mdef1
25942594
case EmptyTree =>
25952595
// clashing synthetic case methods are converted to empty trees, drop them here
@@ -2621,7 +2621,8 @@ class Typer extends Namer
26212621
}
26222622
def finalize(stat: Tree)(using Context): Tree = stat match {
26232623
case stat: TypeDef if stat.symbol.is(Module) =>
2624-
for (enumContext <- enumContexts.get(stat.symbol.linkedClass))
2624+
val enumContext = enumContexts(stat.symbol.linkedClass)
2625+
if enumContext != null then
26252626
checkEnumCaseRefsLegal(stat, enumContext)
26262627
stat.removeAttachment(Deriver) match {
26272628
case Some(deriver) => deriver.finalize(stat)

0 commit comments

Comments
 (0)