Skip to content

Commit

Permalink
Avoid slow path for associated file more often
Browse files Browse the repository at this point in the history
Also fix a bug in fullName with encoded names.
  • Loading branch information
retronym committed Apr 23, 2020
1 parent 0fcb33d commit b645682
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
val newResult = findOnPreviousCompilationProducts(fqn)
.map(f => (f, true))
.orElse(findOnClassPath(fqn).map(f => (f, false)))

newResult.foreach(res => fqnsToAssociatedFiles.put(fqn, res))
newResult
}
Expand Down Expand Up @@ -220,18 +221,18 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
def loop(size: Int, sym: Symbol): Unit = {
val symName = sym.name
// Use of encoded to produce correct paths for names that have symbols
val encodedName = symName.encoded
val encodedName = symName.encode
val nSize = encodedName.length - (if (symName.endsWith(nme.LOCAL_SUFFIX_STRING)) 1 else 0)
if (sym.isRoot || sym.isRootPackage || sym == NoSymbol || sym.owner.isEffectiveRoot) {
val capacity = size + nSize
b = new java.lang.StringBuffer(capacity)
b.append(chrs, symName.start, nSize)
b.append(chrs, encodedName.start, nSize)
} else {
val next = if (sym.owner.isPackageObjectClass) sym.owner else sym.effectiveOwner.enclClass
loop(size + nSize + 1, next)
// Addition to normal `fullName` to produce correct names for nested non-local classes
if (sym.isNestedClass) b.append(nme.MODULE_SUFFIX_STRING) else b.append(separator)
b.append(chrs, symName.start, nSize)
b.append(chrs, encodedName.start, nSize)
}
()
}
Expand Down
16 changes: 10 additions & 6 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
val targetSymbol = dep.to
val onSource = targetSymbol.sourceFile
if (onSource == null) {
// Ignore packages right away as they don't map to a class file/jar
if (targetSymbol.hasFlag(scala.tools.nsc.symtab.Flags.PACKAGE)) ()
// Ignore `Any` which by default has no `associatedFile`
else if (targetSymbol == definitions.AnyClass) ()
else {
classFile(targetSymbol) match {
val noByteCode = (
// Ignore packages right away as they don't map to a class file/jar
targetSymbol.hasFlag(scala.tools.nsc.symtab.Flags.PACKAGE) ||
// Seen in the wild: an Ident as the original of a TypeTree from a synthetic case accessor was symbol-less
targetSymbol == NoSymbol ||
// Also ignore magic symbols that don't have bytecode like Any/Nothing/Singleton/<byname>/<repeated>/...
isSyntheticCoreClass(targetSymbol)
)
if (!noByteCode) {
classFile(targetSymbol.initialize) match {
case Some((at, binaryClassName)) =>
// Associated file is set, so we know which classpath entry it came from
processExternalDependency(binaryClassName, at)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,9 @@ trait GlobalHelpers { self: Compat =>
|Some errors like unused import referring to a non-existent class might not be reported.
""".stripMargin
}

final def isSyntheticCoreClass(sym: Symbol): Boolean = {
syntheticCoreClassSet.contains(sym)
}
private val syntheticCoreClassSet = definitions.syntheticCoreClasses.toSet[Symbol]
}

0 comments on commit b645682

Please sign in to comment.