Skip to content

Commit b868bc7

Browse files
committed
Also track newArray and box as allocations
1 parent 5ed661b commit b868bc7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Instrumentation.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Instrumentation extends MiniPhase { thisPhase =>
2929
ctx.settings.YinstrumentAllocations.value
3030

3131
private val namesOfInterest = List(
32-
"::", "+=", "toString",
32+
"::", "+=", "toString", "newArray", "box",
3333
"map", "flatMap", "filter", "withFilter", "collect", "foldLeft", "foldRight", "take",
3434
"reverse", "mapConserve", "mapconserve", "filterConserve", "zip")
3535
private var namesToRecord: Set[Name] = _
@@ -46,10 +46,13 @@ class Instrumentation extends MiniPhase { thisPhase =>
4646
ref(defn.Stats_doRecord).appliedTo(key, Literal(Constant(1)))
4747
}
4848

49+
private def ok(using Context) =
50+
!ctx.owner.ownersIterator.exists(_.name.toString.startsWith("Stats"))
51+
4952
override def transformApply(tree: Apply)(using Context): Tree = tree.fun match {
5053
case Select(nu: New, _) =>
5154
cpy.Block(tree)(record(i"alloc/${nu.tpe}", tree) :: Nil, tree)
52-
case ref: RefTree if namesToRecord.contains(ref.name) =>
55+
case ref: RefTree if namesToRecord.contains(ref.name) && ok =>
5356
cpy.Block(tree)(record(i"call/${ref.name}", tree) :: Nil, tree)
5457
case _ =>
5558
tree

0 commit comments

Comments
 (0)