Skip to content

Commit b810891

Browse files
committed
Avoid creating a mutable hashmap in typedStats
1 parent cf8f605 commit b810891

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,7 +2596,7 @@ class Typer extends Namer
25962596

25972597
def typedStats(stats: List[untpd.Tree], exprOwner: Symbol)(using Context): (List[Tree], Context) = {
25982598
val buf = new mutable.ListBuffer[Tree]
2599-
val enumContexts = new mutable.HashMap[Symbol, Context]
2599+
var enumContexts: SimpleIdentityMap[Symbol, Context] = SimpleIdentityMap.Empty
26002600
val initialNotNullInfos = ctx.notNullInfos
26012601
// A map from `enum` symbols to the contexts enclosing their definitions
26022602
@tailrec def traverse(stats: List[untpd.Tree])(using Context): (List[Tree], Context) = stats match {
@@ -2618,7 +2618,7 @@ class Typer extends Namer
26182618
// replace body with expansion, because it will be used as inlined body
26192619
// from separately compiled files - the original BodyAnnotation is not kept.
26202620
case mdef1: TypeDef if mdef1.symbol.is(Enum, butNot = Case) =>
2621-
enumContexts(mdef1.symbol) = ctx
2621+
enumContexts = enumContexts.updated(mdef1.symbol, ctx)
26222622
buf += mdef1
26232623
case EmptyTree =>
26242624
// clashing synthetic case methods are converted to empty trees, drop them here
@@ -2650,7 +2650,8 @@ class Typer extends Namer
26502650
}
26512651
def finalize(stat: Tree)(using Context): Tree = stat match {
26522652
case stat: TypeDef if stat.symbol.is(Module) =>
2653-
for (enumContext <- enumContexts.get(stat.symbol.linkedClass))
2653+
val enumContext = enumContexts(stat.symbol.linkedClass)
2654+
if enumContext != null then
26542655
checkEnumCaseRefsLegal(stat, enumContext)
26552656
stat.removeAttachment(Deriver) match {
26562657
case Some(deriver) => deriver.finalize(stat)

0 commit comments

Comments
 (0)