Skip to content

Commit 51ce9bb

Browse files
committed
traverse annots once per definition symbol
1 parent 0a369f4 commit 51ce9bb

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class ExtractSemanticDB extends Phase:
7272
/** The symbol occurrences generated so far, as a set */
7373
private val generated = new mutable.HashSet[SymbolOccurrence]
7474

75+
private val anotatedSymbols = new mutable.HashSet[Symbol]
76+
7577
/** Definitions of this symbol should be excluded from semanticdb */
7678
private def excludeDef(sym: Symbol)(using Context): Boolean =
7779
!sym.exists
@@ -104,13 +106,15 @@ class ExtractSemanticDB extends Phase:
104106
|| sym == defn.Any_typeCast
105107
|| qualifier.exists(excludeQual)
106108

107-
private def traverseAnnotsOf(sym: Symbol)(using Context): Unit =
108-
for annot <- sym.annotations do
109-
if annot.tree.span.exists
110-
&& annot.tree.span.hasLength
111-
annot.tree match
112-
case tree: Typed => () // hack for inline code
113-
case tree => traverse(tree)
109+
private def traverseAnnotsOfDefinition(sym: Symbol)(using Context): Unit =
110+
if (!anotatedSymbols.contains(sym)) then
111+
anotatedSymbols += sym
112+
for annot <- sym.annotations do
113+
if annot.tree.span.exists
114+
&& annot.tree.span.hasLength
115+
annot.tree match
116+
case tree: Typed => () // hack for inline code
117+
case tree => traverse(tree)
114118

115119
override def traverse(tree: Tree)(using Context): Unit =
116120

@@ -125,7 +129,11 @@ class ExtractSemanticDB extends Phase:
125129
else
126130
traverse(tpt)
127131

128-
traverseAnnotsOf(tree.symbol)
132+
tree match
133+
case tree: DefTree if tree.symbol.exists =>
134+
traverseAnnotsOfDefinition(tree.symbol)
135+
case _ =>
136+
()
129137

130138
tree match
131139
case tree: PackageDef =>
@@ -182,6 +190,7 @@ class ExtractSemanticDB extends Phase:
182190
case tree: Template =>
183191
val ctorSym = tree.constr.symbol
184192
if !excludeDef(ctorSym)
193+
traverseAnnotsOfDefinition(ctorSym)
185194
registerDefinition(ctorSym, tree.constr.span, Set.empty)
186195
ctorParams(tree.constr.vparamss, tree.body)(traverseCtorParamTpt(ctorSym, _))
187196
for parent <- tree.parentsOrDerived if parent.span.hasLength do
@@ -568,8 +577,8 @@ class ExtractSemanticDB extends Phase:
568577
vparams <- vparamss
569578
vparam <- vparams
570579
do
571-
traverseAnnotsOf(vparam.symbol)
572580
if !excludeSymbol(vparam.symbol)
581+
traverseAnnotsOfDefinition(vparam.symbol)
573582
val symkinds =
574583
getters.get(vparam.name).fold(SymbolKind.emptySet)(getter =>
575584
if getter.mods.is(Mutable) then SymbolKind.VarSet else SymbolKind.ValSet)

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ object TestConfiguration {
1616
"-Yno-deep-subtypes",
1717
"-Yno-double-bindings",
1818
"-Yforce-sbt-phases",
19+
// "-Ysemanticdb",
1920
"-Xverify-signatures"
2021
)
2122

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
trait Reporter:
2+
def report(m: String): Unit
3+
4+
class Dummy extends Reporter:
5+
def report(m: String) = ()
6+
7+
object ABug {
8+
sealed trait Nat {
9+
inline def ++ : Succ[this.type] = Succ(this)
10+
11+
transparent inline def +(inline that: Nat): Nat =
12+
inline this match {
13+
case Zero => that
14+
case Succ(p) => p + that.++
15+
}
16+
}
17+
18+
case object Zero extends Nat
19+
case class Succ[N <: Nat](p: N) extends Nat
20+
21+
transparent inline def toIntg(inline n: Nat): Int =
22+
inline n match {
23+
case Zero => 0
24+
case Succ(p) => toIntg(p) + 1
25+
}
26+
27+
val j31 = toIntg(Zero.++.++.++ + Zero.++)
28+
}

0 commit comments

Comments
 (0)