Skip to content

Improve instrumentation #9592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case info2: TypeBounds =>
compareLower(info2, tyconIsTypeRef = true)
case info2: ClassInfo =>
tycon2.name.toString.startsWith("Tuple") &&
tycon2.name.startsWith("Tuple") &&
defn.isTupleType(tp2) && recur(tp1, tp2.toNestedPairs) ||
tryBaseType(info2.cls)
case _ =>
Expand Down
25 changes: 16 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/Instrumentation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Decorators._
import ast.Trees._
import MegaPhase._
import StdNames.nme
import Names.TermName
import Names._
import Constants.Constant


Expand All @@ -28,25 +28,32 @@ class Instrumentation extends MiniPhase { thisPhase =>
ctx.settings.YinstrumentClosures.value ||
ctx.settings.YinstrumentAllocations.value

private val namesOfInterest = List(
"::", "+=", "toString", "newArray", "box",
"map", "flatMap", "filter", "withFilter", "collect", "foldLeft", "foldRight", "take",
"reverse", "mapConserve", "mapconserve", "filterConserve", "zip")
private var namesToRecord: Set[Name] = _

private var consName: TermName = _
private var consEqName: TermName = _

override def prepareForUnit(tree: Tree)(using Context): Context = {
consName = "::".toTermName
consEqName = "+=".toTermName
override def prepareForUnit(tree: Tree)(using Context): Context =
namesToRecord = namesOfInterest.map(_.toTermName).toSet
ctx
}

private def record(category: String, tree: Tree)(using Context): Tree = {
val key = Literal(Constant(s"$category${tree.sourcePos.show}"))
val key = Literal(Constant(s"$category@${tree.sourcePos.show}"))
ref(defn.Stats_doRecord).appliedTo(key, Literal(Constant(1)))
}

private def ok(using Context) =
!ctx.owner.ownersIterator.exists(_.name.toString.startsWith("Stats"))

override def transformApply(tree: Apply)(using Context): Tree = tree.fun match {
case Select(nu: New, _) =>
cpy.Block(tree)(record(i"alloc/${nu.tpe}@", tree) :: Nil, tree)
case Select(_, name) if name == consName || name == consEqName =>
cpy.Block(tree)(record("alloc/::", tree) :: Nil, tree)
cpy.Block(tree)(record(i"alloc/${nu.tpe}", tree) :: Nil, tree)
case ref: RefTree if namesToRecord.contains(ref.name) && ok =>
cpy.Block(tree)(record(i"call/${ref.name}", tree) :: Nil, tree)
case _ =>
tree
}
Expand Down