Skip to content

Commit 7199a33

Browse files
committed
Tweaks
1 parent f947236 commit 7199a33

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/src/dotty/tools/dotc/reporting/Profile.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ object Profile:
2828

2929
inline val TastyChunkSize = 50
3030

31+
def chunks(size: Int) = (size + TastyChunkSize - 1) / TastyChunkSize
32+
3133
case class MethodInfo(meth: Symbol, size: Int, span: Span)
3234
@sharable object NoInfo extends MethodInfo(NoSymbol, 0, NoSpan)
3335

3436
class Info(details: Int):
3537
var lineCount: Int = 0
3638
var tokenCount: Int = 0
3739
var tastySize: Int = 0
38-
def complexity: Float = (tastySize/TastyChunkSize).toFloat/lineCount
40+
def complexity: Float = chunks(tastySize).toFloat/lineCount
3941
val leading: Array[MethodInfo] = Array.fill[MethodInfo](details)(NoInfo)
4042

4143
def recordMethodSize(meth: Symbol, size: Int, span: Span): Unit =
@@ -56,7 +58,7 @@ class ActiveProfile(details: Int) extends Profile:
5658

5759
private def curInfo(using Context): Profile.Info =
5860
val unit: CompilationUnit | Null = ctx.compilationUnit
59-
if unit == null then junkInfo else unitProfile(unit)
61+
if unit == null || unit.source.file.isVirtual then junkInfo else unitProfile(unit)
6062

6163
def unitProfile(unit: CompilationUnit): Profile.Info =
6264
pinfo.getOrElseUpdate(unit, new Profile.Info(details))
@@ -98,7 +100,7 @@ class ActiveProfile(details: Int) extends Profile:
98100
else if complexity < 25 then "high "
99101
else "extreme "
100102
report.echo(layout.format(
101-
name, info.lineCount, info.tokenCount, info.tastySize/Profile.TastyChunkSize,
103+
name, info.lineCount, info.tokenCount, Profile.chunks(info.tastySize),
102104
s"${"%6.2f".format(complexity)} $explanation", path))
103105

104106
def safeMax(xs: Array[Int]) = xs.max.max(10).min(50)
@@ -135,6 +137,7 @@ class ActiveProfile(details: Int) extends Profile:
135137
val s = Scanner(meth.source, span.start, methProfile)(using methCtx)
136138
while s.offset < span.end do s.nextToken()
137139
val info = methProfile.unitProfile(unit)
140+
info.lineCount += 1
138141
info.tastySize = size
139142
val file = meth.source.file
140143
val header = s"%-${sourceNameWidth}s %-${methNameWidth}s".format(file.name, meth.name)

0 commit comments

Comments
 (0)