Skip to content

Commit a290a41

Browse files
smartertgodzik
authored andcommitted
-Yprofile-trace properly report macro splicing source
Previously when we had some code like: def userCode: Unit = ... val x = myExpensiveMacro() ... The profiler reported the time spent executing the macro as `«method userCode»` which is misleading. This commit changes it to be reported as `«method myExpensiveMacro»`. This is particularly useful in bottom-up profiling to find which macros we spend the most amount of time in. [Cherry-picked 7f81cc5]
1 parent 4e8c35c commit a290a41

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,9 +1098,10 @@ class Inliner(val call: tpd.Tree)(using Context):
10981098
if suspendable then
10991099
ctx.compilationUnit.suspend() // this throws a SuspendException
11001100

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object Splicer {
5454
inContext(sliceContext) {
5555
val oldContextClassLoader = Thread.currentThread().getContextClassLoader
5656
Thread.currentThread().setContextClassLoader(classLoader)
57-
try ctx.profiler.onMacroSplice(owner){
57+
try {
5858
val interpreter = new SpliceInterpreter(splicePos, classLoader)
5959

6060
// Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree

0 commit comments

Comments
 (0)