Skip to content

Commit 1e6572d

Browse files
committed
More detailed stats
We now track typemaps, substitutions, context creations, and typerState creations, among others.
1 parent 3034f59 commit 1e6572d

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import reporting.diagnostic.Message
2727
import collection.mutable
2828
import collection.immutable.BitSet
2929
import printing._
30+
import util.Stats.record
3031
import config.{Settings, ScalaSettings, Platform, JavaPlatform}
3132
import language.implicitConversions
3233
import DenotTransformers.DenotTransformer
@@ -418,7 +419,10 @@ object Contexts {
418419
}
419420

420421
/** A fresh clone of this context. */
421-
def fresh: FreshContext = clone.asInstanceOf[FreshContext].init(this)
422+
def fresh: FreshContext = {
423+
record("context")
424+
clone.asInstanceOf[FreshContext].init(this)
425+
}
422426

423427
final def withOwner(owner: Symbol): Context =
424428
if (owner ne this.owner) fresh.setOwner(owner) else this
@@ -449,32 +453,32 @@ object Contexts {
449453
* of its attributes using the with... methods.
450454
*/
451455
abstract class FreshContext extends Context {
452-
def setPeriod(period: Period): this.type = { this.period = period; this }
453-
def setMode(mode: Mode): this.type = { this.mode = mode; this }
456+
def setPeriod(period: Period): this.type = { record("context-period"); this.period = period; this }
457+
def setMode(mode: Mode): this.type = { record("context-mode"); this.mode = mode; this }
454458
def setCompilerCallback(callback: CompilerCallback): this.type = { this.compilerCallback = callback; this }
455459
def setSbtCallback(callback: AnalysisCallback): this.type = { this.sbtCallback = callback; this }
456-
def setTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this }
460+
def setTyperState(typerState: TyperState): this.type = { record("context-typerState"); this.typerState = typerState; this }
457461
def setReporter(reporter: Reporter): this.type = setTyperState(typerState.withReporter(reporter))
458-
def setNewTyperState: this.type = setTyperState(typerState.fresh(isCommittable = true))
459-
def setExploreTyperState: this.type = setTyperState(typerState.fresh(isCommittable = false))
462+
def setNewTyperState: this.type = { record("new typerState"); setTyperState(typerState.fresh(isCommittable = true)) }
463+
def setExploreTyperState: this.type = { record("explore typerState"); setTyperState(typerState.fresh(isCommittable = false)) }
460464
def setPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this }
461-
def setOwner(owner: Symbol): this.type = { assert(owner != NoSymbol); this.owner = owner; this }
465+
def setOwner(owner: Symbol): this.type = { record("context-owner"); assert(owner != NoSymbol); this.owner = owner; this }
462466
def setSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this }
463467
def setCompilationUnit(compilationUnit: CompilationUnit): this.type = { this.compilationUnit = compilationUnit; this }
464-
def setTree(tree: Tree[_ >: Untyped]): this.type = { this.tree = tree; this }
465-
def setScope(scope: Scope): this.type = { this.scope = scope; this }
468+
def setTree(tree: Tree[_ >: Untyped]): this.type = { record("context-tree"); this.tree = tree; this }
469+
def setScope(scope: Scope): this.type = { record("context-scope"); this.scope = scope; this }
466470
def setNewScope: this.type = { this.scope = newScope; this }
467471
def setTypeAssigner(typeAssigner: TypeAssigner): this.type = { this.typeAssigner = typeAssigner; this }
468472
def setTyper(typer: Typer): this.type = { this.scope = typer.scope; setTypeAssigner(typer) }
469473
def setImportInfo(importInfo: ImportInfo): this.type = { this.importInfo = importInfo; this }
470-
def setImplicits(implicits: ContextualImplicits): this.type = { this.implicitsCache = implicits; this }
474+
def setImplicits(implicits: ContextualImplicits): this.type = { record("context-implicits"); this.implicitsCache = implicits; this }
471475
def setRunInfo(runInfo: RunInfo): this.type = { this.runInfo = runInfo; this }
472476
def setDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this }
473-
def setGadt(gadt: GADTMap): this.type = { this.gadt = gadt; this }
477+
def setGadt(gadt: GADTMap): this.type = { record("context-gadt"); this.gadt = gadt; this }
474478
def setTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this }
475479
def setSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this }
476480
def setFreshNames(freshNames: FreshNameCreator): this.type = { this.freshNames = freshNames; this }
477-
def setMoreProperties(moreProperties: Map[Key[Any], Any]): this.type = { this.moreProperties = moreProperties; this }
481+
def setMoreProperties(moreProperties: Map[Key[Any], Any]): this.type = { record("context-moreProps"); this.moreProperties = moreProperties; this }
478482

479483
def setProperty[T](key: Key[T], value: T): this.type =
480484
setMoreProperties(moreProperties.updated(key, value))

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,10 @@ object Types {
735735
*/
736736
final def asSeenFrom(pre: Type, cls: Symbol)(implicit ctx: Context): Type = track("asSeenFrom") {
737737
if (!cls.membersNeedAsSeenFrom(pre)) this
738-
else ctx.asSeenFrom(this, pre, cls)
738+
else {
739+
record("asSeenFrom")
740+
ctx.asSeenFrom(this, pre, cls)
741+
}
739742
}
740743

741744
// ----- Subtype-related --------------------------------------------
@@ -1260,7 +1263,8 @@ object Types {
12601263
/** Substitute all types that refer in their symbol attribute to
12611264
* one of the symbols in `from` by the corresponding types in `to`.
12621265
*/
1263-
final def subst(from: List[Symbol], to: List[Type])(implicit ctx: Context): Type =
1266+
final def subst(from: List[Symbol], to: List[Type])(implicit ctx: Context): Type = {
1267+
record("substSymsTypes")
12641268
if (from.isEmpty) this
12651269
else {
12661270
val from1 = from.tail
@@ -1271,6 +1275,7 @@ object Types {
12711275
else ctx.subst(this, from, to)
12721276
}
12731277
}
1278+
}
12741279

12751280
/** Same as `subst` but follows aliases as a fallback. When faced with a reference
12761281
* to an alias type, where normal substitution does not yield a new type, the
@@ -1280,39 +1285,53 @@ object Types {
12801285
* of a class and also wants to substitute any parameter accessors that alias
12811286
* the type parameters.
12821287
*/
1283-
final def substDealias(from: List[Symbol], to: List[Type])(implicit ctx: Context): Type =
1288+
final def substDealias(from: List[Symbol], to: List[Type])(implicit ctx: Context): Type = {
1289+
record("substDealias")
12841290
ctx.substDealias(this, from, to)
1291+
}
12851292

12861293
/** Substitute all types of the form `TypeParamRef(from, N)` by
12871294
* `TypeParamRef(to, N)`.
12881295
*/
1289-
final def subst(from: BindingType, to: BindingType)(implicit ctx: Context): Type =
1296+
final def subst(from: BindingType, to: BindingType)(implicit ctx: Context): Type = {
1297+
record("substBindings")
12901298
ctx.subst(this, from, to)
1299+
}
12911300

12921301
/** Substitute all occurrences of `This(cls)` by `tp` */
1293-
final def substThis(cls: ClassSymbol, tp: Type)(implicit ctx: Context): Type =
1302+
final def substThis(cls: ClassSymbol, tp: Type)(implicit ctx: Context): Type = {
1303+
record("substThis")
12941304
ctx.substThis(this, cls, tp)
1305+
}
12951306

1296-
/** As substThis, but only is class is a static owner (i.e. a globally accessible object) */
1307+
/** As substThis, but only is class is not a static owner (i.e. a globally accessible object) */
12971308
final def substThisUnlessStatic(cls: ClassSymbol, tp: Type)(implicit ctx: Context): Type =
1298-
if (cls.isStaticOwner) this else ctx.substThis(this, cls, tp)
1299-
1309+
if (cls.isStaticOwner) this else {
1310+
record("substThis")
1311+
ctx.substThis(this, cls, tp)
1312+
}
13001313
/** Substitute all occurrences of `RecThis(binder)` by `tp` */
13011314
final def substRecThis(binder: RecType, tp: Type)(implicit ctx: Context): Type =
13021315
ctx.substRecThis(this, binder, tp)
13031316

13041317
/** Substitute a bound type by some other type */
1305-
final def substParam(from: ParamRef, to: Type)(implicit ctx: Context): Type =
1318+
final def substParam(from: ParamRef, to: Type)(implicit ctx: Context): Type = {
1319+
record("substParam")
13061320
ctx.substParam(this, from, to)
1321+
}
13071322

13081323
/** Substitute bound types by some other types */
1309-
final def substParams(from: BindingType, to: List[Type])(implicit ctx: Context): Type =
1324+
final def substParams(from: BindingType, to: List[Type])(implicit ctx: Context): Type = {
1325+
record("substParams")
13101326
ctx.substParams(this, from, to)
1327+
}
13111328

13121329
/** Substitute all occurrences of symbols in `from` by references to corresponding symbols in `to`
13131330
*/
1314-
final def substSym(from: List[Symbol], to: List[Symbol])(implicit ctx: Context): Type =
1331+
final def substSym(from: List[Symbol], to: List[Symbol])(implicit ctx: Context): Type = {
1332+
record("substSym")
13151333
ctx.substSym(this, from, to)
1334+
}
13161335

13171336
// ----- misc -----------------------------------------------------------
13181337

@@ -3769,6 +3788,8 @@ object Types {
37693788
abstract class TypeMap(implicit protected val ctx: Context)
37703789
extends VariantTraversal with (Type => Type) { thisMap =>
37713790

3791+
record("all typemaps")
3792+
record(s"typemap: $getClass")
37723793
protected def stopAtStatic = true
37733794

37743795
def apply(tp: Type): Type
@@ -3834,6 +3855,7 @@ object Types {
38343855

38353856
def mapOver2(tp: Type) = tp match {
38363857
case tp: AppliedType =>
3858+
record(s"mapOver2 AppliedType")
38373859
def mapArgs(args: List[Type], tparams: List[ParamInfo]): List[Type] = args match {
38383860
case arg :: otherArgs =>
38393861
val arg1 = arg match {
@@ -3852,6 +3874,7 @@ object Types {
38523874
}
38533875

38543876
def mapOver3(tp: Type) = {
3877+
record(s"mapOver3 ${tp.getClass}")
38553878
implicit val ctx = this.ctx
38563879
tp match {
38573880
case tp: RefinedType =>
@@ -3978,7 +4001,7 @@ object Types {
39784001
*/
39794002
abstract class ApproximatingTypeMap(implicit ctx: Context) extends TypeMap { thisMap =>
39804003

3981-
protected def range(lo: Type, hi: Type) =
4004+
def range(lo: Type, hi: Type) =
39824005
if (variance > 0) hi
39834006
else if (variance < 0) lo
39844007
else Range(lower(lo), upper(hi))

0 commit comments

Comments
 (0)