diff options
Diffstat (limited to 'src')
16 files changed, 151 insertions, 102 deletions
diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl index 7acb3632d2..9862ea7987 100755 --- a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl +++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl @@ -109,9 +109,6 @@ if [[ -n "$cygwin" ]]; then JAVA_HOME="$(cygpath --$format "$JAVA_HOME")" fi TOOL_CLASSPATH="$(cygpath --path --$format "$TOOL_CLASSPATH")" -elif [[ -n "$mingw" ]]; then - SCALA_HOME="$(cmd //c echo "$SCALA_HOME")" - TOOL_CLASSPATH="$(cmd //c echo "$TOOL_CLASSPATH")" fi if [[ -n "$cygwin$mingw" ]]; then @@ -131,23 +128,6 @@ fi declare -a java_args declare -a scala_args -# default to the boot classpath for speed, except on cygwin/mingw because -# JLine on Windows requires a custom DLL to be loaded. -unset usebootcp -if [[ -z "$cygwin$mingw" ]]; then - usebootcp="true" -fi - -# If using the boot classpath, also pass an empty classpath -# to java to suppress "." from materializing. -classpathArgs () { - if [[ -n $usebootcp ]]; then - echo "-Xbootclasspath/a:$TOOL_CLASSPATH -classpath \"\"" - else - echo "-classpath $TOOL_CLASSPATH" - fi -} - # SI-8358, SI-8368 -- the default should really be false, # but I don't want to flip the default during 2.11's RC cycle OVERRIDE_USEJAVACP="-Dscala.usejavacp=true" @@ -200,6 +180,23 @@ if [[ -z "$JAVACMD" && -n "$JAVA_HOME" && -x "$JAVA_HOME/bin/java" ]]; then JAVACMD="$JAVA_HOME/bin/java" fi +declare -a classpath_args + +# default to the boot classpath for speed, except on cygwin/mingw because +# JLine on Windows requires a custom DLL to be loaded. +unset usebootcp +if [[ -z "$cygwin$mingw" ]]; then + usebootcp="true" +fi + +# If using the boot classpath, also pass an empty classpath +# to java to suppress "." from materializing. +if [[ -n $usebootcp ]]; then + classpath_args=("-Xbootclasspath/a:$TOOL_CLASSPATH" -classpath "\"\"") +else + classpath_args=(-classpath "$TOOL_CLASSPATH") +fi + # note that variables which may intentionally be empty must not # be quoted: otherwise an empty string will appear as a command line # argument, and java will think that is the program to run. @@ -207,7 +204,7 @@ execCommand \ "${JAVACMD:=java}" \ $JAVA_OPTS \ "${java_args[@@]}" \ - $(classpathArgs) \ + "${classpath_args[@@]}" \ -Dscala.home="$SCALA_HOME" \ $OVERRIDE_USEJAVACP \ "$EMACS_OPT" \ diff --git a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala index 743bbe53bd..02356580cc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala @@ -266,7 +266,6 @@ abstract class TreeCheckers extends Analyzer { if (tree ne typed) treesDiffer(tree, typed) - tree } diff --git a/src/library/scala/collection/SetLike.scala b/src/library/scala/collection/SetLike.scala index 3e549f72cd..f8ac1d754d 100644 --- a/src/library/scala/collection/SetLike.scala +++ b/src/library/scala/collection/SetLike.scala @@ -107,22 +107,36 @@ self => */ def + (elem: A): This - /** Creates a new $coll with additional elements. + /** Creates a new $coll with additional elements, omitting duplicates. * - * This method takes two or more elements to be added. Another overloaded - * variant of this method handles the case where a single element is added. + * This method takes two or more elements to be added. Elements that already exist in the $coll will + * not be added. Another overloaded variant of this method handles the case where a single element is added. + * + * Example: + * {{{ + * scala> val a = Set(1, 3) + 2 + 3 + * a: scala.collection.immutable.Set[Int] = Set(1, 3, 2) + * }}} * * @param elem1 the first element to add. * @param elem2 the second element to add. * @param elems the remaining elements to add. - * @return a new $coll with the given elements added. + * @return a new $coll with the given elements added, omitting duplicates. */ def + (elem1: A, elem2: A, elems: A*): This = this + elem1 + elem2 ++ elems - /** Creates a new $coll by adding all elements contained in another collection to this $coll. + /** Creates a new $coll by adding all elements contained in another collection to this $coll, omitting duplicates. + * + * This method takes a collection of elements and adds all elements, omitting duplicates, into $coll. + * + * Example: + * {{{ + * scala> val a = Set(1, 2) ++ Set(2, "a") + * a: scala.collection.immutable.Set[Any] = Set(1, 2, a) + * }}} * - * @param elems the collection containing the added elements. - * @return a new $coll with the given elements added. + * @param elems the collection containing the elements to add. + * @return a new $coll with the given elements added, omitting duplicates. */ def ++ (elems: GenTraversableOnce[A]): This = (repr /: elems.seq)(_ + _) @@ -171,7 +185,7 @@ self => * * @return the iterator. */ - def subsets: Iterator[This] = new AbstractIterator[This] { + def subsets(): Iterator[This] = new AbstractIterator[This] { private val elms = self.toIndexedSeq private var len = 0 private var itr: Iterator[This] = Iterator.empty diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala index fccc1d81b9..bcfea7a463 100644 --- a/src/library/scala/collection/concurrent/TrieMap.scala +++ b/src/library/scala/collection/concurrent/TrieMap.scala @@ -873,6 +873,44 @@ extends scala.collection.concurrent.Map[K, V] insertifhc(k, hc, v, INode.KEY_ABSENT) } + // TODO once computeIfAbsent is added to concurrent.Map, + // move the comment there and tweak the 'at most once' part + /** If the specified key is not already in the map, computes its value using + * the given thunk `op` and enters it into the map. + * + * Since concurrent maps cannot contain `null` for keys or values, + * a `NullPointerException` is thrown if the thunk `op` + * returns `null`. + * + * If the specified mapping function throws an exception, + * that exception is rethrown. + * + * Note: This method will invoke op at most once. + * However, `op` may be invoked without the result being added to the map if + * a concurrent process is also trying to add a value corresponding to the + * same key `k`. + * + * @param k the key to modify + * @param op the expression that computes the value + * @return the newly added value + */ + override def getOrElseUpdate(k: K, op: =>V): V = { + val oldv = lookup(k) + if (oldv != null) oldv.asInstanceOf[V] + else { + val v = op + if (v == null) { + throw new NullPointerException("Concurrent TrieMap values cannot be null.") + } else { + val hc = computeHash(k) + insertifhc(k, hc, v, INode.KEY_ABSENT) match { + case Some(oldv) => oldv + case None => v + } + } + } + } + def remove(k: K, v: V): Boolean = { val hc = computeHash(k) removehc(k, v, hc).nonEmpty diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala index 78150b5e88..e92d48cfeb 100644 --- a/src/library/scala/collection/mutable/BitSet.scala +++ b/src/library/scala/collection/mutable/BitSet.scala @@ -121,8 +121,10 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def &= (other: BitSet): this.type = { - ensureCapacity(other.nwords - 1) - for (i <- 0 until other.nwords) + // Different from other operations: no need to ensure capacity because + // anything beyond the capacity is 0. Since we use other.word which is 0 + // off the end, we also don't need to make sure we stay in bounds there. + for (i <- 0 until nwords) elems(i) = elems(i) & other.word(i) this } diff --git a/src/library/scala/collection/mutable/MapLike.scala b/src/library/scala/collection/mutable/MapLike.scala index af28df1b88..44af886cf5 100644 --- a/src/library/scala/collection/mutable/MapLike.scala +++ b/src/library/scala/collection/mutable/MapLike.scala @@ -178,6 +178,10 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]] * * Otherwise, computes value from given expression `op`, stores with key * in map and returns that value. + * + * Concurrent map implementations may evaluate the expression `op` + * multiple times, or may evaluate `op` without inserting the result. + * * @param key the key to test * @param op the computation yielding the value to associate with `key`, if * `key` is previously unbound. diff --git a/src/library/scala/reflect/ClassTag.scala b/src/library/scala/reflect/ClassTag.scala index 2f4aa9cb84..9dd96183da 100644 --- a/src/library/scala/reflect/ClassTag.scala +++ b/src/library/scala/reflect/ClassTag.scala @@ -69,22 +69,22 @@ trait ClassTag[T] extends ClassManifestDeprecatedApis[T] with Equals with Serial * `SomeExtractor(...)` is turned into `ct(SomeExtractor(...))` if `T` in `SomeExtractor.unapply(x: T)` * is uncheckable, but we have an instance of `ClassTag[T]`. */ - def unapply(x: Any): Option[T] = x match { - case null => None - case b: Byte => unapply(b) - case s: Short => unapply(s) - case c: Char => unapply(c) - case i: Int => unapply(i) - case l: Long => unapply(l) - case f: Float => unapply(f) - case d: Double => unapply(d) - case b: Boolean => unapply(b) - case u: Unit => unapply(u) - case a: Any => unapplyImpl(a) - } + def unapply(x: Any): Option[T] = + if (null != x && ( + (runtimeClass.isInstance(x)) + || (x.isInstanceOf[Byte] && runtimeClass.isAssignableFrom(classOf[Byte])) + || (x.isInstanceOf[Short] && runtimeClass.isAssignableFrom(classOf[Short])) + || (x.isInstanceOf[Char] && runtimeClass.isAssignableFrom(classOf[Char])) + || (x.isInstanceOf[Int] && runtimeClass.isAssignableFrom(classOf[Int])) + || (x.isInstanceOf[Long] && runtimeClass.isAssignableFrom(classOf[Long])) + || (x.isInstanceOf[Float] && runtimeClass.isAssignableFrom(classOf[Float])) + || (x.isInstanceOf[Double] && runtimeClass.isAssignableFrom(classOf[Double])) + || (x.isInstanceOf[Boolean] && runtimeClass.isAssignableFrom(classOf[Boolean])) + || (x.isInstanceOf[Unit] && runtimeClass.isAssignableFrom(classOf[Unit]))) + ) Some(x.asInstanceOf[T]) + else None - // TODO: Inline the bodies of these into the Any-accepting unapply overload above and delete them. - // This cannot be done until at least 2.12.0 for reasons of binary compatibility + // TODO: deprecate overloads in 2.12.0, remove in 2.13.0 def unapply(x: Byte) : Option[T] = unapplyImpl(x, classOf[Byte]) def unapply(x: Short) : Option[T] = unapplyImpl(x, classOf[Short]) def unapply(x: Char) : Option[T] = unapplyImpl(x, classOf[Char]) @@ -94,11 +94,10 @@ trait ClassTag[T] extends ClassManifestDeprecatedApis[T] with Equals with Serial def unapply(x: Double) : Option[T] = unapplyImpl(x, classOf[Double]) def unapply(x: Boolean) : Option[T] = unapplyImpl(x, classOf[Boolean]) def unapply(x: Unit) : Option[T] = unapplyImpl(x, classOf[Unit]) - - private[this] def unapplyImpl(x: Any, alternative: jClass[_] = null): Option[T] = { - val conforms = runtimeClass.isAssignableFrom(x.getClass) || (alternative != null && runtimeClass.isAssignableFrom(alternative)) - if (conforms) Some(x.asInstanceOf[T]) else None - } + + private[this] def unapplyImpl(x: Any, primitiveCls: java.lang.Class[_]): Option[T] = + if (runtimeClass.isInstance(x) || runtimeClass.isAssignableFrom(primitiveCls)) Some(x.asInstanceOf[T]) + else None // case class accessories override def canEqual(x: Any) = x.isInstanceOf[ClassTag[_]] diff --git a/src/library/scala/util/Random.scala b/src/library/scala/util/Random.scala index 8d68c5be38..2d38c9d4a0 100644 --- a/src/library/scala/util/Random.scala +++ b/src/library/scala/util/Random.scala @@ -121,15 +121,21 @@ class Random(val self: java.util.Random) extends AnyRef with Serializable { (bf(xs) ++= buf).result() } + @deprecated("Preserved for backwards binary compatibility. To remove in 2.12.x.", "2.11.6") + final def `scala$util$Random$$isAlphaNum$1`(c: Char) = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') + /** Returns a Stream of pseudorandomly chosen alphanumeric characters, * equally chosen from A-Z, a-z, and 0-9. * * @since 2.8 */ def alphanumeric: Stream[Char] = { - def isAlphaNum(c: Char) = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') + def nextAlphaNum: Char = { + val chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + chars charAt (self nextInt chars.length) + } - Stream continually nextPrintableChar filter isAlphaNum + Stream continually nextAlphaNum } } diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index ce36f7efa3..8f114caac0 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -1976,13 +1976,13 @@ trait Types * usage scenario. */ private var relativeInfoCache: Type = _ - private var memberInfoCache: Type = _ + private var relativeInfoPeriod: Period = NoPeriod - private[Types] def relativeInfo = { - val memberInfo = pre.memberInfo(sym) - if (relativeInfoCache == null || (memberInfo ne memberInfoCache)) { - memberInfoCache = memberInfo + private[Types] def relativeInfo = /*trace(s"relativeInfo(${safeToString}})")*/{ + if (relativeInfoPeriod != currentPeriod) { + val memberInfo = pre.memberInfo(sym) relativeInfoCache = transformInfo(memberInfo) + relativeInfoPeriod = currentPeriod } relativeInfoCache } diff --git a/src/scaladoc/scala/tools/nsc/doc/Universe.scala b/src/scaladoc/scala/tools/nsc/doc/Universe.scala index 11520c810e..edf5112d7b 100644 --- a/src/scaladoc/scala/tools/nsc/doc/Universe.scala +++ b/src/scaladoc/scala/tools/nsc/doc/Universe.scala @@ -5,6 +5,8 @@ package scala.tools.nsc.doc +import scala.tools.nsc.doc.html.page.diagram.DotRunner + /** * Class to hold common dependencies across Scaladoc classes. * @author Pedro Furlanetto @@ -13,4 +15,5 @@ package scala.tools.nsc.doc trait Universe { def settings: Settings def rootPackage: model.Package + def dotRunner: DotRunner } diff --git a/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala b/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala index a0dd154d2e..61ab18d42d 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala @@ -13,8 +13,6 @@ import io.{ Streamable, Directory } import scala.collection._ import page.diagram._ -import html.page.diagram.DiagramGenerator - /** A class that can generate Scaladoc sites to some fixed root folder. * @author David Bernard * @author Gilles Dubochet */ @@ -121,28 +119,27 @@ class HtmlFactory(val universe: doc.Universe, index: doc.Index) { finally out.close() } - DiagramGenerator.initialize(universe.settings) - libResources foreach (s => copyResource("lib/" + s)) new page.Index(universe, index) writeFor this new page.IndexScript(universe, index) writeFor this - - writeTemplates(_ writeFor this) - - for (letter <- index.firstLetterIndex) { - new html.page.ReferenceIndex(letter._1, index, universe) writeFor this + try { + writeTemplates(_ writeFor this) + for (letter <- index.firstLetterIndex) { + new html.page.ReferenceIndex(letter._1, index, universe) writeFor this + } + } finally { + DiagramStats.printStats(universe.settings) + universe.dotRunner.cleanup() } - - DiagramGenerator.cleanup() } def writeTemplates(writeForThis: HtmlPage => Unit) { val written = mutable.HashSet.empty[DocTemplateEntity] - val diagramGenerator: DiagramGenerator = new DotDiagramGenerator(universe.settings) def writeTemplate(tpl: DocTemplateEntity) { if (!(written contains tpl)) { + val diagramGenerator: DiagramGenerator = new DotDiagramGenerator(universe.settings, universe.dotRunner) writeForThis(new page.Template(universe, diagramGenerator, tpl)) written += tpl tpl.templates collect { case d: DocTemplateEntity => d } map writeTemplate diff --git a/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala b/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala index 3738e79ffe..ce75749859 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala @@ -227,6 +227,18 @@ abstract class HtmlPage extends Page { thisPage => <img src={ relativeLinkTo(List("permalink.png", "lib")) } /> </a> </span> + + def docEntityKindToCompanionTitle(ety: DocTemplateEntity, baseString: String = "See companion") = + ety.companion match{ + case Some(companion) => + s"$baseString${ + if(companion.isObject) " object" + else if(companion.isTrait) " trait" + else if(companion.isClass) " class" + else "" + }" + case None => baseString + } def companionAndPackage(tpl: DocTemplateEntity): Elem = <span class="morelinks">{ @@ -238,7 +250,7 @@ abstract class HtmlPage extends Page { thisPage => else s"class ${companionTpl.name}" <div> Related Docs: - <a href={relativeLinkTo(tpl.companion.get)} title="See companion">{objClassTrait}</a> + <a href={relativeLinkTo(tpl.companion.get)} title={docEntityKindToCompanionTitle(tpl)}>{objClassTrait}</a> | {templateToHtml(tpl.inTemplate, s"package ${tpl.inTemplate.name}")} </div> case None => diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala index eda52c5fbf..e10c54a414 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala @@ -89,7 +89,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp val templateName = if (tpl.isRootPackage) "root package" else tpl.name val displayName = tpl.companion match { case Some(companion) if (companion.visibility.isPublic && companion.inSource != None) => - <a href={relativeLinkTo(companion)} title="Go to companion">{ templateName }</a> + <a href={relativeLinkTo(companion)} title={docEntityKindToCompanionTitle(tpl)}>{ templateName }</a> case _ => templateName } @@ -105,7 +105,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp { tpl.companion match { case Some(companion) if (companion.visibility.isPublic && companion.inSource != None) => - <a href={relativeLinkTo(companion)} title="Go to companion"><img src={ relativeLinkTo(List(docEntityKindToBigImage(tpl), "lib")) }/></a> + <a href={relativeLinkTo(companion)} title={docEntityKindToCompanionTitle(tpl)}><img src={ relativeLinkTo(List(docEntityKindToBigImage(tpl), "lib")) }/></a> case _ => <img src={ relativeLinkTo(List(docEntityKindToBigImage(tpl), "lib")) }/> }} diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DiagramGenerator.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DiagramGenerator.scala index 61c1819d11..cf65de4151 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DiagramGenerator.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DiagramGenerator.scala @@ -25,29 +25,3 @@ trait DiagramGenerator { */ def generate(d: Diagram, t: DocTemplateEntity, p: HtmlPage):NodeSeq } - -object DiagramGenerator { - - // TODO: This is tailored towards the dot generator, since it's the only generator. In the future it should be more - // general. - - private[this] var dotRunner: DotRunner = null - private[this] var settings: doc.Settings = null - - def initialize(s: doc.Settings) = - settings = s - - def getDotRunner() = { - if (dotRunner == null) - dotRunner = new DotRunner(settings) - dotRunner - } - - def cleanup() = { - DiagramStats.printStats(settings) - if (dotRunner != null) { - dotRunner.cleanup() - dotRunner = null - } - } -}
\ No newline at end of file diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala index 4ff436bdc6..b541cf721b 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala @@ -15,7 +15,7 @@ import scala.collection.immutable._ import model._ import model.diagram._ -class DotDiagramGenerator(settings: doc.Settings) extends DiagramGenerator { +class DotDiagramGenerator(settings: doc.Settings, dotRunner: DotRunner) extends DiagramGenerator { // the page where the diagram will be embedded private var page: HtmlPage = null @@ -317,7 +317,7 @@ class DotDiagramGenerator(settings: doc.Settings) extends DiagramGenerator { * Calls dot with a given dot string and returns the SVG output. */ private def generateSVG(dotInput: String, template: DocTemplateEntity) = { - val dotOutput = DiagramGenerator.getDotRunner().feedToDot(dotInput, template) + val dotOutput = dotRunner.feedToDot(dotInput, template) var tSVG = -System.currentTimeMillis val result = if (dotOutput != null) { diff --git a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala index 7289edc137..03d71f15a3 100644 --- a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala @@ -9,8 +9,11 @@ import base.comment._ import diagram._ import scala.collection._ +import scala.tools.nsc.doc.html.HtmlPage +import scala.tools.nsc.doc.html.page.diagram.{DotRunner} import scala.util.matching.Regex import scala.reflect.macros.internal.macroImpl +import scala.xml.NodeSeq import symtab.Flags import io._ @@ -47,6 +50,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { thisFactory.universe = thisUniverse val settings = thisFactory.settings val rootPackage = modelCreation.createRootPackage + lazy val dotRunner = new DotRunner(settings) } _modelFinished = true // complete the links between model entities, everthing that couldn't have been done before |