Skip to content

Commit afb7444

Browse files
committed
More statistics for created and retained trees
1 parent a4e2a6e commit afb7444

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,18 @@ object Trees {
297297
def orElse[U >: Untyped <: T](that: => Tree[U]): Tree[U] =
298298
if (this eq genericEmptyTree) that else this
299299

300+
/** The number of nodes in this tree */
301+
def treeSize: Int = {
302+
var s = 1
303+
def addSize(elem: Any): Unit = elem match {
304+
case t: Tree[_] => s += t.treeSize
305+
case ts: List[_] => ts foreach addSize
306+
case _ =>
307+
}
308+
productIterator foreach addSize
309+
s
310+
}
311+
300312
override def toText(printer: Printer) = printer.toText(this)
301313

302314
override def hashCode(): Int = System.identityHashCode(this)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class TypeComparer(initctx: Context) extends DotClass {
195195
val saved = constraint
196196
val savedSuccessCount = successCount
197197
val savedTotalCount = totalCount
198-
if (Stats.monitored) Stats.record(s"isSubType ${tp1.show} <:< ${tp2.show}")
198+
//if (Stats.monitored) Stats.record(s"isSubType ${tp1.show} <:< ${tp2.show}")
199199
try {
200200
recCount += 1
201201
/* !!! DEBUG

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Phases._
66
import Contexts._
77
import parsing.Parsers.Parser
88
import config.Printers._
9+
import util.Stats._
910

1011
class FrontEnd extends Phase {
1112

@@ -35,13 +36,17 @@ class FrontEnd extends Phase {
3536
val unit = ctx.compilationUnit
3637
unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
3738
typr.println("typed: "+unit.source)
39+
record("retainedUntypedTrees", unit.untpdTree.treeSize)
40+
record("retainedTypedTrees", unit.tpdTree.treeSize)
3841
}
3942

4043
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): Unit = {
4144
val unitContexts = units map (unit => ctx.fresh.withCompilationUnit(unit))
4245
unitContexts foreach (parse(_))
46+
record("parsedTrees", ast.Trees.ntrees)
4347
unitContexts foreach (enterSyms(_))
4448
unitContexts foreach (typeCheck(_))
49+
record("totalTrees", ast.Trees.ntrees)
4550
}
4651

4752
override def run(implicit ctx: Context): Unit = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import util.SourcePosition
2828
import collection.mutable
2929
import annotation.tailrec
3030
import Implicits._
31-
import util.Stats.track
31+
import util.Stats.{track, record}
3232
import config.Printers._
3333
import language.implicitConversions
3434

@@ -959,7 +959,7 @@ class Typer extends Namer with Applications with Implicits {
959959
}
960960

961961
def typedUnadapted(initTree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = {
962-
962+
record("typedUnadapted")
963963
val xtree = expanded(initTree)
964964
xtree.removeAttachment(TypedAhead) match {
965965
case Some(ttree) => ttree

0 commit comments

Comments
 (0)