Skip to content

Commit e9509f8

Browse files
committed
Update period in place when transforming denotations
1 parent d83d672 commit e9509f8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ object Contexts {
313313
final def withPhase(phase: Phase): Context =
314314
withPhase(phase.id)
315315

316+
inline def evalAt[T](phase: Phase)(inline op: Context ?=> T): T =
317+
val saved = period
318+
this.asInstanceOf[FreshContext].period = Period(runId, phase.id)
319+
try op(using this)
320+
finally period = saved
321+
316322
// `creationTrace`-related code. To enable, uncomment the code below and the
317323
// call to `setCreationTrace()` in this file.
318324
/*

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,13 @@ object Denotations {
797797
val transformer = ctx.base.denotTransformers(nextTransformerId)
798798
//println(s"transforming $this with $transformer")
799799
try
800-
next = atPhase(transformer)(transformer.transform(cur))
800+
util.Stats.record("denot transform")
801+
next = ctx.evalAt(transformer)(transformer.transform(cur))
802+
// We temporarily update the context with the new phase instead of creating a
803+
// new one. This is done for performance. We cut down on about 30% of context
804+
// creations that way, and also avoid phase caches in contexts to get large.
805+
// To work correctly, we need to demand that the context with the new phase
806+
// is not retained in the result.
801807
catch {
802808
case ex: CyclicReference =>
803809
println(s"error while transforming $this") // DEBUG

0 commit comments

Comments
 (0)