Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use a different encoding for constructor:
constructor.enclosingClass.fullName ++ ";init;"
  • Loading branch information
allanrenucci committed Mar 13, 2018
1 parent e4eed7b commit ca2b2d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ class ExtractDependencies extends Phase {
object ExtractDependencies {
def classNameAsString(sym: Symbol)(implicit ctx: Context): String =
sym.fullName.stripModuleClassSuffix.toString

/** Return the enclosing class or the module class if it's a module. */
def enclOrModuleClass(dep: Symbol)(implicit ctx: Context): Symbol =
if (dep.is(ModuleVal)) dep.moduleClass else dep.enclosingClass
}

private case class ClassDependency(from: Symbol, to: Symbol, context: DependencyContext)
Expand Down Expand Up @@ -230,7 +226,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
if (_responsibleForImports == null) {
val tree = ctx.compilationUnit.tpdTree
_responsibleForImports = firstClassOrModule(tree)
if (_responsibleForImports == NoSymbol)
if (!_responsibleForImports.exists)
ctx.warning("""|No class, trait or object is defined in the compilation unit.
|The incremental compiler cannot record the dependency information in such case.
|Some errors like unused import referring to a non-existent class might not be reported.
Expand Down Expand Up @@ -274,24 +270,32 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT

private def addUsedName(name: Name, scope: UseScope)(implicit ctx: Context): Unit = {
val fromClass = resolveDependencySource
if (fromClass ne NoSymbol) {
if (fromClass.exists) {
assert(fromClass.isClass)
addUsedName(fromClass, name, scope)
}
}

/** Mangle a JVM symbol name in a format better suited for internal uses by sbt. */
private def mangledName(sym: Symbol)(implicit ctx: Context): Name = {
def constructorName = sym.enclosingClass.fullName ++ ";init;"

if (sym.isConstructor) constructorName
else sym.name.stripModuleClassSuffix
}

private def addMemberRefDependency(sym: Symbol)(implicit ctx: Context): Unit =
if (!ignoreDependency(sym)) {
val depClass = enclOrModuleClass(sym)
// assert(depClass.isClass, s"$depClass, $sym, ${sym.isClass}")
val enclOrModuleClass = if (sym.is(ModuleVal)) sym.moduleClass else sym.enclosingClass
// assert(enclOrModuleClass.isClass, s"$depClass, $sym"))

if (depClass ne NoSymbol) {
assert(depClass.isClass)
if (enclOrModuleClass.exists) {
assert(enclOrModuleClass.isClass)
val fromClass = resolveDependencySource
if (fromClass ne NoSymbol) {
if (fromClass.exists) {
assert(fromClass.isClass)
_dependencies += ClassDependency(fromClass, depClass, DependencyByMemberRef)
addUsedName(fromClass, sym.name.stripModuleClassSuffix, UseScope.Default)
_dependencies += ClassDependency(fromClass, enclOrModuleClass, DependencyByMemberRef)
addUsedName(fromClass, mangledName(sym), UseScope.Default)
}
}
}
Expand All @@ -308,7 +312,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
}

private def ignoreDependency(sym: Symbol)(implicit ctx: Context) =
sym.eq(NoSymbol) ||
!sym.exists ||
sym.isAnonymousFunction ||
sym.isAnonymousClass ||
sym.is(PackageClass)
Expand Down Expand Up @@ -424,7 +428,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
val traverser = new TypeDependencyTraverser {
def addDependency(symbol: Symbol) =
if (!ignoreDependency(symbol) && symbol.is(Sealed)) {
val usedName = symbol.name.stripModuleClassSuffix
val usedName = mangledName(symbol)
addUsedName(usedName, UseScope.PatMatTarget)
}
}
Expand Down
2 changes: 1 addition & 1 deletion sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class ExtractUsedNamesSpecification {
// The default parent of a class is "AnyRef" which is an alias for "Object"
"AnyRef",
"Object",
"java;lang;Object;init;"
"java.lang.Object;init;"
)

}

0 comments on commit ca2b2d5

Please sign in to comment.