From 5f3e2ce75c1223efc2bbacdb3e546f7d2628880a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 17 Aug 2012 18:53:25 +0200 Subject: Made all statistic code disappear unless built with Statistics.canEnable = true --- .../scala/tools/nsc/symtab/SymbolLoaders.scala | 4 +- .../scala/tools/nsc/typechecker/Analyzer.scala | 4 +- .../scala/tools/nsc/typechecker/Implicits.scala | 66 +++++++++--------- .../scala/tools/nsc/typechecker/Macros.scala | 6 +- .../tools/nsc/typechecker/PatternMatching.scala | 26 +++---- .../scala/tools/nsc/typechecker/Typers.scala | 46 ++++++------- .../scala/reflect/internal/BaseTypeSeqs.scala | 4 +- src/reflect/scala/reflect/internal/Symbols.scala | 2 +- src/reflect/scala/reflect/internal/Trees.scala | 2 +- src/reflect/scala/reflect/internal/Types.scala | 79 +++++++++++----------- .../scala/reflect/internal/util/Statistics.scala | 22 ++++-- 11 files changed, 138 insertions(+), 123 deletions(-) diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index 213a995e96..8e77f8b6f4 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -250,7 +250,7 @@ abstract class SymbolLoaders { protected def description = "class file "+ classfile.toString protected def doComplete(root: Symbol) { - val start = Statistics.startTimer(classReadNanos) + val start = if (Statistics.canEnable) Statistics.startTimer(classReadNanos) else null classfileParser.parse(classfile, root) if (root.associatedFile eq null) { root match { @@ -262,7 +262,7 @@ abstract class SymbolLoaders { debuglog("Not setting associatedFile to %s because %s is a %s".format(classfile, root.name, root.shortSymbolClass)) } } - Statistics.stopTimer(classReadNanos, start) + if (Statistics.canEnable) Statistics.stopTimer(classReadNanos, start) } override def sourcefile: Option[AbstractFile] = classfileParser.srcfile } diff --git a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala index 7f4f61bf80..ab8836f339 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala @@ -85,13 +85,13 @@ trait Analyzer extends AnyRef // compiler run). This is good enough for the resident compiler, which was the most affected. undoLog.clear() override def run() { - val start = Statistics.startTimer(typerNanos) + val start = if (Statistics.canEnable) Statistics.startTimer(typerNanos) else null global.echoPhaseSummary(this) currentRun.units foreach applyPhase undoLog.clear() // need to clear it after as well or 10K+ accumulated entries are // uncollectable the rest of the way. - Statistics.stopTimer(typerNanos, start) + if (Statistics.canEnable) Statistics.stopTimer(typerNanos, start) } def apply(unit: CompilationUnit) { try { diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index f7fb17dee6..226e17f605 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -72,10 +72,10 @@ trait Implicits { ) indentTyping() - val rawTypeStart = Statistics.startCounter(rawTypeImpl) - val findMemberStart = Statistics.startCounter(findMemberImpl) - val subtypeStart = Statistics.startCounter(subtypeImpl) - val start = Statistics.startTimer(implicitNanos) + val rawTypeStart = if (Statistics.canEnable) Statistics.startCounter(rawTypeImpl) else null + val findMemberStart = if (Statistics.canEnable) Statistics.startCounter(findMemberImpl) else null + val subtypeStart = if (Statistics.canEnable) Statistics.startCounter(subtypeImpl) else null + val start = if (Statistics.canEnable) Statistics.startTimer(implicitNanos) else null if (printInfers && !tree.isEmpty && !context.undetparams.isEmpty) printTyping("typing implicit: %s %s".format(tree, context.undetparamsString)) val implicitSearchContext = context.makeImplicit(reportAmbiguous) @@ -87,10 +87,10 @@ trait Implicits { printInference("[infer implicit] inferred " + result) context.undetparams = context.undetparams filterNot result.subst.from.contains - Statistics.stopTimer(implicitNanos, start) - Statistics.stopCounter(rawTypeImpl, rawTypeStart) - Statistics.stopCounter(findMemberImpl, findMemberStart) - Statistics.stopCounter(subtypeImpl, subtypeStart) + if (Statistics.canEnable) Statistics.stopTimer(implicitNanos, start) + if (Statistics.canEnable) Statistics.stopCounter(rawTypeImpl, rawTypeStart) + if (Statistics.canEnable) Statistics.stopCounter(findMemberImpl, findMemberStart) + if (Statistics.canEnable) Statistics.stopCounter(subtypeImpl, subtypeStart) deindentTyping() printTyping("Implicit search yielded: "+ result) result @@ -308,12 +308,12 @@ trait Implicits { /** Is implicit info `info1` better than implicit info `info2`? */ def improves(info1: ImplicitInfo, info2: ImplicitInfo) = { - Statistics.incCounter(improvesCount) + if (Statistics.canEnable) Statistics.incCounter(improvesCount) (info2 == NoImplicitInfo) || (info1 != NoImplicitInfo) && { if (info1.sym.isStatic && info2.sym.isStatic) { improvesCache get (info1, info2) match { - case Some(b) => Statistics.incCounter(improvesCachedCount); b + case Some(b) => if (Statistics.canEnable) Statistics.incCounter(improvesCachedCount); b case None => val result = isStrictlyMoreSpecific(info1.tpe, info2.tpe, info1.sym, info2.sym) improvesCache((info1, info2)) = result @@ -377,7 +377,7 @@ trait Implicits { overlaps(dtor1, dted1) && (dtor1 =:= dted1 || complexity(dtor1) > complexity(dted1)) } - Statistics.incCounter(implicitSearchCount) + if (Statistics.canEnable) Statistics.incCounter(implicitSearchCount) /** The type parameters to instantiate */ val undetParams = if (isView) List() else context.outer.undetparams @@ -429,7 +429,7 @@ trait Implicits { * This method is performance critical: 5-8% of typechecking time. */ private def matchesPt(tp: Type, pt: Type, undet: List[Symbol]): Boolean = { - val start = Statistics.startTimer(matchesPtNanos) + val start = if (Statistics.canEnable) Statistics.startTimer(matchesPtNanos) else null val result = normSubType(tp, pt) || isView && { pt match { case TypeRef(_, Function1.Sym, args) => @@ -438,7 +438,7 @@ trait Implicits { false } } - Statistics.stopTimer(matchesPtNanos, start) + if (Statistics.canEnable) Statistics.stopTimer(matchesPtNanos, start) result } private def matchesPt(info: ImplicitInfo): Boolean = ( @@ -537,7 +537,7 @@ trait Implicits { } private def typedImplicit0(info: ImplicitInfo, ptChecked: Boolean, isLocal: Boolean): SearchResult = { - Statistics.incCounter(plausiblyCompatibleImplicits) + if (Statistics.canEnable) Statistics.incCounter(plausiblyCompatibleImplicits) printTyping ( ptBlock("typedImplicit0", "info.name" -> info.name, @@ -557,7 +557,7 @@ trait Implicits { } private def typedImplicit1(info: ImplicitInfo, isLocal: Boolean): SearchResult = { - Statistics.incCounter(matchingImplicits) + if (Statistics.canEnable) Statistics.incCounter(matchingImplicits) val itree = atPos(pos.focus) { // workaround for deficient context provided by ModelFactoryImplicitSupport#makeImplicitConstraints @@ -595,7 +595,7 @@ trait Implicits { if (context.hasErrors) return fail("typed implicit %s has errors".format(info.sym.fullLocationString)) - Statistics.incCounter(typedImplicits) + if (Statistics.canEnable) Statistics.incCounter(typedImplicits) printTyping("typed implicit %s:%s, pt=%s".format(itree1, itree1.tpe, wildPt)) val itree2 = if (isView) (itree1: @unchecked) match { case Apply(fun, _) => fun } @@ -678,7 +678,7 @@ trait Implicits { fail("typing TypeApply reported errors for the implicit tree") else { val result = new SearchResult(itree2, subst) - Statistics.incCounter(foundImplicits) + if (Statistics.canEnable) Statistics.incCounter(foundImplicits) printInference("[success] found %s for pt %s".format(result, ptInstantiated)) result } @@ -905,11 +905,11 @@ trait Implicits { * @return map from infos to search results */ def applicableInfos(iss: Infoss, isLocal: Boolean): Map[ImplicitInfo, SearchResult] = { - val start = Statistics.startCounter(subtypeAppInfos) + val start = if (Statistics.canEnable) Statistics.startCounter(subtypeAppInfos) else null val computation = new ImplicitComputation(iss, isLocal) { } val applicable = computation.findAll() - Statistics.stopCounter(subtypeAppInfos, start) + if (Statistics.canEnable) Statistics.stopCounter(subtypeAppInfos, start) applicable } @@ -1125,13 +1125,13 @@ trait Implicits { * such that some part of `tp` has C as one of its superclasses. */ private def implicitsOfExpectedType: Infoss = { - Statistics.incCounter(implicitCacheAccs) + if (Statistics.canEnable) Statistics.incCounter(implicitCacheAccs) implicitsCache get pt match { case Some(implicitInfoss) => - Statistics.incCounter(implicitCacheHits) + if (Statistics.canEnable) Statistics.incCounter(implicitCacheHits) implicitInfoss case None => - val start = Statistics.startTimer(subtypeETNanos) + val start = if (Statistics.canEnable) Statistics.startTimer(subtypeETNanos) else null // val implicitInfoss = companionImplicits(pt) val implicitInfoss1 = companionImplicitMap(pt).valuesIterator.toList // val is1 = implicitInfoss.flatten.toSet @@ -1140,7 +1140,7 @@ trait Implicits { // if (!(is2 contains i)) println("!!! implicit infos of "+pt+" differ, new does not contain "+i+",\nold: "+implicitInfoss+",\nnew: "+implicitInfoss1) // for (i <- is2) // if (!(is1 contains i)) println("!!! implicit infos of "+pt+" differ, old does not contain "+i+",\nold: "+implicitInfoss+",\nnew: "+implicitInfoss1) - Statistics.stopTimer(subtypeETNanos, start) + if (Statistics.canEnable) Statistics.stopTimer(subtypeETNanos, start) implicitsCache(pt) = implicitInfoss1 if (implicitsCache.size >= sizeLimit) implicitsCache -= implicitsCache.keysIterator.next @@ -1372,21 +1372,21 @@ trait Implicits { * If all fails return SearchFailure */ def bestImplicit: SearchResult = { - val failstart = Statistics.startTimer(inscopeFailNanos) - val succstart = Statistics.startTimer(inscopeSucceedNanos) + val failstart = if (Statistics.canEnable) Statistics.startTimer(inscopeFailNanos) else null + val succstart = if (Statistics.canEnable) Statistics.startTimer(inscopeSucceedNanos) else null var result = searchImplicit(context.implicitss, true) if (result == SearchFailure) { - Statistics.stopTimer(inscopeFailNanos, failstart) + if (Statistics.canEnable) Statistics.stopTimer(inscopeFailNanos, failstart) } else { - Statistics.stopTimer(inscopeSucceedNanos, succstart) - Statistics.incCounter(inscopeImplicitHits) + if (Statistics.canEnable) Statistics.stopTimer(inscopeSucceedNanos, succstart) + if (Statistics.canEnable) Statistics.incCounter(inscopeImplicitHits) } if (result == SearchFailure) { val previousErrs = context.flushAndReturnBuffer() - val failstart = Statistics.startTimer(oftypeFailNanos) - val succstart = Statistics.startTimer(oftypeSucceedNanos) + val failstart = if (Statistics.canEnable) Statistics.startTimer(oftypeFailNanos) else null + val succstart = if (Statistics.canEnable) Statistics.startTimer(oftypeSucceedNanos) else null result = materializeImplicit(pt) @@ -1396,10 +1396,10 @@ trait Implicits { if (result == SearchFailure) { context.updateBuffer(previousErrs) - Statistics.stopTimer(oftypeFailNanos, failstart) + if (Statistics.canEnable) Statistics.stopTimer(oftypeFailNanos, failstart) } else { - Statistics.stopTimer(oftypeSucceedNanos, succstart) - Statistics.incCounter(oftypeImplicitHits) + if (Statistics.canEnable) Statistics.stopTimer(oftypeSucceedNanos, succstart) + if (Statistics.canEnable) Statistics.incCounter(oftypeImplicitHits) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index abfefcd31e..dbafd01ebc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -696,8 +696,8 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { * the expandee with an error marker set if there has been an error */ def macroExpand(typer: Typer, expandee: Tree, mode: Int = EXPRmode, pt: Type = WildcardType): Tree = { - val start = Statistics.startTimer(macroExpandNanos) - Statistics.incCounter(macroExpandCount) + val start = if (Statistics.canEnable) Statistics.startTimer(macroExpandNanos) else null + if (Statistics.canEnable) Statistics.incCounter(macroExpandCount) try { macroExpand1(typer, expandee) match { case Success(expanded) => @@ -725,7 +725,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { result } } finally { - Statistics.stopTimer(macroExpandNanos, start) + if (Statistics.canEnable) Statistics.stopTimer(macroExpandNanos, start) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala index de927f783a..eaa18c142c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala @@ -277,7 +277,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL if(phase.id >= currentRun.uncurryPhase.id) debugwarn("running translateMatch at "+ phase +" on "+ selector +" match "+ cases) patmatDebug("translating "+ cases.mkString("{", "\n", "}")) - val start = Statistics.startTimer(patmatNanos) + val start = if (Statistics.canEnable) Statistics.startTimer(patmatNanos) else null val selectorTp = repeatedToSeq(elimAnonymousClass(selector.tpe.widen.withoutAnnotations)) @@ -305,7 +305,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL // pt = Any* occurs when compiling test/files/pos/annotDepMethType.scala with -Xexperimental val combined = combineCases(selector, selectorSym, cases map translateCase(selectorSym, pt), pt, matchOwner, matchFailGenOverride) - Statistics.stopTimer(patmatNanos, start) + if (Statistics.canEnable) Statistics.stopTimer(patmatNanos, start) combined } @@ -1954,7 +1954,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL // TODO: for V1 representing x1 and V2 standing for x1.head, encode that // V1 = Nil implies -(V2 = Ci) for all Ci in V2's domain (i.e., it is unassignable) def removeVarEq(props: List[Prop], modelNull: Boolean = false): (Prop, List[Prop]) = { - val start = Statistics.startTimer(patmatAnaVarEq) + val start = if (Statistics.canEnable) Statistics.startTimer(patmatAnaVarEq) else null val vars = new collection.mutable.HashSet[Var] @@ -2009,7 +2009,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL patmatDebug("eqAxioms:\n"+ cnfString(eqFreePropToSolvable(eqAxioms))) patmatDebug("pure:"+ pure.map(p => cnfString(eqFreePropToSolvable(p))).mkString("\n")) - Statistics.stopTimer(patmatAnaVarEq, start) + if (Statistics.canEnable) Statistics.stopTimer(patmatAnaVarEq, start) (eqAxioms, pure) } @@ -2121,13 +2121,13 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL } } - val start = Statistics.startTimer(patmatCNF) + val start = if (Statistics.canEnable) Statistics.startTimer(patmatCNF) else null val res = conjunctiveNormalForm(negationNormalForm(p)) - Statistics.stopTimer(patmatCNF, start) + if (Statistics.canEnable) Statistics.stopTimer(patmatCNF, start) // - if (Statistics.enabled) patmatCNFSizes(res.size).value += 1 + if (Statistics.canEnable) patmatCNFSizes(res.size).value += 1 // patmatDebug("cnf for\n"+ p +"\nis:\n"+cnfString(res)) res @@ -2204,7 +2204,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL patmatDebug("DPLL\n"+ cnfString(f)) - val start = Statistics.startTimer(patmatAnaDPLL) + val start = if (Statistics.canEnable) Statistics.startTimer(patmatAnaDPLL) else null val satisfiableWithModel: Model = if (f isEmpty) EmptyModel @@ -2242,7 +2242,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL } } - Statistics.stopTimer(patmatAnaDPLL, start) + if (Statistics.canEnable) Statistics.stopTimer(patmatAnaDPLL, start) satisfiableWithModel } @@ -2603,7 +2603,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL // thus, the case is unreachable if there is no model for -(-P /\ C), // or, equivalently, P \/ -C, or C => P def unreachableCase(prevBinder: Symbol, cases: List[List[TreeMaker]], pt: Type): Option[Int] = { - val start = Statistics.startTimer(patmatAnaReach) + val start = if (Statistics.canEnable) Statistics.startTimer(patmatAnaReach) else null // use the same approximator so we share variables, // but need different conditions depending on whether we're conservatively looking for failure or success @@ -2657,7 +2657,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL } } - Statistics.stopTimer(patmatAnaReach, start) + if (Statistics.canEnable) Statistics.stopTimer(patmatAnaReach, start) if (reachable) None else Some(caseIndex) } catch { @@ -2750,7 +2750,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL // - back off (to avoid crying exhaustive too often) when: // - there are guards --> // - there are extractor calls (that we can't secretly/soundly) rewrite - val start = Statistics.startTimer(patmatAnaExhaust) + val start = if (Statistics.canEnable) Statistics.startTimer(patmatAnaExhaust) else null var backoff = false val approx = new TreeMakersToConds(prevBinder) @@ -2802,7 +2802,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL val pruned = CounterExample.prune(counterExamples).map(_.toString).sorted - Statistics.stopTimer(patmatAnaExhaust, start) + if (Statistics.canEnable) Statistics.stopTimer(patmatAnaExhaust, start) pruned } catch { case ex : AnalysisBudget.Exception => diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index ff951a0436..2e680c8df6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -706,15 +706,15 @@ trait Typers extends Modes with Adaptations with Tags { def silent[T](op: Typer => T, reportAmbiguousErrors: Boolean = context.ambiguousErrors, newtree: Tree = context.tree): SilentResult[T] = { - val rawTypeStart = Statistics.startCounter(rawTypeFailed) - val findMemberStart = Statistics.startCounter(findMemberFailed) - val subtypeStart = Statistics.startCounter(subtypeFailed) - val failedSilentStart = Statistics.startTimer(failedSilentNanos) + val rawTypeStart = if (Statistics.canEnable) Statistics.startCounter(rawTypeFailed) else null + val findMemberStart = if (Statistics.canEnable) Statistics.startCounter(findMemberFailed) else null + val subtypeStart = if (Statistics.canEnable) Statistics.startCounter(subtypeFailed) else null + val failedSilentStart = if (Statistics.canEnable) Statistics.startTimer(failedSilentNanos) else null def stopStats() = { - Statistics.stopCounter(rawTypeFailed, rawTypeStart) - Statistics.stopCounter(findMemberFailed, findMemberStart) - Statistics.stopCounter(subtypeFailed, subtypeStart) - Statistics.stopTimer(failedSilentNanos, failedSilentStart) + if (Statistics.canEnable) Statistics.stopCounter(rawTypeFailed, rawTypeStart) + if (Statistics.canEnable) Statistics.stopCounter(findMemberFailed, findMemberStart) + if (Statistics.canEnable) Statistics.stopCounter(subtypeFailed, subtypeStart) + if (Statistics.canEnable) Statistics.stopTimer(failedSilentNanos, failedSilentStart) } try { if (context.reportErrors || @@ -3588,9 +3588,9 @@ trait Typers extends Modes with Adaptations with Tags { def isCapturedExistential(sym: Symbol) = (sym hasAllFlags (EXISTENTIAL | CAPTURED)) && { - val start = Statistics.startTimer(isReferencedNanos) + val start = if (Statistics.canEnable) Statistics.startTimer(isReferencedNanos) else null try !isReferencedFrom(context, sym) - finally Statistics.stopTimer(isReferencedNanos, start) + finally if (Statistics.canEnable) Statistics.stopTimer(isReferencedNanos, start) } def packCaptured(tpe: Type): Type = { @@ -4239,10 +4239,10 @@ trait Typers extends Modes with Adaptations with Tags { * insert an implicit conversion. */ def tryTypedApply(fun: Tree, args: List[Tree]): Tree = { - val start = Statistics.startTimer(failedApplyNanos) + val start = if (Statistics.canEnable) Statistics.startTimer(failedApplyNanos) else null def onError(typeError: AbsTypeError): Tree = { - Statistics.stopTimer(failedApplyNanos, start) + if (Statistics.canEnable) Statistics.stopTimer(failedApplyNanos, start) // If the problem is with raw types, copnvert to existentials and try again. // See #4712 for a case where this situation arises, @@ -4305,8 +4305,8 @@ trait Typers extends Modes with Adaptations with Tags { typed1(tree, mode & ~PATTERNmode | EXPRmode, pt) } else { val funpt = if (isPatternMode) pt else WildcardType - val appStart = Statistics.startTimer(failedApplyNanos) - val opeqStart = Statistics.startTimer(failedOpEqNanos) + val appStart = if (Statistics.canEnable) Statistics.startTimer(failedApplyNanos) else null + val opeqStart = if (Statistics.canEnable) Statistics.startTimer(failedOpEqNanos) else null def onError(reportError: => Tree): Tree = { fun match { @@ -4314,14 +4314,14 @@ trait Typers extends Modes with Adaptations with Tags { if !isPatternMode && nme.isOpAssignmentName(newTermName(name.decode)) => val qual1 = typedQualifier(qual) if (treeInfo.isVariableOrGetter(qual1)) { - Statistics.stopTimer(failedOpEqNanos, opeqStart) + if (Statistics.canEnable) Statistics.stopTimer(failedOpEqNanos, opeqStart) convertToAssignment(fun, qual1, name, args) } else { - Statistics.stopTimer(failedApplyNanos, appStart) + if (Statistics.canEnable) Statistics.stopTimer(failedApplyNanos, appStart) reportError } case _ => - Statistics.stopTimer(failedApplyNanos, appStart) + if (Statistics.canEnable) Statistics.stopTimer(failedApplyNanos, appStart) reportError } } @@ -4330,7 +4330,7 @@ trait Typers extends Modes with Adaptations with Tags { if ((mode & EXPRmode) != 0) tree else context.tree) match { case SilentResultValue(fun1) => val fun2 = if (stableApplication) stabilizeFun(fun1, mode, pt) else fun1 - Statistics.incCounter(typedApplyCount) + if (Statistics.canEnable) Statistics.incCounter(typedApplyCount) def isImplicitMethod(tpe: Type) = tpe match { case mt: MethodType => mt.isImplicit case _ => false @@ -4626,7 +4626,7 @@ trait Typers extends Modes with Adaptations with Tags { // the qualifier type of a supercall constructor is its first parent class typedSelect(tree, qual1, nme.CONSTRUCTOR) case _ => - Statistics.incCounter(typedSelectCount) + if (Statistics.canEnable) Statistics.incCounter(typedSelectCount) var qual1 = checkDead(typedQualifier(qual, mode)) if (name.isTypeName) qual1 = checkStable(qual1) @@ -4906,7 +4906,7 @@ trait Typers extends Modes with Adaptations with Tags { def typedIdentOrWildcard(tree: Ident) = { val name = tree.name - Statistics.incCounter(typedIdentCount) + if (Statistics.canEnable) Statistics.incCounter(typedIdentCount) if ((name == nme.WILDCARD && (mode & (PATTERNmode | FUNmode)) == PATTERNmode) || (name == tpnme.WILDCARD && (mode & TYPEmode) != 0)) tree setType makeFullyDefined(pt) @@ -5386,8 +5386,8 @@ trait Typers extends Modes with Adaptations with Tags { indentTyping() var alreadyTyped = false - val startByType = Statistics.pushTimer(byTypeStack, byTypeNanos(tree.getClass)) - Statistics.incCounter(visitsByType, tree.getClass) + val startByType = if (Statistics.canEnable) Statistics.pushTimer(byTypeStack, byTypeNanos(tree.getClass)) else null + if (Statistics.canEnable) Statistics.incCounter(visitsByType, tree.getClass) try { if (context.retyping && (tree.tpe ne null) && (tree.tpe.isErroneous || !(tree.tpe <:< pt))) { @@ -5442,7 +5442,7 @@ trait Typers extends Modes with Adaptations with Tags { } finally { deindentTyping() - Statistics.popTimer(byTypeStack, startByType) + if (Statistics.canEnable) Statistics.popTimer(byTypeStack, startByType) } } diff --git a/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala b/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala index fbee906b7b..554b3bfca6 100644 --- a/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala +++ b/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala @@ -39,8 +39,8 @@ trait BaseTypeSeqs { */ class BaseTypeSeq protected[BaseTypeSeqs] (private[BaseTypeSeqs] val parents: List[Type], private[BaseTypeSeqs] val elems: Array[Type]) { self => - Statistics.incCounter(baseTypeSeqCount) - Statistics.incCounter(baseTypeSeqLenTotal, elems.length) + if (Statistics.canEnable) Statistics.incCounter(baseTypeSeqCount) + if (Statistics.canEnable) Statistics.incCounter(baseTypeSeqLenTotal, elems.length) /** The number of types in the sequence */ def length: Int = elems.length diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index f9e4005d16..7b6aeb4d72 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2884,7 +2884,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => } override def name: TypeName = { - Statistics.incCounter(nameCount) + if (Statistics.canEnable) Statistics.incCounter(nameCount) if (needsFlatClasses) { if (flatname eq null) flatname = nme.flattenedName(rawowner.name, rawname).toTypeName diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 8405b95527..b4bfbd410a 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -19,7 +19,7 @@ trait Trees extends api.Trees { self: SymbolTable => val id = nodeCount // TODO: add to attachment? nodeCount += 1 - Statistics.incCounter(TreesStats.nodeByType, getClass) + if (Statistics.canEnable) Statistics.incCounter(TreesStats.nodeByType, getClass) @inline final override def pos: Position = rawatt.pos diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 101097a32f..b23588707c 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -725,7 +725,8 @@ trait Types extends api.Types { self: SymbolTable => * = Int */ def asSeenFrom(pre: Type, clazz: Symbol): Type = { - TypesStats.timedTypeOp(asSeenFromNanos) { + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, asSeenFromNanos) else null + try { val trivial = ( this.isTrivial || phase.erasedTypes && pre.typeSymbol != ArrayClass @@ -740,7 +741,7 @@ trait Types extends api.Types { self: SymbolTable => if (m.capturedSkolems.isEmpty) tp1 else deriveType(m.capturedSkolems, _.cloneSymbol setFlag CAPTURED)(tp1) } - } + } finally if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) } /** The info of `sym`, seen as a member of this type. @@ -848,7 +849,7 @@ trait Types extends api.Types { self: SymbolTable => /** Is this type a subtype of that type? */ def <:<(that: Type): Boolean = { - if (util.Statistics.enabled) stat_<:<(that) + if (Statistics.canEnable) stat_<:<(that) else { (this eq that) || (if (explainSwitch) explain("<:", isSubType, this, that) @@ -876,26 +877,26 @@ trait Types extends api.Types { self: SymbolTable => } def stat_<:<(that: Type): Boolean = { - Statistics.incCounter(subtypeCount) - val start = Statistics.pushTimer(typeOpsStack, subtypeNanos) + if (Statistics.canEnable) Statistics.incCounter(subtypeCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, subtypeNanos) else null val result = (this eq that) || (if (explainSwitch) explain("<:", isSubType, this, that) else isSubType(this, that, AnyDepth)) - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) result } /** Is this type a weak subtype of that type? True also for numeric types, i.e. Int weak_<:< Long. */ def weak_<:<(that: Type): Boolean = { - Statistics.incCounter(subtypeCount) - val start = Statistics.pushTimer(typeOpsStack, subtypeNanos) + if (Statistics.canEnable) Statistics.incCounter(subtypeCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, subtypeNanos) else null val result = ((this eq that) || (if (explainSwitch) explain("weak_<:", isWeakSubType, this, that) else isWeakSubType(this, that))) - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) result } @@ -1058,8 +1059,8 @@ trait Types extends api.Types { self: SymbolTable => // See (t0851) for a situation where this happens. val suspension: List[TypeVar] = if (this.isGround) null else suspendTypeVarsInType(this) - Statistics.incCounter(findMembersCount) - val start = Statistics.pushTimer(typeOpsStack, findMembersNanos) + if (Statistics.canEnable) Statistics.incCounter(findMembersCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, findMembersNanos) else null //Console.println("find member " + name.decode + " in " + this + ":" + this.baseClasses)//DEBUG var members: Scope = null @@ -1111,7 +1112,7 @@ trait Types extends api.Types { self: SymbolTable => required |= DEFERRED excluded &= ~(DEFERRED.toLong) } // while (continue) - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) if (suspension ne null) suspension foreach (_.suspended = false) if (members eq null) EmptyScope else members } @@ -1134,8 +1135,8 @@ trait Types extends api.Types { self: SymbolTable => // See (t0851) for a situation where this happens. val suspension: List[TypeVar] = if (this.isGround) null else suspendTypeVarsInType(this) - Statistics.incCounter(findMemberCount) - val start = Statistics.pushTimer(typeOpsStack, findMemberNanos) + if (Statistics.canEnable) Statistics.incCounter(findMemberCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, findMemberNanos) else null //Console.println("find member " + name.decode + " in " + this + ":" + this.baseClasses)//DEBUG var member: Symbol = NoSymbol @@ -1165,7 +1166,7 @@ trait Types extends api.Types { self: SymbolTable => (flags & PrivateLocal) != PrivateLocal || (bcs0.head.hasTransOwner(bcs.head)))) { if (name.isTypeName || stableOnly && sym.isStable) { - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) if (suspension ne null) suspension foreach (_.suspended = false) return sym } else if (member eq NoSymbol) { @@ -1213,13 +1214,13 @@ trait Types extends api.Types { self: SymbolTable => required |= DEFERRED excluded &= ~(DEFERRED.toLong) } // while (continue) - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) if (suspension ne null) suspension foreach (_.suspended = false) if (members eq null) { - if (member == NoSymbol) Statistics.incCounter(noMemberCount) + if (member == NoSymbol) if (Statistics.canEnable) Statistics.incCounter(noMemberCount) member } else { - Statistics.incCounter(multMemberCount) + if (Statistics.canEnable) Statistics.incCounter(multMemberCount) lastM.tl = Nil baseClasses.head.newOverloaded(this, members) } @@ -1310,7 +1311,7 @@ trait Types extends api.Types { self: SymbolTable => override def isVolatile = underlying.isVolatile override def widen: Type = underlying.widen override def baseTypeSeq: BaseTypeSeq = { - Statistics.incCounter(singletonBaseTypeSeqCount) + if (Statistics.canEnable) Statistics.incCounter(singletonBaseTypeSeqCount) underlying.baseTypeSeq prepend this } override def isHigherKinded = false // singleton type classifies objects, thus must be kind * @@ -1667,8 +1668,8 @@ trait Types extends api.Types { self: SymbolTable => val bts = copyRefinedType(tpe.asInstanceOf[RefinedType], tpe.parents map varToParam, varToParam mapOver tpe.decls).baseTypeSeq tpe.baseTypeSeqCache = bts lateMap paramToVar } else { - Statistics.incCounter(compoundBaseTypeSeqCount) - val start = Statistics.pushTimer(typeOpsStack, baseTypeSeqNanos) + if (Statistics.canEnable) Statistics.incCounter(compoundBaseTypeSeqCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, baseTypeSeqNanos) else null try { tpe.baseTypeSeqCache = undetBaseTypeSeq tpe.baseTypeSeqCache = @@ -1677,7 +1678,7 @@ trait Types extends api.Types { self: SymbolTable => else compoundBaseTypeSeq(tpe) } finally { - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) } // [Martin] suppressing memo-ization solves the problem with "same type after erasure" errors // when compiling with @@ -1725,12 +1726,12 @@ trait Types extends api.Types { self: SymbolTable => if (period != currentPeriod) { tpe.baseClassesPeriod = currentPeriod if (!isValidForBaseClasses(period)) { - val start = Statistics.pushTimer(typeOpsStack, baseClassesNanos) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, baseClassesNanos) else null try { tpe.baseClassesCache = null tpe.baseClassesCache = tpe.memo(computeBaseClasses)(tpe.typeSymbol :: _.baseClasses.tail) } finally { - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) } } } @@ -2559,13 +2560,13 @@ trait Types extends api.Types { self: SymbolTable => if (period != currentPeriod) { tpe.baseTypeSeqPeriod = currentPeriod if (!isValidForBaseClasses(period)) { - Statistics.incCounter(typerefBaseTypeSeqCount) - val start = Statistics.pushTimer(typeOpsStack, baseTypeSeqNanos) + if (Statistics.canEnable) Statistics.incCounter(typerefBaseTypeSeqCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, baseTypeSeqNanos) else null try { tpe.baseTypeSeqCache = undetBaseTypeSeq tpe.baseTypeSeqCache = tpe.baseTypeSeqImpl } finally { - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) } } } @@ -3895,7 +3896,7 @@ trait Types extends api.Types { self: SymbolTable => private var uniqueRunId = NoRunId protected def unique[T <: Type](tp: T): T = { - Statistics.incCounter(rawTypeCount) + if (Statistics.canEnable) Statistics.incCounter(rawTypeCount) if (uniqueRunId != currentRunId) { uniques = util.HashSet[Type]("uniques", initialUniquesCapacity) perRunCaches.recordCache(uniques) @@ -5296,7 +5297,7 @@ trait Types extends api.Types { self: SymbolTable => /** Do `tp1` and `tp2` denote equivalent types? */ def isSameType(tp1: Type, tp2: Type): Boolean = try { - Statistics.incCounter(sametypeCount) + if (Statistics.canEnable) Statistics.incCounter(sametypeCount) subsametypeRecursions += 1 //OPT cutdown on Function0 allocation //was: @@ -6552,14 +6553,14 @@ trait Types extends api.Types { self: SymbolTable => case List() => NothingClass.tpe case List(t) => t case _ => - Statistics.incCounter(lubCount) - val start = Statistics.pushTimer(typeOpsStack, lubNanos) + if (Statistics.canEnable) Statistics.incCounter(lubCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, lubNanos) else null try { lub(ts, lubDepth(ts)) } finally { lubResults.clear() glbResults.clear() - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) } } @@ -6675,7 +6676,7 @@ trait Types extends api.Types { self: SymbolTable => indent = indent + " " assert(indent.length <= 100) } - Statistics.incCounter(nestedLubCount) + if (Statistics.canEnable) Statistics.incCounter(nestedLubCount) val res = lub0(ts) if (printLubs) { indent = indent stripSuffix " " @@ -6700,14 +6701,14 @@ trait Types extends api.Types { self: SymbolTable => case List() => AnyClass.tpe case List(t) => t case ts0 => - Statistics.incCounter(lubCount) - val start = Statistics.pushTimer(typeOpsStack, lubNanos) + if (Statistics.canEnable) Statistics.incCounter(lubCount) + val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, lubNanos) else null try { glbNorm(ts0, lubDepth(ts0)) } finally { lubResults.clear() glbResults.clear() - Statistics.popTimer(typeOpsStack, start) + if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start) } } @@ -6822,7 +6823,7 @@ trait Types extends api.Types { self: SymbolTable => } // if (settings.debug.value) { println(indent + "glb of " + ts + " at depth "+depth); indent = indent + " " } //DEBUG - Statistics.incCounter(nestedLubCount) + if (Statistics.canEnable) Statistics.incCounter(nestedLubCount) val res = glb0(ts) // if (settings.debug.value) { indent = indent.substring(0, indent.length() - 2); log(indent + "glb of " + ts + " is " + res) }//DEBUG @@ -7185,9 +7186,11 @@ object TypesStats { val singletonBaseTypeSeqCount = Statistics.newSubCounter(" of which for singletons", baseTypeSeqCount) val typeOpsStack = Statistics.newTimerStack() + /** Commented out, because right now this does not inline, so creates a closure which will distort statistics @inline final def timedTypeOp[T](c: Statistics.StackableTimer)(op: => T): T = { val start = Statistics.pushTimer(typeOpsStack, c) try op - finally Statistics.popTimer(typeOpsStack, start) + finally } + */ } diff --git a/src/reflect/scala/reflect/internal/util/Statistics.scala b/src/reflect/scala/reflect/internal/util/Statistics.scala index e503d812e6..e077e38fb6 100644 --- a/src/reflect/scala/reflect/internal/util/Statistics.scala +++ b/src/reflect/scala/reflect/internal/util/Statistics.scala @@ -236,6 +236,23 @@ quant) private var _enabled = false private val qs = new mutable.HashMap[String, Quantity] + + /** replace with + * + * final val canEnable = true + * + * and rebuild, to allow for statistics to be enabled + */ + final val canEnable = false + + /** replace with + * + * final def hotEnabled = _enabled + * + * and rebuild, to also count tiny but super-hot methods + * such as phase, flags, owner, name. + */ + final val hotEnabled = false def enabled = _enabled def enabled_=(cond: Boolean) = { @@ -253,9 +270,4 @@ quant) _enabled = true } } - - /** replace rhs with enabled and rebuild to also count tiny but super-hot methods - * such as phase, flags, owner, name. - */ - final val hotEnabled = false } -- cgit v1.2.3