Skip to content

Commit 2db0047

Browse files
committed
Use Symbol instead of String for usedNames cache's key
1 parent 01d35ff commit 2db0047

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ExtractDependencies extends Phase {
7575
if (ctx.sbtCallback != null) {
7676
extractDeps.usedNames.foreach {
7777
case (clazz, usedNames) =>
78-
val className = clazz
78+
val className = classNameAsString(clazz)
7979
usedNames.names.foreach {
8080
case (usedName, scopes) =>
8181
ctx.sbtCallback.usedName(className, usedName.toString, scopes)
@@ -187,13 +187,13 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
187187
import tpd._
188188
import ExtractDependencies._
189189

190-
private[this] val _usedNames = new mutable.HashMap[String, UsedNamesInClass]
190+
private[this] val _usedNames = new mutable.HashMap[Symbol, UsedNamesInClass]
191191
private[this] val _dependencies = new mutable.HashSet[ClassDependency]
192192

193193
/** The names used in this class, this does not include names which are only
194194
* defined and not referenced.
195195
*/
196-
def usedNames: collection.Map[String, UsedNamesInClass] = _usedNames
196+
def usedNames: collection.Map[Symbol, UsedNamesInClass] = _usedNames
197197

198198
/** The set of class dependencies from this compilation unit.
199199
*/
@@ -242,12 +242,17 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
242242
if (source.isEffectiveRoot) responsibleForImports else source
243243
}
244244

245-
private def addUsedName(enclosingSym: Symbol, name: Name, scope: UseScope)(implicit ctx: Context) = {
246-
val enclosingName =
247-
if (enclosingSym == defn.RootClass) classNameAsString(responsibleForImports)
248-
else classNameAsString(enclosingSym)
249-
val nameUsed = _usedNames.getOrElseUpdate(enclosingName, new UsedNamesInClass)
250-
nameUsed.update(name, scope)
245+
private def addUsedName(fromClass: Symbol, name: Name, scope: UseScope): Unit = {
246+
val usedName = _usedNames.getOrElseUpdate(fromClass, new UsedNamesInClass)
247+
usedName.update(name, scope)
248+
}
249+
250+
private def addUsedName(name: Name, scope: UseScope)(implicit ctx: Context): Unit = {
251+
val fromClass = resolveDependencySource
252+
if (fromClass ne NoSymbol) {
253+
assert(fromClass.isClass)
254+
addUsedName(fromClass, name, scope)
255+
}
251256
}
252257

253258
private def addDependency(sym: Symbol)(implicit ctx: Context): Unit =
@@ -298,7 +303,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
298303
case Thicket(Ident(name) :: Ident(rename) :: Nil) =>
299304
addImported(name)
300305
if (rename ne nme.WILDCARD) {
301-
addUsedName(resolveDependencySource, rename, UseScope.Default)
306+
addUsedName(rename, UseScope.Default)
302307
}
303308
case _ =>
304309
}
@@ -389,10 +394,9 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
389394
val traverser = new TypeDependencyTraverser {
390395
def addDependency(symbol: Symbol) =
391396
if (!ignoreDependency(symbol) && symbol.is(Sealed)) {
392-
val enclosingSym = resolveDependencySource
393397
val usedName = symbol.name.stripModuleClassSuffix
394-
addUsedName(enclosingSym, usedName, UseScope.Default)
395-
addUsedName(enclosingSym, usedName, UseScope.PatMatTarget)
398+
addUsedName(usedName, UseScope.Default)
399+
addUsedName(usedName, UseScope.PatMatTarget)
396400
}
397401
}
398402
traverser.traverse(tpe)

0 commit comments

Comments
 (0)