Skip to content

Commit 74b2638

Browse files
smartertgodzik
authored andcommitted
-Yprofile-trace profiles all inline calls (scala#23490)
Previously we only profiled macro expansion, but even non-macro inline calls can have a significant impact on performance (e.g. if we're doing typeclass derivation) and are worth tracking. This does not seem to significantly impact the size of traces in practice. [Cherry-picked 8a14de3]
1 parent d743501 commit 74b2638

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,7 @@ class Inliner(val call: tpd.Tree)(using Context):
11001100

11011101
val evaluatedSplice =
11021102
inContext(quoted.MacroExpansion.context(inlinedFrom)):
1103-
ctx.profiler.onMacroSplice(inlinedFrom.symbol):
1104-
Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext)
1103+
Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext)
11051104
val inlinedNormalizer = new TreeMap {
11061105
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
11071106
case tree @ Inlined(_, Nil, expr) if tree.inlinedFromOuterScope && enclosingInlineds.isEmpty => transform(expr)

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ object Inlines:
101101
* @return An `Inlined` node that refers to the original call and the inlined bindings
102102
* and body that replace it.
103103
*/
104-
def inlineCall(tree: Tree)(using Context): Tree =
104+
def inlineCall(tree: Tree)(using Context): Tree = ctx.profiler.onInlineCall(tree.symbol):
105105
if tree.symbol.denot != SymDenotations.NoDenotation
106106
&& tree.symbol.effectiveOwner == defn.CompiletimeTestingPackage.moduleClass
107107
then

compiler/src/dotty/tools/dotc/profile/Profiler.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ sealed trait Profiler {
117117
protected def beforeImplicitSearch(pt: Type): TracedEventId = TracedEventId.Empty
118118
protected def afterImplicitSearch(event: TracedEventId): Unit = ()
119119

120-
inline def onMacroSplice[T](macroSym: Symbol)(inline body: T): T =
121-
val event = beforeMacroSplice(macroSym)
120+
inline def onInlineCall[T](inlineSym: Symbol)(inline body: T): T =
121+
val event = beforeInlineCall(inlineSym)
122122
try body
123-
finally afterMacroSplice(event)
124-
protected def beforeMacroSplice(macroSym: Symbol): TracedEventId = TracedEventId.Empty
125-
protected def afterMacroSplice(event: TracedEventId): Unit = ()
123+
finally afterInlineCall(event)
124+
protected def beforeInlineCall(inlineSym: Symbol): TracedEventId = TracedEventId.Empty
125+
protected def afterInlineCall(event: TracedEventId): Unit = ()
126126

127127
inline def onCompletion[T](root: Symbol, associatedFile: => AbstractFile)(inline body: T): T =
128128
val (event, completionName) = beforeCompletion(root, associatedFile)
@@ -178,7 +178,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
178178

179179
enum Category:
180180
def name: String = this.toString().toLowerCase()
181-
case Run, Phase, File, TypeCheck, Implicit, Macro, Completion
181+
case Run, Phase, File, TypeCheck, Implicit, Inline, Completion
182182
private [profile] val chromeTrace =
183183
if ctx.settings.YprofileTrace.isDefault
184184
then null
@@ -317,8 +317,8 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
317317
override def beforeImplicitSearch(pt: Type): TracedEventId = traceDurationStart(Category.Implicit, s"?[${symbolName(pt.typeSymbol)}]", colour = "yellow")
318318
override def afterImplicitSearch(event: TracedEventId): Unit = traceDurationEnd(Category.Implicit, event, colour = "yellow")
319319

320-
override def beforeMacroSplice(macroSym: Symbol): TracedEventId = traceDurationStart(Category.Macro, s"«${symbolName(macroSym)}»", colour = "olive")
321-
override def afterMacroSplice(event: TracedEventId): Unit = traceDurationEnd(Category.Macro, event, colour = "olive")
320+
override def beforeInlineCall(inlineSym: Symbol): TracedEventId = traceDurationStart(Category.Inline, s"«${symbolName(inlineSym)}»", colour = "olive")
321+
override def afterInlineCall(event: TracedEventId): Unit = traceDurationEnd(Category.Inline, event, colour = "olive")
322322

323323
override def beforeCompletion(root: Symbol, associatedFile: => AbstractFile): (TracedEventId, String) =
324324
if chromeTrace == null

0 commit comments

Comments
 (0)