Skip to content

Commit

Permalink
Merge pull request #7724 from som-snytt/issue/unusages
Browse files Browse the repository at this point in the history
Unused imports and serial ID
  • Loading branch information
SethTisue committed Feb 13, 2019
2 parents 481a78b + 8485a38 commit f1c1d62
Show file tree
Hide file tree
Showing 56 changed files with 115 additions and 120 deletions.
1 change: 1 addition & 0 deletions build.sbt
Expand Up @@ -152,6 +152,7 @@ lazy val commonSettings = instanceSettings ++ clearSourceAndResourceDirectories
cleanFiles += (target in Compile in doc).value,
fork in run := true,
connectInput in run := true,
//scalacOptions in Compile += "-deprecation",
//scalacOptions in Compile += "-Xlint:-nullary-override,-inaccessible,-nonlocal-return,_",
//scalacOptions ++= Seq("-Xmaxerrs", "5", "-Xmaxwarns", "5"),
scalacOptions in Compile in doc ++= Seq(
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/reflect/macros/compiler/Errors.scala
Expand Up @@ -105,7 +105,7 @@ trait Errors extends Traces {
val verbose = macroDebugVerbose

def check(rtpe: Type, atpe: Type): Boolean = {
def success() = { if (verbose) println(rtpe + " <: " + atpe + "?" + EOL + "true"); true }
def success() = { if (verbose) println(f"$rtpe <: $atpe?%ntrue"); true }
(rtpe, atpe) match {
case _ if rtpe eq atpe => success()
case (TypeRef(_, RepeatedParamClass, rtpe :: Nil), TypeRef(_, RepeatedParamClass, atpe :: Nil)) => check(rtpe, atpe)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/reflect/reify/codegen/GenUtils.scala
Expand Up @@ -42,7 +42,7 @@ trait GenUtils {
def call(fname: String, args: Tree*): Tree =
Apply(termPath(fname), args.toList)

def mirrorSelect(name: String): Tree = termPath(nme.UNIVERSE_PREFIX + name)
def mirrorSelect(name: String): Tree = termPath(nme.UNIVERSE_PREFIX.decoded + name)
def mirrorSelect(name: TermName): Tree = mirrorSelect(name.toString)

def mirrorMirrorSelect(name: TermName): Tree =
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/Global.scala
Expand Up @@ -414,7 +414,7 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
inform("[running phase " + name + " on " + unit + "]")
}

@deprecated
@deprecated("Unused, inlined in applyPhase", since="2.13")
final def withCurrentUnit(unit: CompilationUnit)(task: => Unit): Unit = {
beforeUnit(unit)
if (!cancelled(unit)) {
Expand All @@ -425,6 +425,7 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
}

@inline
@deprecated("Unused, see withCurrentUnit", since="2.13")
final def withCurrentUnitNoLog(unit: CompilationUnit)(task: => Unit): Unit = {
val unit0 = currentUnit
try {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/ast/NodePrinters.scala
Expand Up @@ -205,7 +205,7 @@ abstract class NodePrinters {
else if (trees.tail.isEmpty)
traverse(trees.head)
else {
printLine("", trees.length + " " + what + "s")
printLine("", "" + trees.length + " " + what + "s")
trees foreach traverse
}
}
Expand Down Expand Up @@ -295,7 +295,7 @@ abstract class NodePrinters {
printLine("", "1 parameter list")
ps foreach traverse
case pss =>
printLine("", pss.length + " parameter lists")
printLine("", "" + pss.length + " parameter lists")
pss foreach (ps => traverseList("()", "parameter")(ps))
}
traverse(tpt)
Expand Down
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/ast/TreeGen.scala
Expand Up @@ -17,6 +17,7 @@ import scala.collection.mutable.ListBuffer
import symtab.Flags._
import scala.language.postfixOps
import scala.reflect.internal.util.FreshNameCreator
import scala.reflect.internal.util.ListOfNil

/** XXX to resolve: TreeGen only assumes global is a SymbolTable, but
* TreeDSL at the moment expects a Global. Can we get by with SymbolTable?
Expand Down
Expand Up @@ -481,7 +481,7 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
// phase travel necessary: after flatten, the name includes the name of outer classes.
// if some outer name contains $anon, a non-anon class is considered anon.
if (exitingPickler(innerClassSym.isAnonymousClass || innerClassSym.isAnonymousFunction)) None
else Some(innerClassSym.rawname + innerClassSym.moduleSuffix) // moduleSuffix for module classes
else Some(s"${innerClassSym.rawname}${innerClassSym.moduleSuffix}") // moduleSuffix for module classes
}

Some(NestedInfo(enclosingClass, outerName, innerName, isStaticNestedClass))
Expand Down
69 changes: 31 additions & 38 deletions src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala
Expand Up @@ -36,16 +36,10 @@ object BackendReporting {
def assertionError(message: String): Nothing = throw new AssertionError(message)

implicit class RightBiasedEither[A, B](val v: Either[A, B]) extends AnyVal {
def withFilter(f: B => Boolean)(implicit empty: A): Either[A, B] = v match {
case Left(_) => v
case Right(e) => if (f(e)) v else Left(empty) // scalaz.\/ requires an implicit Monoid m to get m.empty
}
def withFilter(f: B => Boolean)(implicit empty: A): Either[A, B] = v.filterOrElse(f, empty)

/** Get the value, fail with an assertion if this is an error. */
def get: B = {
assert(v.isRight, v.left.get)
v.right.get
}
def get: B = v.fold(a => assertionError(s"$a"), identity)

/**
* Get the right value of an `Either` by throwing a potential error message. Can simplify the
Expand All @@ -56,10 +50,7 @@ object BackendReporting {
* eitherOne.orThrow .... eitherTwo.orThrow ... eitherThree.orThrow
* }
*/
def orThrow: B = v match {
case Left(m) => throw Invalid(m)
case Right(t) => t
}
def orThrow: B = v.fold(a => throw Invalid(a), identity)
}

case class Invalid[A](e: A) extends ControlThrowable
Expand All @@ -73,11 +64,13 @@ object BackendReporting {
def emitWarning(settings: CompilerSettings): Boolean
}

// Method withFilter in RightBiasedEither requires an implicit empty value. Taking the value here
// in scope allows for-comprehensions that desugar into withFilter calls (for example when using a
// tuple de-constructor).
implicit object emptyOptimizerWarning extends OptimizerWarning {
def emitWarning(settings: CompilerSettings): Boolean = false
object OptimizerWarning {
// Method withFilter in RightBiasedEither requires an implicit empty value. Taking the value here
// in scope allows for-comprehensions that desugar into withFilter calls (for example when using a
// tuple de-constructor).
implicit val emptyOptimizerWarning: OptimizerWarning = new OptimizerWarning {
def emitWarning(settings: CompilerSettings): Boolean = false
}
}

sealed trait MissingBytecodeWarning extends OptimizerWarning {
Expand Down Expand Up @@ -116,11 +109,11 @@ object BackendReporting {
}
}

case class ClassNotFound(internalName: InternalName, definedInJavaSource: Boolean) extends MissingBytecodeWarning
case class MethodNotFound(name: String, descriptor: String, ownerInternalNameOrArrayDescriptor: InternalName, missingClass: Option[ClassNotFound]) extends MissingBytecodeWarning {
final case class ClassNotFound(internalName: InternalName, definedInJavaSource: Boolean) extends MissingBytecodeWarning
final case class MethodNotFound(name: String, descriptor: String, ownerInternalNameOrArrayDescriptor: InternalName, missingClass: Option[ClassNotFound]) extends MissingBytecodeWarning {
def isArrayMethod = ownerInternalNameOrArrayDescriptor.charAt(0) == '['
}
case class FieldNotFound(name: String, descriptor: String, ownerInternalName: InternalName, missingClass: Option[ClassNotFound]) extends MissingBytecodeWarning
final case class FieldNotFound(name: String, descriptor: String, ownerInternalName: InternalName, missingClass: Option[ClassNotFound]) extends MissingBytecodeWarning

sealed trait NoClassBTypeInfo extends OptimizerWarning {
override def toString = this match {
Expand All @@ -137,8 +130,8 @@ object BackendReporting {
}
}

case class NoClassBTypeInfoMissingBytecode(cause: MissingBytecodeWarning) extends NoClassBTypeInfo
case class NoClassBTypeInfoClassSymbolInfoFailedSI9111(classFullName: String) extends NoClassBTypeInfo
final case class NoClassBTypeInfoMissingBytecode(cause: MissingBytecodeWarning) extends NoClassBTypeInfo
final case class NoClassBTypeInfoClassSymbolInfoFailedSI9111(classFullName: String) extends NoClassBTypeInfo

/**
* Used in the CallGraph for nodes where an issue occurred determining the callee information.
Expand Down Expand Up @@ -172,9 +165,9 @@ object BackendReporting {
}
}

case class MethodInlineInfoIncomplete(declarationClass: InternalName, name: String, descriptor: String, cause: ClassInlineInfoWarning) extends CalleeInfoWarning
case class MethodInlineInfoMissing(declarationClass: InternalName, name: String, descriptor: String, cause: Option[ClassInlineInfoWarning]) extends CalleeInfoWarning
case class MethodInlineInfoError(declarationClass: InternalName, name: String, descriptor: String, cause: NoClassBTypeInfo) extends CalleeInfoWarning
final case class MethodInlineInfoIncomplete(declarationClass: InternalName, name: String, descriptor: String, cause: ClassInlineInfoWarning) extends CalleeInfoWarning
final case class MethodInlineInfoMissing(declarationClass: InternalName, name: String, descriptor: String, cause: Option[ClassInlineInfoWarning]) extends CalleeInfoWarning
final case class MethodInlineInfoError(declarationClass: InternalName, name: String, descriptor: String, cause: NoClassBTypeInfo) extends CalleeInfoWarning

sealed trait CannotInlineWarning extends OptimizerWarning {
def calleeDeclarationClass: InternalName
Expand Down Expand Up @@ -226,22 +219,22 @@ object BackendReporting {
annotatedInline && settings.optWarningEmitAtInlineFailed
}
}
case class CalleeNotFinal(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean) extends CannotInlineWarning
case class IllegalAccessInstructions(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
final case class CalleeNotFinal(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean) extends CannotInlineWarning
final case class IllegalAccessInstructions(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
callsiteClass: InternalName, instructions: List[AbstractInsnNode]) extends CannotInlineWarning
case class IllegalAccessCheckFailed(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
final case class IllegalAccessCheckFailed(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
callsiteClass: InternalName, instruction: AbstractInsnNode, cause: OptimizerWarning) extends CannotInlineWarning
case class MethodWithHandlerCalledOnNonEmptyStack(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
final case class MethodWithHandlerCalledOnNonEmptyStack(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
callsiteClass: InternalName, callsiteName: String, callsiteDesc: String) extends CannotInlineWarning
case class SynchronizedMethod(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean) extends CannotInlineWarning
case class StrictfpMismatch(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
final case class SynchronizedMethod(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean) extends CannotInlineWarning
final case class StrictfpMismatch(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
callsiteClass: InternalName, callsiteName: String, callsiteDesc: String) extends CannotInlineWarning
case class ResultingMethodTooLarge(calleeDeclarationClass: InternalName, name: String, descriptor: String, annotatedInline: Boolean,
callsiteClass: InternalName, callsiteName: String, callsiteDesc: String) extends CannotInlineWarning

// TODO: this should be a subtype of CannotInlineWarning
// but at the place where it's created (in findIllegalAccess) we don't have the necessary data (calleeName, calleeDescriptor).
case object UnknownInvokeDynamicInstruction extends OptimizerWarning {
final case object UnknownInvokeDynamicInstruction extends OptimizerWarning {
override def toString = "The callee contains an InvokeDynamic instruction with an unknown bootstrap method (not a LambdaMetaFactory)."
def emitWarning(settings: CompilerSettings): Boolean = settings.optWarningEmitAnyInlineFailed
}
Expand All @@ -265,8 +258,8 @@ object BackendReporting {
s"The closure body invocation cannot be rewritten because the target method is not accessible in class $callsiteClass."
}
}
case class RewriteClosureAccessCheckFailed(pos: Position, cause: OptimizerWarning) extends RewriteClosureApplyToClosureBodyFailed
case class RewriteClosureIllegalAccess(pos: Position, callsiteClass: InternalName) extends RewriteClosureApplyToClosureBodyFailed
final case class RewriteClosureAccessCheckFailed(pos: Position, cause: OptimizerWarning) extends RewriteClosureApplyToClosureBodyFailed
final case class RewriteClosureIllegalAccess(pos: Position, callsiteClass: InternalName) extends RewriteClosureApplyToClosureBodyFailed

/**
* Used in the InlineInfo of a ClassBType, when some issue occurred obtaining the inline information.
Expand Down Expand Up @@ -294,8 +287,8 @@ object BackendReporting {
}
}

case class NoInlineInfoAttribute(internalName: InternalName) extends ClassInlineInfoWarning
case class ClassSymbolInfoFailureSI9111(classFullName: String) extends ClassInlineInfoWarning
case class ClassNotFoundWhenBuildingInlineInfoFromSymbol(missingClass: ClassNotFound) extends ClassInlineInfoWarning
case class UnknownScalaInlineInfoVersion(internalName: InternalName, version: Int) extends ClassInlineInfoWarning
final case class NoInlineInfoAttribute(internalName: InternalName) extends ClassInlineInfoWarning
final case class ClassSymbolInfoFailureSI9111(classFullName: String) extends ClassInlineInfoWarning
final case class ClassNotFoundWhenBuildingInlineInfoFromSymbol(missingClass: ClassNotFound) extends ClassInlineInfoWarning
final case class UnknownScalaInlineInfoVersion(internalName: InternalName, version: Int) extends ClassInlineInfoWarning
}
Expand Up @@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap
import scala.annotation.{switch, tailrec}
import scala.collection.JavaConverters._
import scala.collection.immutable.BitSet
import scala.collection.immutable.ArraySeq.unsafeWrapArray
import scala.collection.mutable
import scala.reflect.internal.util.Position
import scala.tools.asm
Expand Down Expand Up @@ -139,11 +140,11 @@ abstract class BackendUtils extends PerRunInit {
}
for ((label, i) <- initialLabels.iterator.zipWithIndex) {
mv.visitLabel(label)
emitLambdaDeserializeIndy(groups(i))
emitLambdaDeserializeIndy(unsafeWrapArray(groups(i)))
mv.visitInsn(ARETURN)
}
mv.visitLabel(terminalLabel)
emitLambdaDeserializeIndy(groups(numGroups - 1))
emitLambdaDeserializeIndy(unsafeWrapArray(groups(numGroups - 1)))
mv.visitInsn(ARETURN)
}

Expand Down
Expand Up @@ -25,7 +25,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi

protected def emptyFiles: Array[AbstractFile] = Array.empty
protected def getSubDir(packageDirName: String): Option[AbstractFile] =
Option(AbstractFileClassLoader.lookupPath(dir)(packageDirName.split('/'), directory = true))
Option(AbstractFileClassLoader.lookupPath(dir)(packageDirName.split('/').toIndexedSeq, directory = true))
protected def listChildren(dir: AbstractFile, filter: Option[AbstractFile => Boolean] = None): Array[F] = filter match {
case Some(f) => dir.iterator.filter(f).toArray
case _ => dir.toArray
Expand All @@ -41,7 +41,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi

def findClassFile(className: String): Option[AbstractFile] = {
val relativePath = FileUtils.dirPath(className) + ".class"
Option(AbstractFileClassLoader.lookupPath(dir)(relativePath split '/', directory = false))
Option(AbstractFileClassLoader.lookupPath(dir)(relativePath.split('/').toIndexedSeq, directory = false))
}

private[nsc] def classes(inPackage: String): Seq[ClassFileEntry] = files(inPackage)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/fsc/CompileServer.scala
Expand Up @@ -84,7 +84,7 @@ class StandardCompileServer(fixPort: Int = 0) extends SocketServer(fixPort) {
val input = in.readLine()

def fscError(msg: String): Unit = out println (
FakePos("fsc") + msg + "\n fsc -help gives more information"
"" + FakePos("fsc") + msg + "\n fsc -help gives more information"
)
if (input == null || password != guessedPassword)
return
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
Expand Up @@ -53,7 +53,7 @@ abstract class BrowsingLoaders extends GlobalSymbolLoaders {
val memberSourceFile = member.sourceFile
if (memberSourceFile != null) {
if (existingSourceFile != memberSourceFile)
error(member+"is defined twice,"+
error(""+member+"is defined twice,"+
"\n in "+existingSourceFile+
"\n and also in "+memberSourceFile)
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/symtab/SymbolTrackers.scala
Expand Up @@ -138,7 +138,7 @@ trait SymbolTrackers {
val s = sym.defString take 240
if (s.length == 240) s + "..." else s
}
else sym + changedOwnerString + flagSummaryString
else "" + sym + changedOwnerString + flagSummaryString
)

def flatten = children.foldLeft(Set(root))(_ ++ _.flatten)
Expand Down
Expand Up @@ -619,7 +619,7 @@ abstract class ClassfileParser {
* If symbol 1 gets completed (e.g. because the compiled source mentions `A$B`, not `A#B`), the
* ClassfileParser for 1 executes, and clazz.owner is the package.
*/
assert(params.head.tpe.typeSymbol == clazz.owner || clazz.owner.hasPackageFlag, params.head.tpe.typeSymbol + ": " + clazz.owner)
assert(params.head.tpe.typeSymbol == clazz.owner || clazz.owner.hasPackageFlag, "" + params.head.tpe.typeSymbol + ": " + clazz.owner)
removedOuterParameter = true
params.tail
case _ =>
Expand Down Expand Up @@ -907,6 +907,7 @@ abstract class ClassfileParser {
parseExceptions(attrLen)

case tpnme.SourceFileATTR =>
/*
if (forInteractive) {
// opt: disable this code in the batch compiler for performance reasons.
// it appears to be looking for the .java source file mentioned in this attribute
Expand All @@ -927,6 +928,8 @@ abstract class ClassfileParser {
}
srcfile0 = settings.outputDirs.srcFilesFor(in.file, srcpath).find(_.exists)
} else in.skip(attrLen)
*/
in.skip(attrLen)

case tpnme.CodeATTR =>
if (sym.owner.isInterface) {
Expand Down

0 comments on commit f1c1d62

Please sign in to comment.