Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.12.x' into backport/sbt-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Feb 3, 2020
2 parents 6f7a83c + 31d4d2f commit 5b1bf53
Show file tree
Hide file tree
Showing 17 changed files with 473 additions and 595 deletions.
7 changes: 3 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ val partestDep = scalaDep("org.scala-lang.modules", "scala-par
// Non-Scala dependencies:
val junitDep = "junit" % "junit" % "4.12"
val junitInterfaceDep = "com.novocode" % "junit-interface" % "0.11" % "test"
val scalacheckDep = "org.scalacheck" % "scalacheck_2.12" % "1.13.4" % "test"
val scalacheckDep = "org.scalacheck" % "scalacheck_2.12" % "1.14.3" % "test"
val jolDep = "org.openjdk.jol" % "jol-core" % "0.9"
val asmDep = "org.scala-lang.modules" % "scala-asm" % versionProps("scala-asm.version")
val jlineDep = "jline" % "jline" % versionProps("jline.version")
Expand Down Expand Up @@ -184,6 +184,8 @@ val mimaFilterSettings = Seq {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.immutable.HashMap#HashMapCollision1.foreachEntry"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.util.hashing.MurmurHash3.product2Hash"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.util.hashing.MurmurHash3.emptyMapHash"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.immutable.HashMap$HashMapKeys"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.immutable.HashMap$HashMapValues"),

// Some static forwarder changes detected after a MiMa upgrade.
// e.g. static method apply(java.lang.Object)java.lang.Object in class scala.Symbol does not have a correspondent in current version
Expand Down Expand Up @@ -901,9 +903,6 @@ lazy val scalacheck = project.in(file("test") / "scalacheck")
.settings(
// enable forking to workaround https://github.com/sbt/sbt/issues/4009
fork in Test := true,
// customise framework for early acess to https://github.com/rickynils/scalacheck/pull/388
// TODO remove this when we upgrade scalacheck
testFrameworks := Seq(TestFramework("org.scalacheck.CustomScalaCheckFramework")),
javaOptions in Test += "-Xss1M",
testOptions ++= {
if ((fork in Test).value) Nil
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/DocComments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ trait DocComments { self: Global =>
if (pos == NoPosition) NoPosition
else {
val start1 = pos.start + start
val end1 = pos.end + end
val end1 = pos.start + end
pos withStart start1 withPoint start1 withEnd end1
}

Expand Down
11 changes: 8 additions & 3 deletions src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
}

def staticHandleFromSymbol(sym: Symbol): asm.Handle = {
val owner = if (sym.owner.isModuleClass) sym.owner.linkedClassOfClass else sym.owner
val descriptor = methodBTypeFromMethodType(sym.info, isConstructor = false).descriptor
val ownerBType = classBTypeFromSymbol(owner)
new asm.Handle(asm.Opcodes.H_INVOKESTATIC, ownerBType.internalName, sym.name.encoded, descriptor, /* itf = */ ownerBType.isInterface.get)
val ownerBType = classBTypeFromSymbol(sym.owner)
val rawInternalName = ownerBType.internalName
// object Qux { def foo = 1 } --> we want the handle to be to (static) Qux.foo, not (member) Qux$.foo
val mustUseMirrorClass = !sym.isJava && sym.owner.isModuleClass && !sym.isStaticMember
// ... but we don't know that the mirror class exists! (if there's no companion, the class is synthesized in jvm without a symbol)
val ownerInternalName = if (mustUseMirrorClass) rawInternalName stripSuffix nme.MODULE_SUFFIX_STRING else rawInternalName
val isInterface = sym.owner.linkedClassOfClass.isTraitOrInterface
new asm.Handle(asm.Opcodes.H_INVOKESTATIC, ownerInternalName, sym.name.encoded, descriptor, isInterface)
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/compiler/scala/tools/nsc/util/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,33 @@ package object util {
writer.toString()
}

/** Generate a string using a routine that wants to write on a stream. */
/** Generate a string using a routine that wants to write on a writer. */
def stringFromWriter(writer: PrintWriter => Unit): String = {
val stringWriter = new StringWriter()
val stream = new NewLinePrintWriter(stringWriter)
writer(stream)
stream.close()
stringWriter.toString
}
/** Generate a string using a routine that wants to write on a stream. */
def stringFromStream(stream: OutputStream => Unit): String = {
val utf8 = java.nio.charset.StandardCharsets.UTF_8
val bs = new ByteArrayOutputStream()
val ps = new PrintStream(bs)
val ps = new PrintStream(bs, /*autoflush=*/ false, utf8.name) // use Charset directly in jdk10
stream(ps)
ps.close()
bs.toString()
bs.toString(utf8.name)
}
def stackTraceString(ex: Throwable): String = stringFromWriter(ex printStackTrace _)
def stackTraceString(t: Throwable): String = stringFromWriter(t.printStackTrace(_))

/** A one line string which contains the class of the exception, the
* message if any, and the first non-Predef location in the stack trace
* (to exclude assert, require, etc.)
*/
def stackTraceHeadString(ex: Throwable): String = {
val frame = ex.getStackTrace.dropWhile(_.getClassName contains "Predef") take 1 mkString ""
val msg = ex.getMessage match { case null | "" => "" ; case s => s"""("$s")""" }
val clazz = ex.getClass.getName.split('.').last
def stackTraceHeadString(t: Throwable): String = {
val frame = t.getStackTrace.dropWhile(_.getClassName contains "Predef").take(1).mkString("")
val msg = t.getMessage match { case null | "" => "" ; case s => s"""("$s")""" }
val clazz = t.getClass.getName.split('.').last

s"$clazz$msg @ $frame"
}
Expand Down
15 changes: 15 additions & 0 deletions src/library/scala/collection/immutable/HashMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]

override def par = ParHashMap.fromTrie(this)

/* Override to avoid tuple allocation in foreach */
private[collection] class HashMapKeys extends ImmutableDefaultKeySet {
override def foreach[U](f: A => U) = foreachEntry((key, _) => f(key))
override lazy val hashCode = super.hashCode()
}
override def keySet: immutable.Set[A] = new HashMapKeys

/** The implementation class of the iterable returned by `values`.
*/
private[collection] class HashMapValues extends DefaultValuesIterable {
override def foreach[U](f: B => U) = foreachEntry((_, value) => f(value))
}
override def values: scala.collection.Iterable[B] = new HashMapValues


}

/** $factoryInfo
Expand Down
7 changes: 7 additions & 0 deletions src/library/scala/collection/immutable/TreeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,11 @@ final class TreeMap[A, +B] private (tree: RB.Tree[A, B])(implicit val ordering:
}
}

override def keySet: SortedSet[A] = new DefaultKeySortedSet {
override def foreach[U](f: A => U): Unit = RB.foreachEntry(tree, {(key: A, _: B) => f(key)})
}

override def values: scala.Iterable[B] = new DefaultValuesIterable {
override def foreach[U](f: B => U): Unit = RB.foreachEntry(tree, {(_: A, value: B) => f(value)})
}
}
7 changes: 6 additions & 1 deletion src/library/scala/collection/mutable/ListBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,18 @@ final class ListBuffer[A]
def result: List[A] = toList

/** Converts this buffer to a list. Takes constant time. The buffer is
* copied lazily, the first time it is mutated.
* copied lazily the first time it is mutated.
*/
override def toList: List[A] = {
exported = !isEmpty
start
}

// scala/bug#11869
override def toSeq: collection.Seq[A] = toList
override def toIterable: collection.Iterable[A] = toList
override def toStream: immutable.Stream[A] = toList.toStream // mind the laziness

// New methods in ListBuffer

/** Prepends the elements of this buffer to a given list
Expand Down
41 changes: 6 additions & 35 deletions src/repl/scala/tools/nsc/interpreter/ILoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import PartialFunction.{cond => when}
import interpreter.session._
import StdReplTags._
import scala.tools.asm.ClassReader
import scala.util.Properties.jdkHome
import scala.tools.nsc.util.{ClassPath, stringFromStream}
import scala.reflect.classTag
import scala.reflect.internal.util.{BatchSourceFile, ScalaClassLoader, NoPosition}
import scala.reflect.internal.util.{BatchSourceFile, NoPosition}
import scala.reflect.io.{Directory, File, Path}
import scala.tools.util._
import io.AbstractFile
import scala.concurrent.{Await, Future}
import java.io.BufferedReader
Expand Down Expand Up @@ -278,27 +276,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) extend
}
}

private def findToolsJar() = PathResolver.SupplementalLocations.platformTools

private def addToolsJarToLoader() = {
val cl = findToolsJar() match {
case Some(tools) => ScalaClassLoader.fromURLs(Seq(tools.toURL), intp.classLoader)
case _ => intp.classLoader
}
if (Javap.isAvailable(cl)) {
repldbg(":javap available.")
cl
}
else {
repldbg(":javap unavailable: no tools.jar at " + jdkHome)
intp.classLoader
}
}

protected def newJavap() = JavapClass(addToolsJarToLoader(), new IMain.ReplStrippingWriter(intp), intp)

private lazy val javap = substituteAndLog[Javap]("javap", NoJavap)(newJavap())

// Still todo: modules.
private def typeCommand(line0: String): Result = {
line0.trim match {
Expand Down Expand Up @@ -371,17 +348,11 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) extend
ok && rest.isEmpty
}

private def javapCommand(line: String): Result = {
if (javap == null)
s":javap unavailable, no tools.jar at $jdkHome. Set JDK_HOME."
else if (line == "")
Javap.helpText
else
javap(words(line)) foreach { res =>
if (res.isError) return s"Failed: ${res.value}"
else res.show()
}
}
private def javapCommand(line: String): Result =
Javap(intp)(words(line): _*) foreach { res =>
if (res.isError) return s"${res.value}"
else res.show()
}

private def pathToPhaseWrapper = intp.originalPath("$r") + ".phased.atCurrent"

Expand Down
Loading

0 comments on commit 5b1bf53

Please sign in to comment.