Skip to content

Commit cf70732

Browse files
committed
Micro-optimization: Make completion printing a Config option
Making completion printing a config option keeps the size of key method `SymDenotations#completeFrom` small.
1 parent 4fb358c commit cf70732

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ object Config {
144144
*/
145145
final val simplifyApplications = true
146146

147+
/** If set, prints a trace of all symbol completions */
148+
final val showCompletions = false
149+
147150
/** Initial size of superId table */
148151
final val InitialSuperIdsSize = 4096
149152

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ object Printers {
2727
val incremental: Printer = noPrinter
2828
val config: Printer = noPrinter
2929
val transforms: Printer = noPrinter
30-
val completions: Printer = noPrinter
3130
val cyclicErrors: Printer = noPrinter
3231
val pickling: Printer = noPrinter
3332
val inlining: Printer = noPrinter

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import util.SimpleMap
1717
import util.Stats
1818
import java.util.WeakHashMap
1919
import config.Config
20-
import config.Printers.{completions, incremental, noPrinter}
20+
import config.Printers.{incremental, noPrinter}
2121

2222
trait SymDenotations { this: Context =>
2323
import SymDenotations._
@@ -214,28 +214,31 @@ object SymDenotations {
214214
case _ => Some(myInfo)
215215
}
216216

217-
private def completeFrom(completer: LazyType)(implicit ctx: Context): Unit = {
218-
if (completions ne noPrinter) {
219-
completions.println(i"${" " * indent}completing ${if (isType) "type" else "val"} $name")
217+
private def completeFrom(completer: LazyType)(implicit ctx: Context): Unit =
218+
if (Config.showCompletions) {
219+
println(i"${" " * indent}completing ${if (isType) "type" else "val"} $name")
220220
indent += 1
221-
}
222-
if (myFlags is Touched) throw CyclicReference(this)
223-
myFlags |= Touched
224-
225-
// completions.println(s"completing ${this.debugString}")
226-
try completer.complete(this)(ctx.withPhase(validFor.firstPhaseId))
227-
catch {
228-
case ex: CyclicReference =>
229-
completions.println(s"error while completing ${this.debugString}")
230-
throw ex
231-
}
232-
finally
233-
if (completions ne noPrinter) {
221+
222+
if (myFlags is Touched) throw CyclicReference(this)
223+
myFlags |= Touched
224+
225+
// completions.println(s"completing ${this.debugString}")
226+
try completer.complete(this)(ctx.withPhase(validFor.firstPhaseId))
227+
catch {
228+
case ex: CyclicReference =>
229+
println(s"error while completing ${this.debugString}")
230+
throw ex
231+
}
232+
finally {
234233
indent -= 1
235-
completions.println(i"${" " * indent}completed $name in $owner")
234+
println(i"${" " * indent}completed $name in $owner")
236235
}
237-
// completions.println(s"completed ${this.debugString}")
238-
}
236+
}
237+
else {
238+
if (myFlags is Touched) throw CyclicReference(this)
239+
myFlags |= Touched
240+
completer.complete(this)(ctx.withPhase(validFor.firstPhaseId))
241+
}
239242

240243
protected[dotc] def info_=(tp: Type) = {
241244
/* // DEBUG
@@ -797,7 +800,10 @@ object SymDenotations {
797800
*/
798801
/** The class implementing this module, NoSymbol if not applicable. */
799802
final def moduleClass(implicit ctx: Context): Symbol = {
800-
def notFound = { completions.println(s"missing module class for $name: $myInfo"); NoSymbol }
803+
def notFound = {
804+
if (Config.showCompletions) println(s"missing module class for $name: $myInfo")
805+
NoSymbol
806+
}
801807
if (this is ModuleVal)
802808
myInfo match {
803809
case info: TypeRef => info.symbol

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import annotation.tailrec
1616
import ErrorReporting._
1717
import tpd.ListOfTreeDecorator
1818
import config.Config
19-
import config.Printers.{typr, completions, noPrinter}
19+
import config.Printers.{typr, noPrinter}
2020
import Annotations._
2121
import Inferencing._
2222
import transform.ValueClasses._
@@ -746,14 +746,13 @@ class Namer { typer: Typer =>
746746
}
747747

748748
final override def complete(denot: SymDenotation)(implicit ctx: Context) = {
749-
if (completions != noPrinter && ctx.typerState != this.ctx.typerState) {
750-
completions.println(completions.getClass.toString)
749+
if (Config.showCompletions && ctx.typerState != this.ctx.typerState) {
751750
def levels(c: Context): Int =
752751
if (c.typerState eq this.ctx.typerState) 0
753752
else if (c.typerState == null) -1
754753
else if (c.outer.typerState == c.typerState) levels(c.outer)
755754
else levels(c.outer) + 1
756-
completions.println(s"!!!completing ${denot.symbol.showLocated} in buried typerState, gap = ${levels(ctx)}")
755+
println(s"!!!completing ${denot.symbol.showLocated} in buried typerState, gap = ${levels(ctx)}")
757756
}
758757
assert(ctx.runId == creationContext.runId, "completing $denot in wrong run ${ctx.runId}, was created in ${creationContext.runId}")
759758
completeInCreationContext(denot)

0 commit comments

Comments
 (0)