diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fd1fe30d3fa9..9075abcdf36e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -145,7 +145,10 @@ jobs: ./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test ;sjsCompilerTests/test" - name: Test with Scala 2 library TASTy (fast) - run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala; scala3-bootstrapped/testOnly dotty.tools.backend.jvm.DottyBytecodeTests" # only test a subset of test to avoid doubling the CI execution time + run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala; scala3-bootstrapped/testOnly dotty.tools.backend.jvm.DottyBytecodeTests" # only test a subset of test to avoid doubling the CI execution time + + - name: Test with Scala 2 library with CC TASTy (fast) + run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty ;scala2-library-tasty/compile" # TODO test all the test configurations in non-CC library (currently disabled due to bug while loading the library) test_scala2_library_tasty: runs-on: [self-hosted, Linux] @@ -186,7 +189,11 @@ jobs: run: cp -vf .github/workflows/repositories /root/.sbt/ ; true - name: Test with Scala 2 library TASTy - run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/test" + run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty ;scala3-bootstrapped/test" + + # TODO test all the test configurations in non-CC library (currently disabled due to bug while loading the library) + # - name: Test with Scala 2 library with CC TASTy + # run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty ;scala3-bootstrapped/test" test_windows_fast: diff --git a/build.sbt b/build.sbt index 9b6ebc194ea0..1712e80405ae 100644 --- a/build.sbt +++ b/build.sbt @@ -17,6 +17,8 @@ val `scala3-bench-micro` = Build.`scala3-bench-micro` val `scala2-library-bootstrapped` = Build.`scala2-library-bootstrapped` val `scala2-library-tasty` = Build.`scala2-library-tasty` val `scala2-library-tasty-tests` = Build.`scala2-library-tasty-tests` +val `scala2-library-cc` = Build.`scala2-library-cc` +val `scala2-library-cc-tasty` = Build.`scala2-library-cc-tasty` val `tasty-core` = Build.`tasty-core` val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped` val `tasty-core-scala2` = Build.`tasty-core-scala2` diff --git a/compiler/test/dotty/Properties.scala b/compiler/test/dotty/Properties.scala index 4bb3628722ad..e085b0de4875 100644 --- a/compiler/test/dotty/Properties.scala +++ b/compiler/test/dotty/Properties.scala @@ -87,6 +87,9 @@ object Properties { /** If we are using the scala-library TASTy jar */ def usingScalaLibraryTasty: Boolean = scalaLibraryTasty.isDefined + /** If we are using the scala-library TASTy jar */ + + def usingScalaLibraryCCTasty: Boolean = scalaLibraryTasty.exists(_.contains("scala2-library-cc-tasty")) /** scala-asm jar */ def scalaAsm: String = sys.props("dotty.tests.classes.scalaAsm") diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 798af9bdd6b5..361712c2b469 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -45,9 +45,9 @@ class CompilationTests { compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)), compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")), ) ::: ( - // FIXME: This fails due to a bug involving self types and capture checking - if Properties.usingScalaLibraryTasty then Nil - else List(compileDir("tests/pos-special/stdlib", allowDeepSubtypes)) + // TODO create a folder for capture checking tests with the stdlib, or use tests/pos-custom-args/captures under this mode? + if Properties.usingScalaLibraryCCTasty then List(compileDir("tests/pos-special/stdlib", allowDeepSubtypes)) + else Nil ) if scala.util.Properties.isJavaAtLeast("16") then diff --git a/project/Build.scala b/project/Build.scala index b799c32eb65a..2dcbfb0b29f9 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -173,11 +173,23 @@ object Build { // Run tests with filter through vulpix test suite val testCompilation = inputKey[Unit]("runs integration test with the supplied filter") + sealed trait Scala2Library + // Use Scala 2 compiled library JAR + object Scala2LibraryJar extends Scala2Library // Use the TASTy jar from `scala2-library-tasty` in the classpath // This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped` // - // Enable in SBT with: `set ThisBuild/Build.useScala2LibraryTasty := true` - val useScala2LibraryTasty = settingKey[Boolean]("Use the TASTy jar from `scala2-library-tasty` in the classpath") + object Scala2LibraryTasty extends Scala2Library + // Use the TASTy jar from `scala2-library-cc-tasty` in the classpath + // This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped` + // + object Scala2LibraryCCTasty extends Scala2Library + + // Set in SBT with: + // - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryJar` (default) + // - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty` + // - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty` + val scala2Library = settingKey[Scala2Library]("Choose which version of the Scala 2 library should be used") // Used to compile files similar to ./bin/scalac script val scalac = inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath") @@ -225,7 +237,7 @@ object Build { outputStrategy := Some(StdoutOutput), - useScala2LibraryTasty := false, + scala2Library := Scala2LibraryJar, // enable verbose exception messages for JUnit (Test / testOptions) += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"), @@ -645,12 +657,18 @@ object Build { val externalDeps = externalCompilerClasspathTask.value val jars = packageAll.value - val scala2LibraryTasty = jars.get("scala2-library-tasty") match { - case Some(scala2LibraryTastyJar) if useScala2LibraryTasty.value => - Seq("-Ddotty.tests.tasties.scalaLibrary=" + scala2LibraryTastyJar) - case _ => - if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler") - Seq.empty + def libraryPathProperty(jarName: String): Seq[String] = + jars.get(jarName) match { + case Some(jar) => + Seq(s"-Ddotty.tests.tasties.scalaLibrary=$jar") + case None => + log.warn("Scala 2 library TASTy is ignored on non-bootstrapped compiler") + Seq.empty + } + val scala2LibraryTasty = scala2Library.value match { + case Scala2LibraryJar => Seq.empty + case Scala2LibraryTasty => libraryPathProperty("scala2-library-tasty") + case Scala2LibraryCCTasty => libraryPathProperty("scala2-library-cc-tasty") } scala2LibraryTasty ++ Seq( @@ -764,14 +782,24 @@ object Build { else if (debugFromTasty) "dotty.tools.dotc.fromtasty.Debug" else "dotty.tools.dotc.Main" - var extraClasspath = - scalaLibTastyOpt match { - case Some(scalaLibTasty) if useScala2LibraryTasty.value => - Seq(scalaLibTasty, scalaLib, dottyLib) - case _ => - if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler") - Seq(scalaLib, dottyLib) - } + val scala2LibraryTasty = scala2Library.value match { + case Scala2LibraryJar => Seq.empty + case Scala2LibraryTasty => + jars.get("scala2-library-tasty") match { + case Some(jar) => Seq(jar) + case None => + log.warn("Scala2LibraryTasty is ignored on non-bootstrapped compiler") + Seq.empty + } + case Scala2LibraryCCTasty => + jars.get("scala2-library-cc-tasty") match { + case Some(jar) => Seq(jar) + case None => + log.warn("Scala2LibraryCCTasty is ignored on non-bootstrapped compiler") + Seq.empty + } + } + var extraClasspath = scala2LibraryTasty ++ Seq(scalaLib, dottyLib) if (decompile && !args.contains("-classpath")) extraClasspath ++= Seq(".") @@ -882,6 +910,7 @@ object Build { "scala3-tasty-inspector" -> (LocalProject("scala3-tasty-inspector") / Compile / packageBin).value.getAbsolutePath, "tasty-core" -> (LocalProject("tasty-core-bootstrapped") / Compile / packageBin).value.getAbsolutePath, "scala2-library-tasty" -> (LocalProject("scala2-library-tasty") / Compile / packageBin).value.getAbsolutePath, + "scala2-library-cc-tasty" -> (LocalProject("scala2-library-cc-tasty") / Compile / packageBin).value.getAbsolutePath, ) }, @@ -1010,8 +1039,24 @@ object Build { withCommonSettings(Bootstrapped). dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test"). settings(commonBootstrappedSettings). + settings(scala2LibraryBootstrappedSettings). + settings(moduleName := "scala2-library") + + /** Scala 2 library compiled by dotty using the latest published sources of the library. + * + * This version of the library is not (yet) TASTy/binary compatible with the Scala 2 compiled library. + */ + lazy val `scala2-library-cc` = project.in(file("scala2-library-cc")). + withCommonSettings(Bootstrapped). + dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test"). + settings(commonBootstrappedSettings). + settings(scala2LibraryBootstrappedSettings). settings( - moduleName := "scala2-library", + moduleName := "scala2-library-cc", + scalacOptions += "-Ycheck:all", + ) + + lazy val scala2LibraryBootstrappedSettings = Seq( javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, Compile / scalacOptions ++= { Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString) @@ -1096,13 +1141,13 @@ object Build { | - final val MinorVersion = $minorVersion | - final val ExperimentalVersion = 0 | * Clean everything to generate a compiler with those new TASTy versions - | * Run scala2-library-bootstrapped/tastyMiMaReportIssues + | * Run ${name.value}/tastyMiMaReportIssues |""".stripMargin) }).value, Compile / exportJars := true, artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) => - "scala2-library-" + dottyVersion + "." + artifact.extension + moduleName.value + "-" + dottyVersion + "." + artifact.extension }, run := { val log = streams.value.log @@ -1174,7 +1219,7 @@ object Build { |""".stripMargin) } } - ) + ) /** Packages the TASTy files of `scala2-library-bootstrapped` in a jar */ lazy val `scala2-library-tasty` = project.in(file("scala2-library-tasty")). @@ -1187,6 +1232,17 @@ object Build { }, ) + /** Packages the TASTy files of `scala2-library-cc` in a jar */ + lazy val `scala2-library-cc-tasty` = project.in(file("scala2-library-cc-tasty")). + withCommonSettings(Bootstrapped). + settings( + exportJars := true, + Compile / packageBin / mappings := { + (`scala2-library-cc` / Compile / packageBin / mappings).value + .filter(_._2.endsWith(".tasty")) + }, + ) + /** Test the tasty generated by `scala2-library-bootstrapped` * * The sources in src are compiled using TASTy from scala2-library-tasty but then run diff --git a/scala2-library-cc/src/scala/Function1.scala b/scala2-library-cc/src/scala/Function1.scala new file mode 100644 index 000000000000..96ca493739ed --- /dev/null +++ b/scala2-library-cc/src/scala/Function1.scala @@ -0,0 +1,90 @@ +/* + * Scala (https://www.scala-lang.org) + * + * Copyright EPFL and Lightbend, Inc. + * + * Licensed under Apache License 2.0 + * (http://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp. + +package scala + + +object Function1 { + + implicit final class UnliftOps[A, B] private[Function1](private val f: A => Option[B]) extends AnyVal { + /** Converts an optional function to a partial function. + * + * @example Unlike [[Function.unlift]], this [[UnliftOps.unlift]] method can be used in extractors. + * {{{ + * val of: Int => Option[String] = { i => + * if (i == 2) { + * Some("matched by an optional function") + * } else { + * None + * } + * } + * + * util.Random.nextInt(4) match { + * case of.unlift(m) => // Convert an optional function to a pattern + * println(m) + * case _ => + * println("Not matched") + * } + * }}} + */ + def unlift: PartialFunction[A, B] = Function.unlift(f) + } + +} + +/** A function of 1 parameter. + * + * In the following example, the definition of `succ` is + * shorthand, conceptually, for the anonymous class definition + * `anonfun1`, although the implementation details of how the + * function value is constructed may differ: + * + * {{{ + * object Main extends App { + * val succ = (x: Int) => x + 1 + * val anonfun1 = new Function1[Int, Int] { + * def apply(x: Int): Int = x + 1 + * } + * assert(succ(0) == anonfun1(0)) + * } + * }}} + * + * Note that the difference between `Function1` and [[scala.PartialFunction]] + * is that the latter can specify inputs which it will not handle. + */ +@annotation.implicitNotFound(msg = "No implicit view available from ${T1} => ${R}.") +trait Function1[@specialized(Specializable.Arg) -T1, @specialized(Specializable.Return) +R] extends AnyRef { // FIXME: self => + /** Apply the body of this function to the argument. + * @return the result of function application. + */ + def apply(v1: T1): R + + /** Composes two instances of Function1 in a new Function1, with this function applied last. + * + * @tparam A the type to which function `g` can be applied + * @param g a function A => T1 + * @return a new function `f` such that `f(x) == apply(g(x))` + */ + @annotation.unspecialized def compose[A](g: A => T1): A => R = { x => apply(g(x)) } + + /** Composes two instances of Function1 in a new Function1, with this function applied first. + * + * @tparam A the result type of function `g` + * @param g a function R => A + * @return a new function `f` such that `f(x) == g(apply(x))` + */ + @annotation.unspecialized def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) } + + override def toString(): String = "" +} diff --git a/scala2-library-cc/src/scala/PartialFunction.scala b/scala2-library-cc/src/scala/PartialFunction.scala new file mode 100644 index 000000000000..671d58be33e5 --- /dev/null +++ b/scala2-library-cc/src/scala/PartialFunction.scala @@ -0,0 +1,403 @@ +/* + * Scala (https://www.scala-lang.org) + * + * Copyright EPFL and Lightbend, Inc. + * + * Licensed under Apache License 2.0 + * (http://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +package scala + +import scala.annotation.nowarn + +/** A partial function of type `PartialFunction[A, B]` is a unary function + * where the domain does not necessarily include all values of type `A`. + * The function [[isDefinedAt]] allows to test dynamically if a value is in + * the domain of the function. + * + * Even if `isDefinedAt` returns true for an `a: A`, calling `apply(a)` may + * still throw an exception, so the following code is legal: + * + * {{{ + * val f: PartialFunction[Int, Any] = { case x => x / 0 } // ArithmeticException: / by zero + * }}} + * + * It is the responsibility of the caller to call `isDefinedAt` before + * calling `apply`, because if `isDefinedAt` is false, it is not guaranteed + * `apply` will throw an exception to indicate an error condition. If an + * exception is not thrown, evaluation may result in an arbitrary value. + * + * The usual way to respect this contract is to call [[applyOrElse]], + * which is expected to be more efficient than calling both `isDefinedAt` + * and `apply`. + * + * The main distinction between `PartialFunction` and [[scala.Function1]] is + * that the user of a `PartialFunction` may choose to do something different + * with input that is declared to be outside its domain. For example: + * + * {{{ + * val sample = 1 to 10 + * def isEven(n: Int) = n % 2 == 0 + * val eveningNews: PartialFunction[Int, String] = { + * case x if isEven(x) => s"\$x is even" + * } + * + * // The method collect is described as "filter + map" + * // because it uses a PartialFunction to select elements + * // to which the function is applied. + * val evenNumbers = sample.collect(eveningNews) + * + * val oddlyEnough: PartialFunction[Int, String] = { + * case x if !isEven(x) => s"\$x is odd" + * } + * + * // The method orElse allows chaining another PartialFunction + * // to handle input outside the declared domain. + * val numbers = sample.map(eveningNews orElse oddlyEnough) + * + * // same as + * val numbers = sample.map(n => eveningNews.applyOrElse(n, oddlyEnough)) + * + * val half: PartialFunction[Int, Int] = { + * case x if isEven(x) => x / 2 + * } + * + * // Calculating the domain of a composition can be expensive. + * val oddByHalf = half.andThen(oddlyEnough) + * + * // Invokes `half.apply` on even elements! + * val oddBalls = sample.filter(oddByHalf.isDefinedAt) + * + * // Better than filter(oddByHalf.isDefinedAt).map(oddByHalf) + * val oddBalls = sample.collect(oddByHalf) + * + * // Providing "default" values. + * val oddsAndEnds = sample.map(n => oddByHalf.applyOrElse(n, (i: Int) => s"[\$i]")) + * }}} + * + * @note Optional [[Function]]s, [[PartialFunction]]s and extractor objects + * can be converted to each other as shown in the following table. + *   + * | How to convert ... | to a [[PartialFunction]] | to an optional [[Function]] | to an extractor | + * | :---: | --- | --- | --- | + * | from a [[PartialFunction]] | [[Predef.identity]] | [[lift]] | [[Predef.identity]] | + * | from optional [[Function]] | [[Function1.UnliftOps#unlift]] or [[Function.unlift]] | [[Predef.identity]] | [[Function1.UnliftOps#unlift]] | + * | from an extractor | `{ case extractor(x) => x }` | `extractor.unapply _` | [[Predef.identity]] | + *   + * + * @define applyOrElseOrElse Note that calling [[isDefinedAt]] on the resulting partial function + * may apply the first partial function and execute its side effect. + * For efficiency, it is recommended to call [[applyOrElse]] instead of [[isDefinedAt]] or [[apply]]. + */ +trait PartialFunction[-A, +B] extends (A => B) { // FIXME: self => + import PartialFunction._ + + /** Tries to extract a `B` from an `A` in a pattern matching expression. */ + def unapply(a: A): Option[B] = lift(a) + + /** Returns an extractor object with a `unapplySeq` method, which extracts each element of a sequence data. + * + * @example {{{ + * val firstChar: String => Option[Char] = _.headOption + * + * Seq("foo", "bar", "baz") match { + * case firstChar.unlift.elementWise(c0, c1, c2) => + * println(s"\$c0, \$c1, \$c2") // Output: f, b, b + * } + * }}} + */ + def elementWise: ElementWiseExtractor[A, B] = new ElementWiseExtractor[A, B](this) + + /** Checks if a value is contained in the function's domain. + * + * @param x the value to test + * @return `'''true'''`, iff `x` is in the domain of this function, `'''false'''` otherwise. + */ + def isDefinedAt(x: A): Boolean + + /** Composes this partial function with a fallback partial function which + * gets applied where this partial function is not defined. + * + * @param that the fallback function + * @tparam A1 the argument type of the fallback function + * @tparam B1 the result type of the fallback function + * @return a partial function which has as domain the union of the domains + * of this partial function and `that`. The resulting partial function + * takes `x` to `this(x)` where `this` is defined, and to `that(x)` where it is not. + */ + def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]): PartialFunction[A1, B1] = + new OrElse[A1, B1] (this, that) + //TODO: why not overload it with orElse(that: F1): F1? + + /** Composes this partial function with a transformation function that + * gets applied to results of this partial function. + * + * If the runtime type of the function is a `PartialFunction` then the + * other `andThen` method is used (note its cautions). + * + * @param k the transformation function + * @tparam C the result type of the transformation function. + * @return a partial function with the domain of this partial function, + * possibly narrowed by the specified function, which maps + * arguments `x` to `k(this(x))`. + */ + override def andThen[C](k: B => C): PartialFunction[A, C] = k match { + case pf: PartialFunction[B, C] => andThen(pf) + case _ => new AndThen[A, B, C](this, k) + } + + /** + * Composes this partial function with another partial function that + * gets applied to results of this partial function. + * + * $applyOrElseOrElse + * + * @param k the transformation function + * @tparam C the result type of the transformation function. + * @return a partial function with the domain of this partial function narrowed by + * other partial function, which maps arguments `x` to `k(this(x))`. + */ + def andThen[C](k: PartialFunction[B, C]): PartialFunction[A, C] = + new Combined[A, B, C](this, k) + + /** + * Composes another partial function `k` with this partial function so that this + * partial function gets applied to results of `k`. + * + * $applyOrElseOrElse + * + * @param k the transformation function + * @tparam R the parameter type of the transformation function. + * @return a partial function with the domain of other partial function narrowed by + * this partial function, which maps arguments `x` to `this(k(x))`. + */ + def compose[R](k: PartialFunction[R, A]): PartialFunction[R, B] = + new Combined[R, A, B](k, this) + + /** Turns this partial function into a plain function returning an `Option` result. + * @see Function.unlift + * @return a function that takes an argument `x` to `Some(this(x))` if `this` + * is defined for `x`, and to `None` otherwise. + */ + def lift: A => Option[B] = new Lifted(this) + + /** Applies this partial function to the given argument when it is contained in the function domain. + * Applies fallback function where this partial function is not defined. + * + * Note that expression `pf.applyOrElse(x, default)` is equivalent to + * {{{ if(pf isDefinedAt x) pf(x) else default(x) }}} + * except that `applyOrElse` method can be implemented more efficiently. + * For all partial function literals the compiler generates an `applyOrElse` implementation which + * avoids double evaluation of pattern matchers and guards. + * This makes `applyOrElse` the basis for the efficient implementation for many operations and scenarios, such as: + * + * - combining partial functions into `orElse`/`andThen` chains does not lead to + * excessive `apply`/`isDefinedAt` evaluation + * - `lift` and `unlift` do not evaluate source functions twice on each invocation + * - `runWith` allows efficient imperative-style combining of partial functions + * with conditionally applied actions + * + * For non-literal partial function classes with nontrivial `isDefinedAt` method + * it is recommended to override `applyOrElse` with custom implementation that avoids + * double `isDefinedAt` evaluation. This may result in better performance + * and more predictable behavior w.r.t. side effects. + * + * @param x the function argument + * @param default the fallback function + * @return the result of this function or fallback function application. + */ + def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = + if (isDefinedAt(x)) apply(x) else default(x) + + /** Composes this partial function with an action function which + * gets applied to results of this partial function. + * The action function is invoked only for its side effects; its result is ignored. + * + * Note that expression `pf.runWith(action)(x)` is equivalent to + * {{{ if(pf isDefinedAt x) { action(pf(x)); true } else false }}} + * except that `runWith` is implemented via `applyOrElse` and thus potentially more efficient. + * Using `runWith` avoids double evaluation of pattern matchers and guards for partial function literals. + * @see `applyOrElse`. + * + * @param action the action function + * @return a function which maps arguments `x` to `isDefinedAt(x)`. The resulting function + * runs `action(this(x))` where `this` is defined. + */ + def runWith[U](action: B => U): A => Boolean = { x => + val z = applyOrElse(x, checkFallback[B]) + if (!fallbackOccurred(z)) { action(z); true } else false + } +} + +/** A few handy operations which leverage the extra bit of information + * available in partial functions. Examples: + * {{{ + * import PartialFunction._ + * + * def strangeConditional(other: Any): Boolean = cond(other) { + * case x: String if x == "abc" || x == "def" => true + * case x: Int => true + * } + * def onlyInt(v: Any): Option[Int] = condOpt(v) { case x: Int => x } + * }}} + */ +object PartialFunction { + + final class ElementWiseExtractor[-A, +B] private[PartialFunction] (private val pf: PartialFunction[A, B]) extends AnyVal { + @nowarn("cat=lint-nonlocal-return") + def unapplySeq(seq: Seq[A]): Option[Seq[B]] = { + Some(seq.map { + case pf(b) => b + case _ => return None + }) + } + } + + /** Composite function produced by `PartialFunction#orElse` method + */ + private class OrElse[-A, +B] (f1: PartialFunction[A, B], f2: PartialFunction[A, B]) + extends scala.runtime.AbstractPartialFunction[A, B] with Serializable { + def isDefinedAt(x: A) = f1.isDefinedAt(x) || f2.isDefinedAt(x) + + override def apply(x: A): B = f1.applyOrElse(x, f2) + + override def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = { + val z = f1.applyOrElse(x, checkFallback[B]) + if (!fallbackOccurred(z)) z else f2.applyOrElse(x, default) + } + + override def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]): OrElse[A1, B1] = + new OrElse[A1, B1] (f1, f2 orElse that) + + override def andThen[C](k: B => C): OrElse[A, C] = + new OrElse[A, C] (f1 andThen k, f2 andThen k) + } + + /** Composite function produced by `PartialFunction#andThen` method + */ + private class AndThen[-A, B, +C] (pf: PartialFunction[A, B], k: B => C) extends PartialFunction[A, C] with Serializable { + def isDefinedAt(x: A) = pf.isDefinedAt(x) + + def apply(x: A): C = k(pf(x)) + + override def applyOrElse[A1 <: A, C1 >: C](x: A1, default: A1 => C1): C1 = { + val z = pf.applyOrElse(x, checkFallback[B]) + if (!fallbackOccurred(z)) k(z) else default(x) + } + } + + /** Composite function produced by `PartialFunction#andThen` method + */ + private class Combined[-A, B, +C] (pf: PartialFunction[A, B], k: PartialFunction[B, C]) extends PartialFunction[A, C] with Serializable { + def isDefinedAt(x: A): Boolean = { + val b: B = pf.applyOrElse(x, checkFallback[B]) + if (!fallbackOccurred(b)) k.isDefinedAt(b) else false + } + + def apply(x: A): C = k(pf(x)) + + override def applyOrElse[A1 <: A, C1 >: C](x: A1, default: A1 => C1): C1 = { + val pfv = pf.applyOrElse(x, checkFallback[B]) + if (!fallbackOccurred(pfv)) k.applyOrElse(pfv, (_: B) => default(x)) else default(x) + } + } + + /** To implement patterns like {{{ if(pf isDefinedAt x) f1(pf(x)) else f2(x) }}} efficiently + * the following trick is used: + * + * To avoid double evaluation of pattern matchers & guards `applyOrElse` method is used here + * instead of `isDefinedAt`/`apply` pair. + * + * After call to `applyOrElse` we need both the function result it returned and + * the fact if the function's argument was contained in its domain. The only degree of freedom we have here + * to achieve this goal is tweaking with the continuation argument (`default`) of `applyOrElse` method. + * The obvious way is to throw an exception from `default` function and to catch it after + * calling `applyOrElse` but I consider this somewhat inefficient. + * + * I know only one way how you can do this task efficiently: `default` function should return unique marker object + * which never may be returned by any other (regular/partial) function. This way after calling `applyOrElse` you need + * just one reference comparison to distinguish if `pf isDefined x` or not. + * + * This correctly interacts with specialization as return type of `applyOrElse` + * (which is parameterized upper bound) can never be specialized. + * + * Here `fallback_fn` is used as both unique marker object and special fallback function that returns it. + */ + private[this] val fallback_fn: Any => Any = _ => fallback_fn + private def checkFallback[B] = fallback_fn.asInstanceOf[Any => B] + private def fallbackOccurred[B](x: B) = fallback_fn eq x.asInstanceOf[AnyRef] + + private class Lifted[-A, +B] (val pf: PartialFunction[A, B]) + extends scala.runtime.AbstractFunction1[A, Option[B]] with Serializable { + + def apply(x: A): Option[B] = { + val z = pf.applyOrElse(x, checkFallback[B]) + if (!fallbackOccurred(z)) Some(z) else None + } + } + + private class Unlifted[A, B] (f: A => Option[B]) extends scala.runtime.AbstractPartialFunction[A, B] with Serializable { + def isDefinedAt(x: A): Boolean = f(x).isDefined + + override def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 = { + f(x).getOrElse(default(x)) + } + + override def lift = f + } + + private[scala] def unlifted[A, B](f: A => Option[B]): PartialFunction[A, B] = f match { + case lf: Lifted[A, B] => lf.pf + case ff => new Unlifted(ff) + } + + /** Converts an ordinary function to a partial function. Note that calling `isDefinedAt(x)` on + * this partial function will return `true` for every `x`. + * @param f an ordinary function + * @return a partial function which delegates to the ordinary function `f` + */ + def fromFunction[A, B](f: A => B): PartialFunction[A, B] = { case x => f(x) } + + private[this] val constFalse: Any => Boolean = { _ => false} + + private[this] val empty_pf: PartialFunction[Any, Nothing] = new PartialFunction[Any, Nothing] with Serializable { + def isDefinedAt(x: Any) = false + def apply(x: Any) = throw new MatchError(x) + override def orElse[A1, B1](that: PartialFunction[A1, B1]) = that + override def andThen[C](k: Nothing => C): PartialFunction[Any, Nothing] = this + override val lift: Any => None.type = (x: Any) => None + override def runWith[U](action: Nothing => U) = constFalse + } + + /** The partial function with empty domain. + * Any attempt to invoke empty partial function leads to throwing [[scala.MatchError]] exception. + */ + def empty[A, B] : PartialFunction[A, B] = empty_pf + + /** A Boolean test that is the result of the given function where defined, + * and false otherwise. + * + * It behaves like a `case _ => false` were added to the partial function. + * + * @param x the value to test + * @param pf the partial function + * @return true, iff `x` is in the domain of `pf` and `pf(x) == true`. + */ + def cond[A](x: A)(pf: PartialFunction[A, Boolean]): Boolean = pf.applyOrElse(x, constFalse) + + /** Apply the function to the given value if defined, and return the result + * in a `Some`; otherwise, return `None`. + * + * @param x the value to test + * @param pf the PartialFunction[T, U] + * @return `Some(pf(x))` if `pf isDefinedAt x`, `None` otherwise. + */ + def condOpt[A, B](x: A)(pf: PartialFunction[A, B]): Option[B] = { + val z = pf.applyOrElse(x, checkFallback[B]) + if (!fallbackOccurred(z)) Some(z) else None + } +} diff --git a/scala2-library-cc/src/scala/TODO b/scala2-library-cc/src/scala/TODO new file mode 100644 index 000000000000..241779ab8dd9 --- /dev/null +++ b/scala2-library-cc/src/scala/TODO @@ -0,0 +1 @@ +- Delete or re-clone Function1 and PartialFunction. These where edited to remove the self type. diff --git a/tests/pos-special/stdlib/collection/ArrayOps.scala b/scala2-library-cc/src/scala/collection/ArrayOps.scala similarity index 98% rename from tests/pos-special/stdlib/collection/ArrayOps.scala rename to scala2-library-cc/src/scala/collection/ArrayOps.scala index bb6174f59598..e8548c12751f 100644 --- a/tests/pos-special/stdlib/collection/ArrayOps.scala +++ b/scala2-library-cc/src/scala/collection/ArrayOps.scala @@ -113,7 +113,7 @@ object ArrayOps { b.result() } - def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] = + def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] = flatMap[B](x => asIterable(f(x))) /** Creates a new non-strict filter which combines this filter with the given predicate. */ @@ -505,7 +505,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { * * @return a pair of arrays: the first one made of those values returned by `f` that were wrapped in [[scala.util.Left]], * and the second one made of those wrapped in [[scala.util.Right]]. */ - def partitionMap[A1: ClassTag, A2: ClassTag](f: A => Either[A1, A2]): (Array[A1], Array[A2]) = { + def partitionMap[A1: ClassTag, A2: ClassTag](f: A => Either[A1, A2]): (Array[A1], Array[A2]) = { val res1 = ArrayBuilder.make[A1] val res2 = ArrayBuilder.make[A2] var i = 0 @@ -816,7 +816,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { * }}} * */ - def scanLeft[B : ClassTag](z: B)(op: (B, A) => B): Array[B] = { + def scanLeft[ B : ClassTag ](z: B)(op: (B, A) => B): Array[B] = { var v = z var i = 0 val res = new Array[B](xs.length + 1) @@ -855,7 +855,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { * }}} * */ - def scanRight[B : ClassTag](z: B)(op: (A, B) => B): Array[B] = { + def scanRight[ B : ClassTag ](z: B)(op: (A, B) => B): Array[B] = { var v = z var i = xs.length - 1 val res = new Array[B](xs.length + 1) @@ -973,7 +973,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { b.result() } - def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] = + def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] = flatMap[B](x => asIterable(f(x))) /** Flattens a two-dimensional array by concatenating all its rows @@ -1095,7 +1095,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { * If this array is shorter than `that`, `thisElem` values are used to pad the result. * If `that` is shorter than this array, `thatElem` values are used to pad the result. */ - def zipAll[A1 >: A, B](that: Iterable[B], thisElem: A1, thatElem: B): Array[(A1, B)] = { + def zipAll[A1 >: A, B](that: Iterable[B], thisElem: A1, thatElem: B): Array[(A1, B)] = { val b = new ArrayBuilder.ofRef[(A1, B)]() val k = that.knownSize b.sizeHint(max(k, xs.length)) @@ -1244,7 +1244,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { * @return a pair of Arrays, containing, respectively, the first and second half * of each element pair of this Array. */ - def unzip[A1, A2](implicit asPair: A => (A1, A2), ct1: ClassTag[A1], ct2: ClassTag[A2]): (Array[A1], Array[A2]) = { + def unzip[A1, A2](implicit asPair: A => (A1, A2), ct1: ClassTag[A1], ct2: ClassTag[A2]): (Array[A1], Array[A2]) = { val a1 = new Array[A1](xs.length) val a2 = new Array[A2](xs.length) var i = 0 @@ -1273,7 +1273,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { * @return a triple of Arrays, containing, respectively, the first, second, and third * elements from each element triple of this Array. */ - def unzip3[A1, A2, A3](implicit asTriple: A => (A1, A2, A3), ct1: ClassTag[A1], ct2: ClassTag[A2], + def unzip3[A1, A2, A3](implicit asTriple: A => (A1, A2, A3), ct1: ClassTag[A1], ct2: ClassTag[A2], ct3: ClassTag[A3]): (Array[A1], Array[A2], Array[A3]) = { val a1 = new Array[A1](xs.length) val a2 = new Array[A2](xs.length) @@ -1418,7 +1418,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { * @tparam K the type of keys returned by the discriminator function * @tparam B the type of values returned by the transformation function */ - def groupMap[K, B : ClassTag](key: A => K)(f: A => B): immutable.Map[K, Array[B]] = { + def groupMap[K, B : ClassTag](key: A => K)(f: A => B): immutable.Map[K, Array[B]] = { val m = mutable.Map.empty[K, ArrayBuilder[B]] val len = xs.length var i = 0 @@ -1479,7 +1479,8 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { /** Create a copy of this array with the specified element type. */ def toArray[B >: A: ClassTag]: Array[B] = { val destination = new Array[B](xs.length) - copyToArray(destination, 0) + @annotation.unused val copied = copyToArray(destination, 0) + //assert(copied == xs.length) destination } diff --git a/tests/pos-special/stdlib/collection/BitSet.scala b/scala2-library-cc/src/scala/collection/BitSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/BitSet.scala rename to scala2-library-cc/src/scala/collection/BitSet.scala diff --git a/tests/pos-special/stdlib/collection/BufferedIterator.scala b/scala2-library-cc/src/scala/collection/BufferedIterator.scala similarity index 100% rename from tests/pos-special/stdlib/collection/BufferedIterator.scala rename to scala2-library-cc/src/scala/collection/BufferedIterator.scala diff --git a/tests/pos-special/stdlib/collection/BuildFrom.scala b/scala2-library-cc/src/scala/collection/BuildFrom.scala similarity index 99% rename from tests/pos-special/stdlib/collection/BuildFrom.scala rename to scala2-library-cc/src/scala/collection/BuildFrom.scala index 05df32856d82..d82e90777d3e 100644 --- a/tests/pos-special/stdlib/collection/BuildFrom.scala +++ b/scala2-library-cc/src/scala/collection/BuildFrom.scala @@ -87,7 +87,7 @@ object BuildFrom extends BuildFromLowPriority1 { def newBuilder(from: Array[_]): Builder[A, Array[A]] = Factory.arrayFactory[A].newBuilder } - implicit def buildFromView[A, B]: BuildFrom[View[A], B, View[B]] = + implicit def buildFromView[A, B]: BuildFrom[View[A], B, View[B]] = new BuildFrom[View[A], B, View[B]] { def fromSpecific(from: View[A])(it: IterableOnce[B]^): View[B] = View.from(it).unsafeAssumePure def newBuilder(from: View[A]): Builder[B, View[B]] = View.newBuilder diff --git a/tests/pos-special/stdlib/collection/DefaultMap.scala b/scala2-library-cc/src/scala/collection/DefaultMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/DefaultMap.scala rename to scala2-library-cc/src/scala/collection/DefaultMap.scala diff --git a/tests/pos-special/stdlib/collection/Factory.scala b/scala2-library-cc/src/scala/collection/Factory.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Factory.scala rename to scala2-library-cc/src/scala/collection/Factory.scala diff --git a/tests/pos-special/stdlib/collection/Hashing.scala b/scala2-library-cc/src/scala/collection/Hashing.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Hashing.scala rename to scala2-library-cc/src/scala/collection/Hashing.scala diff --git a/tests/pos-special/stdlib/collection/IndexedSeq.scala b/scala2-library-cc/src/scala/collection/IndexedSeq.scala similarity index 91% rename from tests/pos-special/stdlib/collection/IndexedSeq.scala rename to scala2-library-cc/src/scala/collection/IndexedSeq.scala index a2d4cc942231..998d1a5a635f 100644 --- a/tests/pos-special/stdlib/collection/IndexedSeq.scala +++ b/scala2-library-cc/src/scala/collection/IndexedSeq.scala @@ -94,11 +94,25 @@ trait IndexedSeqOps[+A, +CC[_], +C] extends Any with IndexedSeqViewOps[A, CC, C] override def slice(from: Int, until: Int): C = fromSpecific(new IndexedSeqView.Slice(this, from, until)) - override def head: A = apply(0) + override def head: A = + if (!isEmpty) apply(0) + else throw new NoSuchElementException(s"head of empty ${ + self match { + case self: IndexedSeq[_] => self.collectionClassName + case _ => toString + } + }") override def headOption: Option[A] = if (isEmpty) None else Some(head) - override def last: A = apply(length - 1) + override def last: A = + if (!isEmpty) apply(length - 1) + else throw new NoSuchElementException(s"last of empty ${ + self match { + case self: IndexedSeq[_] => self.collectionClassName + case _ => toString + } + }") // We already inherit an efficient `lastOption = if (isEmpty) None else Some(last)` diff --git a/tests/pos-special/stdlib/collection/IndexedSeqView.scala b/scala2-library-cc/src/scala/collection/IndexedSeqView.scala similarity index 100% rename from tests/pos-special/stdlib/collection/IndexedSeqView.scala rename to scala2-library-cc/src/scala/collection/IndexedSeqView.scala diff --git a/tests/pos-special/stdlib/collection/Iterable.scala b/scala2-library-cc/src/scala/collection/Iterable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Iterable.scala rename to scala2-library-cc/src/scala/collection/Iterable.scala diff --git a/tests/pos-special/stdlib/collection/IterableOnce.scala b/scala2-library-cc/src/scala/collection/IterableOnce.scala similarity index 99% rename from tests/pos-special/stdlib/collection/IterableOnce.scala rename to scala2-library-cc/src/scala/collection/IterableOnce.scala index a0b184410428..30eb142ae156 100644 --- a/tests/pos-special/stdlib/collection/IterableOnce.scala +++ b/scala2-library-cc/src/scala/collection/IterableOnce.scala @@ -19,7 +19,7 @@ import scala.collection.mutable.StringBuilder import scala.language.implicitConversions import scala.math.{Numeric, Ordering} import scala.reflect.ClassTag -import scala.runtime.AbstractFunction2 +import scala.runtime.{AbstractFunction1, AbstractFunction2} import language.experimental.captureChecking /** @@ -272,7 +272,7 @@ object IterableOnce { math.max(math.min(math.min(len, srcLen), destLen - start), 0) /** Calls `copyToArray` on the given collection, regardless of whether or not it is an `Iterable`. */ - @inline private[collection] def copyElemsToArray[A, B >: A]( + @inline private[collection] def copyElemsToArray[A, B >: A]( elems: IterableOnce[A]^, xs: Array[B], start: Int = 0, @@ -1117,8 +1117,8 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A]^ => def collectFirst[B](pf: PartialFunction[A, B]): Option[B] = { // Presumably the fastest way to get in and out of a partial function is for a sentinel function to return itself // (Tested to be lower-overhead than runWith. Would be better yet to not need to (formally) allocate it) - val sentinel: scala.Function1[A, Any] = new scala.runtime.AbstractFunction1[A, Any] { - def apply(a: A) = this + val sentinel: scala.Function1[A, Any] = new AbstractFunction1[A, Any] { + def apply(a: A): AbstractFunction1[A, Any] = this } val it = iterator while (it.hasNext) { @@ -1322,7 +1322,8 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A]^ => def toArray[B >: A: ClassTag]: Array[B] = if (knownSize >= 0) { val destination = new Array[B](knownSize) - copyToArray(destination, 0) + @annotation.unused val copied = copyToArray(destination, 0) + //assert(copied == destination.length) destination } else mutable.ArrayBuilder.make[B].addAll(this).result() @@ -1362,4 +1363,4 @@ object IterableOnceOps: m } } -end IterableOnceOps \ No newline at end of file +end IterableOnceOps diff --git a/tests/pos-special/stdlib/collection/Iterator.scala b/scala2-library-cc/src/scala/collection/Iterator.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Iterator.scala rename to scala2-library-cc/src/scala/collection/Iterator.scala diff --git a/tests/pos-special/stdlib/collection/JavaConverters.scala b/scala2-library-cc/src/scala/collection/JavaConverters.scala similarity index 100% rename from tests/pos-special/stdlib/collection/JavaConverters.scala rename to scala2-library-cc/src/scala/collection/JavaConverters.scala diff --git a/tests/pos-special/stdlib/collection/LazyZipOps.scala b/scala2-library-cc/src/scala/collection/LazyZipOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/LazyZipOps.scala rename to scala2-library-cc/src/scala/collection/LazyZipOps.scala diff --git a/tests/pos-special/stdlib/collection/LinearSeq.scala b/scala2-library-cc/src/scala/collection/LinearSeq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/LinearSeq.scala rename to scala2-library-cc/src/scala/collection/LinearSeq.scala diff --git a/tests/pos-special/stdlib/collection/Map.scala b/scala2-library-cc/src/scala/collection/Map.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Map.scala rename to scala2-library-cc/src/scala/collection/Map.scala diff --git a/tests/pos-special/stdlib/collection/MapView.scala b/scala2-library-cc/src/scala/collection/MapView.scala similarity index 98% rename from tests/pos-special/stdlib/collection/MapView.scala rename to scala2-library-cc/src/scala/collection/MapView.scala index 595fe20538d3..5909fe24fbbc 100644 --- a/tests/pos-special/stdlib/collection/MapView.scala +++ b/scala2-library-cc/src/scala/collection/MapView.scala @@ -161,7 +161,7 @@ object MapView extends MapViewFactory { override def isEmpty: Boolean = underlying.isEmpty } - override def newBuilder[X, Y]: Builder[(X, Y), MapView[X, Y]] = mutable.HashMap.newBuilder[X, Y].mapResult(_.view) + override def newBuilder[X, Y]: Builder[(X, Y), MapView[X, Y]] = mutable.HashMap.newBuilder[X, Y].mapResult(_.view) override def empty[K, V]: MapView[K, V] = EmptyMapView.asInstanceOf[MapView[K, V]] diff --git a/tests/pos-special/stdlib/collection/Searching.scala b/scala2-library-cc/src/scala/collection/Searching.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Searching.scala rename to scala2-library-cc/src/scala/collection/Searching.scala diff --git a/tests/pos-special/stdlib/collection/Seq.scala b/scala2-library-cc/src/scala/collection/Seq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Seq.scala rename to scala2-library-cc/src/scala/collection/Seq.scala diff --git a/tests/pos-special/stdlib/collection/SeqMap.scala b/scala2-library-cc/src/scala/collection/SeqMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/SeqMap.scala rename to scala2-library-cc/src/scala/collection/SeqMap.scala diff --git a/tests/pos-special/stdlib/collection/SeqView.scala b/scala2-library-cc/src/scala/collection/SeqView.scala similarity index 100% rename from tests/pos-special/stdlib/collection/SeqView.scala rename to scala2-library-cc/src/scala/collection/SeqView.scala diff --git a/tests/pos-special/stdlib/collection/Set.scala b/scala2-library-cc/src/scala/collection/Set.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Set.scala rename to scala2-library-cc/src/scala/collection/Set.scala diff --git a/tests/pos-special/stdlib/collection/SortedMap.scala b/scala2-library-cc/src/scala/collection/SortedMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/SortedMap.scala rename to scala2-library-cc/src/scala/collection/SortedMap.scala diff --git a/tests/pos-special/stdlib/collection/SortedOps.scala b/scala2-library-cc/src/scala/collection/SortedOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/SortedOps.scala rename to scala2-library-cc/src/scala/collection/SortedOps.scala diff --git a/tests/pos-special/stdlib/collection/SortedSet.scala b/scala2-library-cc/src/scala/collection/SortedSet.scala similarity index 99% rename from tests/pos-special/stdlib/collection/SortedSet.scala rename to scala2-library-cc/src/scala/collection/SortedSet.scala index fb2f879edcd2..639dc9ddead0 100644 --- a/tests/pos-special/stdlib/collection/SortedSet.scala +++ b/scala2-library-cc/src/scala/collection/SortedSet.scala @@ -69,7 +69,6 @@ trait SortedSetOps[A, +CC[X] <: SortedSet[X], +C <: SortedSetOps[A, CC, C]] * @param start The lower-bound (inclusive) of the iterator */ def iteratorFrom(start: A): Iterator[A] - @deprecated("Use `iteratorFrom` instead.", "2.13.0") @`inline` def keysIteratorFrom(start: A): Iterator[A] = iteratorFrom(start) diff --git a/tests/pos-special/stdlib/collection/Stepper.scala b/scala2-library-cc/src/scala/collection/Stepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/Stepper.scala rename to scala2-library-cc/src/scala/collection/Stepper.scala diff --git a/tests/pos-special/stdlib/collection/StepperShape.scala b/scala2-library-cc/src/scala/collection/StepperShape.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StepperShape.scala rename to scala2-library-cc/src/scala/collection/StepperShape.scala diff --git a/tests/pos-special/stdlib/collection/StrictOptimizedIterableOps.scala b/scala2-library-cc/src/scala/collection/StrictOptimizedIterableOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StrictOptimizedIterableOps.scala rename to scala2-library-cc/src/scala/collection/StrictOptimizedIterableOps.scala diff --git a/tests/pos-special/stdlib/collection/StrictOptimizedMapOps.scala b/scala2-library-cc/src/scala/collection/StrictOptimizedMapOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StrictOptimizedMapOps.scala rename to scala2-library-cc/src/scala/collection/StrictOptimizedMapOps.scala diff --git a/tests/pos-special/stdlib/collection/StrictOptimizedSeqOps.scala b/scala2-library-cc/src/scala/collection/StrictOptimizedSeqOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StrictOptimizedSeqOps.scala rename to scala2-library-cc/src/scala/collection/StrictOptimizedSeqOps.scala diff --git a/tests/pos-special/stdlib/collection/StrictOptimizedSetOps.scala b/scala2-library-cc/src/scala/collection/StrictOptimizedSetOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StrictOptimizedSetOps.scala rename to scala2-library-cc/src/scala/collection/StrictOptimizedSetOps.scala diff --git a/tests/pos-special/stdlib/collection/StrictOptimizedSortedMapOps.scala b/scala2-library-cc/src/scala/collection/StrictOptimizedSortedMapOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StrictOptimizedSortedMapOps.scala rename to scala2-library-cc/src/scala/collection/StrictOptimizedSortedMapOps.scala diff --git a/tests/pos-special/stdlib/collection/StrictOptimizedSortedSetOps.scala b/scala2-library-cc/src/scala/collection/StrictOptimizedSortedSetOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StrictOptimizedSortedSetOps.scala rename to scala2-library-cc/src/scala/collection/StrictOptimizedSortedSetOps.scala diff --git a/tests/pos-special/stdlib/collection/StringOps.scala b/scala2-library-cc/src/scala/collection/StringOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/StringOps.scala rename to scala2-library-cc/src/scala/collection/StringOps.scala diff --git a/tests/pos-special/stdlib/collection/StringParsers.scala b/scala2-library-cc/src/scala/collection/StringParsers.scala similarity index 99% rename from tests/pos-special/stdlib/collection/StringParsers.scala rename to scala2-library-cc/src/scala/collection/StringParsers.scala index 47281815da71..75dedab7183c 100644 --- a/tests/pos-special/stdlib/collection/StringParsers.scala +++ b/scala2-library-cc/src/scala/collection/StringParsers.scala @@ -167,7 +167,6 @@ private[scala] object StringParsers { else None } } - //floating point final def checkFloatFormat(format: String): Boolean = { //indices are tracked with a start index which points *at* the first index @@ -194,7 +193,6 @@ private[scala] object StringParsers { rec(from) } - def isHexFloatLiteral(startIndex: Int, endIndex: Int): Boolean = { def isHexDigit(ch: Char) = ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || @@ -232,7 +230,6 @@ private[scala] object StringParsers { val pIndex = format.indexWhere(ch => ch == 'p' || ch == 'P', startIndex) (pIndex <= endIndex) && prefixOK(startIndex, pIndex) && postfixOK(pIndex + 1, endIndex) } - def isDecFloatLiteral(startIndex: Int, endIndex: Int): Boolean = { //invariant: endIndex > startIndex @@ -279,7 +276,6 @@ private[scala] object StringParsers { //count 0x00 to 0x20 as "whitespace", and nothing else val unspacedStart = format.indexWhere(ch => ch.toInt > 0x20) val unspacedEnd = format.lastIndexWhere(ch => ch.toInt > 0x20) + 1 - if (unspacedStart == -1 || unspacedStart >= unspacedEnd || unspacedEnd <= 0) false else { //all formats can have a sign @@ -306,7 +302,6 @@ private[scala] object StringParsers { } } } - @inline def parseFloat(from: String): Option[Float] = if (checkFloatFormat(from)) Some(java.lang.Float.parseFloat(from)) diff --git a/tests/pos-special/stdlib/collection/View.scala b/scala2-library-cc/src/scala/collection/View.scala similarity index 100% rename from tests/pos-special/stdlib/collection/View.scala rename to scala2-library-cc/src/scala/collection/View.scala diff --git a/tests/pos-special/stdlib/collection/WithFilter.scala b/scala2-library-cc/src/scala/collection/WithFilter.scala similarity index 100% rename from tests/pos-special/stdlib/collection/WithFilter.scala rename to scala2-library-cc/src/scala/collection/WithFilter.scala diff --git a/tests/pos-special/stdlib/collection/concurrent/Map.scala b/scala2-library-cc/src/scala/collection/concurrent/Map.scala similarity index 100% rename from tests/pos-special/stdlib/collection/concurrent/Map.scala rename to scala2-library-cc/src/scala/collection/concurrent/Map.scala diff --git a/tests/pos-special/stdlib/collection/concurrent/TrieMap.scala b/scala2-library-cc/src/scala/collection/concurrent/TrieMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/concurrent/TrieMap.scala rename to scala2-library-cc/src/scala/collection/concurrent/TrieMap.scala diff --git a/tests/pos-special/stdlib/collection/convert/AsJavaConverters.scala b/scala2-library-cc/src/scala/collection/convert/AsJavaConverters.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/AsJavaConverters.scala rename to scala2-library-cc/src/scala/collection/convert/AsJavaConverters.scala diff --git a/tests/pos-special/stdlib/collection/convert/AsJavaExtensions.scala b/scala2-library-cc/src/scala/collection/convert/AsJavaExtensions.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/AsJavaExtensions.scala rename to scala2-library-cc/src/scala/collection/convert/AsJavaExtensions.scala diff --git a/tests/pos-special/stdlib/collection/convert/AsScalaConverters.scala b/scala2-library-cc/src/scala/collection/convert/AsScalaConverters.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/AsScalaConverters.scala rename to scala2-library-cc/src/scala/collection/convert/AsScalaConverters.scala diff --git a/tests/pos-special/stdlib/collection/convert/AsScalaExtensions.scala b/scala2-library-cc/src/scala/collection/convert/AsScalaExtensions.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/AsScalaExtensions.scala rename to scala2-library-cc/src/scala/collection/convert/AsScalaExtensions.scala diff --git a/tests/pos-special/stdlib/collection/convert/ImplicitConversions.scala b/scala2-library-cc/src/scala/collection/convert/ImplicitConversions.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/ImplicitConversions.scala rename to scala2-library-cc/src/scala/collection/convert/ImplicitConversions.scala diff --git a/tests/pos-special/stdlib/collection/convert/JavaCollectionWrappers.scala b/scala2-library-cc/src/scala/collection/convert/JavaCollectionWrappers.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/JavaCollectionWrappers.scala rename to scala2-library-cc/src/scala/collection/convert/JavaCollectionWrappers.scala diff --git a/tests/pos-special/stdlib/collection/convert/StreamExtensions.scala b/scala2-library-cc/src/scala/collection/convert/StreamExtensions.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/StreamExtensions.scala rename to scala2-library-cc/src/scala/collection/convert/StreamExtensions.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/ArrayStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/ArrayStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/ArrayStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/ArrayStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/BinaryTreeStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/BinaryTreeStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/BinaryTreeStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/BinaryTreeStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/BitSetStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/BitSetStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/BitSetStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/BitSetStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/ChampStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/ChampStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/ChampStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/ChampStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/InOrderStepperBase.scala b/scala2-library-cc/src/scala/collection/convert/impl/InOrderStepperBase.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/InOrderStepperBase.scala rename to scala2-library-cc/src/scala/collection/convert/impl/InOrderStepperBase.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/IndexedSeqStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/IndexedSeqStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/IndexedSeqStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/IndexedSeqStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/IndexedStepperBase.scala b/scala2-library-cc/src/scala/collection/convert/impl/IndexedStepperBase.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/IndexedStepperBase.scala rename to scala2-library-cc/src/scala/collection/convert/impl/IndexedStepperBase.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/IteratorStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/IteratorStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/IteratorStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/IteratorStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/NumericRangeStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/NumericRangeStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/NumericRangeStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/NumericRangeStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/RangeStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/RangeStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/RangeStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/RangeStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/StringStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/StringStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/StringStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/StringStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/TableStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/TableStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/TableStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/TableStepper.scala diff --git a/tests/pos-special/stdlib/collection/convert/impl/VectorStepper.scala b/scala2-library-cc/src/scala/collection/convert/impl/VectorStepper.scala similarity index 100% rename from tests/pos-special/stdlib/collection/convert/impl/VectorStepper.scala rename to scala2-library-cc/src/scala/collection/convert/impl/VectorStepper.scala diff --git a/tests/pos-special/stdlib/collection/generic/BitOperations.scala b/scala2-library-cc/src/scala/collection/generic/BitOperations.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/BitOperations.scala rename to scala2-library-cc/src/scala/collection/generic/BitOperations.scala diff --git a/tests/pos-special/stdlib/collection/generic/DefaultSerializationProxy.scala b/scala2-library-cc/src/scala/collection/generic/DefaultSerializationProxy.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/DefaultSerializationProxy.scala rename to scala2-library-cc/src/scala/collection/generic/DefaultSerializationProxy.scala diff --git a/tests/pos-special/stdlib/collection/generic/IsIterable.scala b/scala2-library-cc/src/scala/collection/generic/IsIterable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/IsIterable.scala rename to scala2-library-cc/src/scala/collection/generic/IsIterable.scala diff --git a/tests/pos-special/stdlib/collection/generic/IsIterableOnce.scala b/scala2-library-cc/src/scala/collection/generic/IsIterableOnce.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/IsIterableOnce.scala rename to scala2-library-cc/src/scala/collection/generic/IsIterableOnce.scala diff --git a/tests/pos-special/stdlib/collection/generic/IsMap.scala b/scala2-library-cc/src/scala/collection/generic/IsMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/IsMap.scala rename to scala2-library-cc/src/scala/collection/generic/IsMap.scala diff --git a/tests/pos-special/stdlib/collection/generic/IsSeq.scala b/scala2-library-cc/src/scala/collection/generic/IsSeq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/IsSeq.scala rename to scala2-library-cc/src/scala/collection/generic/IsSeq.scala diff --git a/tests/pos-special/stdlib/collection/generic/Subtractable.scala b/scala2-library-cc/src/scala/collection/generic/Subtractable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/Subtractable.scala rename to scala2-library-cc/src/scala/collection/generic/Subtractable.scala diff --git a/tests/pos-special/stdlib/collection/generic/package.scala b/scala2-library-cc/src/scala/collection/generic/package.scala similarity index 100% rename from tests/pos-special/stdlib/collection/generic/package.scala rename to scala2-library-cc/src/scala/collection/generic/package.scala diff --git a/tests/pos-special/stdlib/collection/immutable/ArraySeq.scala b/scala2-library-cc/src/scala/collection/immutable/ArraySeq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/ArraySeq.scala rename to scala2-library-cc/src/scala/collection/immutable/ArraySeq.scala diff --git a/tests/pos-special/stdlib/collection/immutable/BitSet.scala b/scala2-library-cc/src/scala/collection/immutable/BitSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/BitSet.scala rename to scala2-library-cc/src/scala/collection/immutable/BitSet.scala diff --git a/tests/pos-special/stdlib/collection/immutable/ChampCommon.scala b/scala2-library-cc/src/scala/collection/immutable/ChampCommon.scala similarity index 99% rename from tests/pos-special/stdlib/collection/immutable/ChampCommon.scala rename to scala2-library-cc/src/scala/collection/immutable/ChampCommon.scala index fc9bcb022874..3da269dccbd8 100644 --- a/tests/pos-special/stdlib/collection/immutable/ChampCommon.scala +++ b/scala2-library-cc/src/scala/collection/immutable/ChampCommon.scala @@ -113,7 +113,6 @@ private[immutable] abstract class ChampBaseIterator[T <: Node[T]] { // ChampBaseReverseIterator and in convert.impl.ChampStepperBase. // If you change this code, check those also in case they also // need to be modified. - protected var currentValueCursor: Int = 0 protected var currentValueLength: Int = 0 protected var currentValueNode: T = _ diff --git a/tests/pos-special/stdlib/collection/immutable/HashMap.scala b/scala2-library-cc/src/scala/collection/immutable/HashMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/HashMap.scala rename to scala2-library-cc/src/scala/collection/immutable/HashMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/HashSet.scala b/scala2-library-cc/src/scala/collection/immutable/HashSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/HashSet.scala rename to scala2-library-cc/src/scala/collection/immutable/HashSet.scala diff --git a/tests/pos-special/stdlib/collection/immutable/IntMap.scala b/scala2-library-cc/src/scala/collection/immutable/IntMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/IntMap.scala rename to scala2-library-cc/src/scala/collection/immutable/IntMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/Iterable.scala b/scala2-library-cc/src/scala/collection/immutable/Iterable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/Iterable.scala rename to scala2-library-cc/src/scala/collection/immutable/Iterable.scala diff --git a/tests/pos-special/stdlib/collection/immutable/LazyListIterable.scala b/scala2-library-cc/src/scala/collection/immutable/LazyListIterable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/LazyListIterable.scala rename to scala2-library-cc/src/scala/collection/immutable/LazyListIterable.scala diff --git a/tests/pos-special/stdlib/collection/immutable/List.scala b/scala2-library-cc/src/scala/collection/immutable/List.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/List.scala rename to scala2-library-cc/src/scala/collection/immutable/List.scala diff --git a/tests/pos-special/stdlib/collection/immutable/ListMap.scala b/scala2-library-cc/src/scala/collection/immutable/ListMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/ListMap.scala rename to scala2-library-cc/src/scala/collection/immutable/ListMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/ListSet.scala b/scala2-library-cc/src/scala/collection/immutable/ListSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/ListSet.scala rename to scala2-library-cc/src/scala/collection/immutable/ListSet.scala diff --git a/tests/pos-special/stdlib/collection/immutable/LongMap.scala b/scala2-library-cc/src/scala/collection/immutable/LongMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/LongMap.scala rename to scala2-library-cc/src/scala/collection/immutable/LongMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/Map.scala b/scala2-library-cc/src/scala/collection/immutable/Map.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/Map.scala rename to scala2-library-cc/src/scala/collection/immutable/Map.scala diff --git a/tests/pos-special/stdlib/collection/immutable/NumericRange.scala b/scala2-library-cc/src/scala/collection/immutable/NumericRange.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/NumericRange.scala rename to scala2-library-cc/src/scala/collection/immutable/NumericRange.scala diff --git a/tests/pos-special/stdlib/collection/immutable/Queue.scala b/scala2-library-cc/src/scala/collection/immutable/Queue.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/Queue.scala rename to scala2-library-cc/src/scala/collection/immutable/Queue.scala diff --git a/tests/pos-special/stdlib/collection/immutable/Range.scala b/scala2-library-cc/src/scala/collection/immutable/Range.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/Range.scala rename to scala2-library-cc/src/scala/collection/immutable/Range.scala diff --git a/tests/pos-special/stdlib/collection/immutable/RedBlackTree.scala b/scala2-library-cc/src/scala/collection/immutable/RedBlackTree.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/RedBlackTree.scala rename to scala2-library-cc/src/scala/collection/immutable/RedBlackTree.scala diff --git a/tests/pos-special/stdlib/collection/immutable/Seq.scala b/scala2-library-cc/src/scala/collection/immutable/Seq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/Seq.scala rename to scala2-library-cc/src/scala/collection/immutable/Seq.scala diff --git a/tests/pos-special/stdlib/collection/immutable/SeqMap.scala b/scala2-library-cc/src/scala/collection/immutable/SeqMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/SeqMap.scala rename to scala2-library-cc/src/scala/collection/immutable/SeqMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/Set.scala b/scala2-library-cc/src/scala/collection/immutable/Set.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/Set.scala rename to scala2-library-cc/src/scala/collection/immutable/Set.scala diff --git a/tests/pos-special/stdlib/collection/immutable/SortedMap.scala b/scala2-library-cc/src/scala/collection/immutable/SortedMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/SortedMap.scala rename to scala2-library-cc/src/scala/collection/immutable/SortedMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/SortedSet.scala b/scala2-library-cc/src/scala/collection/immutable/SortedSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/SortedSet.scala rename to scala2-library-cc/src/scala/collection/immutable/SortedSet.scala diff --git a/tests/pos-special/stdlib/collection/immutable/StrictOptimizedSeqOps.scala b/scala2-library-cc/src/scala/collection/immutable/StrictOptimizedSeqOps.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/StrictOptimizedSeqOps.scala rename to scala2-library-cc/src/scala/collection/immutable/StrictOptimizedSeqOps.scala diff --git a/tests/pos-special/stdlib/collection/immutable/TreeMap.scala b/scala2-library-cc/src/scala/collection/immutable/TreeMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/TreeMap.scala rename to scala2-library-cc/src/scala/collection/immutable/TreeMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/TreeSeqMap.scala b/scala2-library-cc/src/scala/collection/immutable/TreeSeqMap.scala similarity index 98% rename from tests/pos-special/stdlib/collection/immutable/TreeSeqMap.scala rename to scala2-library-cc/src/scala/collection/immutable/TreeSeqMap.scala index fe194fa9de5a..dc59d21b8b19 100644 --- a/tests/pos-special/stdlib/collection/immutable/TreeSeqMap.scala +++ b/scala2-library-cc/src/scala/collection/immutable/TreeSeqMap.scala @@ -303,7 +303,7 @@ object TreeSeqMap extends MapFactory[TreeSeqMap] { else EmptyByInsertion }.asInstanceOf[TreeSeqMap[K, V]] - def from[K, V](it: collection.IterableOnce[(K, V)]^): TreeSeqMap[K, V] = + def from[K, V](it: collection.IterableOnce[(K, V)]^): TreeSeqMap[K, V] = it match { case om: TreeSeqMap[K, V] => om case _ => (newBuilder[K, V] ++= it).result() @@ -311,10 +311,10 @@ object TreeSeqMap extends MapFactory[TreeSeqMap] { @inline private def increment(ord: Int) = if (ord == Int.MaxValue) Int.MinValue else ord + 1 - def newBuilder[K, V]: mutable.Builder[(K, V), TreeSeqMap[K, V]] = newBuilder(OrderBy.Insertion) - def newBuilder[K, V](orderedBy: OrderBy): mutable.Builder[(K, V), TreeSeqMap[K, V]] = new Builder[K, V](orderedBy) + def newBuilder[K, V]: mutable.Builder[(K, V), TreeSeqMap[K, V]] = newBuilder(OrderBy.Insertion) + def newBuilder[K, V](orderedBy: OrderBy): mutable.Builder[(K, V), TreeSeqMap[K, V]] = new Builder[K, V](orderedBy) - final class Builder[K, V](orderedBy: OrderBy) extends mutable.Builder[(K, V), TreeSeqMap[K, V]] { + final class Builder[K, V](orderedBy: OrderBy) extends mutable.Builder[(K, V), TreeSeqMap[K, V]] { private[this] val bdr = new MapBuilderImpl[K, (Int, V)] private[this] var ong = Ordering.empty[K] private[this] var ord = 0 diff --git a/tests/pos-special/stdlib/collection/immutable/TreeSet.scala b/scala2-library-cc/src/scala/collection/immutable/TreeSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/TreeSet.scala rename to scala2-library-cc/src/scala/collection/immutable/TreeSet.scala diff --git a/tests/pos-special/stdlib/collection/immutable/Vector.scala b/scala2-library-cc/src/scala/collection/immutable/Vector.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/Vector.scala rename to scala2-library-cc/src/scala/collection/immutable/Vector.scala diff --git a/tests/pos-special/stdlib/collection/immutable/VectorMap.scala b/scala2-library-cc/src/scala/collection/immutable/VectorMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/VectorMap.scala rename to scala2-library-cc/src/scala/collection/immutable/VectorMap.scala diff --git a/tests/pos-special/stdlib/collection/immutable/WrappedString.scala b/scala2-library-cc/src/scala/collection/immutable/WrappedString.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/WrappedString.scala rename to scala2-library-cc/src/scala/collection/immutable/WrappedString.scala diff --git a/tests/pos-special/stdlib/collection/immutable/package.scala b/scala2-library-cc/src/scala/collection/immutable/package.scala similarity index 100% rename from tests/pos-special/stdlib/collection/immutable/package.scala rename to scala2-library-cc/src/scala/collection/immutable/package.scala diff --git a/tests/pos-special/stdlib/collection/mutable/AnyRefMap.scala b/scala2-library-cc/src/scala/collection/mutable/AnyRefMap.scala similarity index 91% rename from tests/pos-special/stdlib/collection/mutable/AnyRefMap.scala rename to scala2-library-cc/src/scala/collection/mutable/AnyRefMap.scala index 8f1ac07e725e..480babbf4b91 100644 --- a/tests/pos-special/stdlib/collection/mutable/AnyRefMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/AnyRefMap.scala @@ -43,7 +43,7 @@ import language.experimental.captureChecking * rapidly as 2^30^ is approached. * */ -class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K -> V, initialBufferSize: Int, initBlank: Boolean) +class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K -> V, initialBufferSize: Int, initBlank: Boolean) extends AbstractMap[K, V] with MapOps[K, V, Map, AnyRefMap[K, V]] with StrictOptimizedIterableOps[(K, V), Iterable, AnyRefMap[K, V]] @@ -478,11 +478,11 @@ class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K -> V, init } // The implicit dummy parameter is necessary to distinguish these methods from the base methods they overload (not override) - def map[K2 <: AnyRef, V2](f: ((K, V)) => (K2, V2))(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] = + def map[K2 <: AnyRef, V2](f: ((K, V)) => (K2, V2))(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] = AnyRefMap.from(new View.Map(this, f)) - def flatMap[K2 <: AnyRef, V2](f: ((K, V)) => IterableOnce[(K2, V2)])(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] = + def flatMap[K2 <: AnyRef, V2](f: ((K, V)) => IterableOnce[(K2, V2)])(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] = AnyRefMap.from(new View.FlatMap(this, f)) - def collect[K2 <: AnyRef, V2](pf: PartialFunction[(K, V), (K2, V2)])(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] = + def collect[K2 <: AnyRef, V2](pf: PartialFunction[(K, V), (K2, V2)])(implicit dummy: DummyImplicit): AnyRefMap[K2, V2] = strictOptimizedCollect(AnyRefMap.newBuilder[K2, V2], pf) override def clear(): Unit = { @@ -515,7 +515,7 @@ object AnyRefMap { * * This builder can be reused to create multiple instances. */ - final class AnyRefMapBuilder[K <: AnyRef, V] extends ReusableBuilder[(K, V), AnyRefMap[K, V]] { + final class AnyRefMapBuilder[K <: AnyRef, V] extends ReusableBuilder[(K, V), AnyRefMap[K, V]] { private[collection] var elems: AnyRefMap[K, V] = new AnyRefMap[K, V] def addOne(entry: (K, V)): this.type = { elems += entry @@ -527,11 +527,11 @@ object AnyRefMap { } /** Creates a new `AnyRefMap` with zero or more key/value pairs. */ - def apply[K <: AnyRef, V](elems: (K, V)*): AnyRefMap[K, V] = buildFromIterableOnce(elems) + def apply[K <: AnyRef, V](elems: (K, V)*): AnyRefMap[K, V] = buildFromIterableOnce(elems) - def newBuilder[K <: AnyRef, V]: ReusableBuilder[(K, V), AnyRefMap[K, V]] = new AnyRefMapBuilder[K, V] + def newBuilder[K <: AnyRef, V]: ReusableBuilder[(K, V), AnyRefMap[K, V]] = new AnyRefMapBuilder[K, V] - private def buildFromIterableOnce[K <: AnyRef, V](elems: IterableOnce[(K, V)]^): AnyRefMap[K, V] = { + private def buildFromIterableOnce[K <: AnyRef, V](elems: IterableOnce[(K, V)]^): AnyRefMap[K, V] = { var sz = elems.knownSize if(sz < 0) sz = 4 val arm = new AnyRefMap[K, V](sz * 2) @@ -541,10 +541,10 @@ object AnyRefMap { } /** Creates a new empty `AnyRefMap`. */ - def empty[K <: AnyRef, V]: AnyRefMap[K, V] = new AnyRefMap[K, V] + def empty[K <: AnyRef, V]: AnyRefMap[K, V] = new AnyRefMap[K, V] /** Creates a new empty `AnyRefMap` with the supplied default */ - def withDefault[K <: AnyRef, V](default: K -> V): AnyRefMap[K, V] = new AnyRefMap[K, V](default) + def withDefault[K <: AnyRef, V](default: K -> V): AnyRefMap[K, V] = new AnyRefMap[K, V](default) /** Creates a new `AnyRefMap` from an existing source collection. A source collection * which is already an `AnyRefMap` gets cloned. @@ -554,7 +554,7 @@ object AnyRefMap { * @tparam V the type of the values * @return a new `AnyRefMap` with the elements of `source` */ - def from[K <: AnyRef, V](source: IterableOnce[(K, V)]^): AnyRefMap[K, V] = source match { + def from[K <: AnyRef, V](source: IterableOnce[(K, V)]^): AnyRefMap[K, V] = source match { case source: AnyRefMap[_, _] => source.clone().asInstanceOf[AnyRefMap[K, V]] case _ => buildFromIterableOnce(source) } @@ -562,7 +562,7 @@ object AnyRefMap { /** Creates a new `AnyRefMap` from arrays of keys and values. * Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`. */ - def fromZip[K <: AnyRef, V](keys: Array[K], values: Array[V]): AnyRefMap[K, V] = { + def fromZip[K <: AnyRef, V](keys: Array[K], values: Array[V]): AnyRefMap[K, V] = { val sz = math.min(keys.length, values.length) val arm = new AnyRefMap[K, V](sz * 2) var i = 0 @@ -574,7 +574,7 @@ object AnyRefMap { /** Creates a new `AnyRefMap` from keys and values. * Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`. */ - def fromZip[K <: AnyRef, V](keys: Iterable[K]^, values: Iterable[V]^): AnyRefMap[K, V] = { + def fromZip[K <: AnyRef, V](keys: Iterable[K]^, values: Iterable[V]^): AnyRefMap[K, V] = { val sz = math.min(keys.size, values.size) val arm = new AnyRefMap[K, V](sz * 2) val ki = keys.iterator @@ -584,7 +584,7 @@ object AnyRefMap { arm } - implicit def toFactory[K <: AnyRef, V](dummy: AnyRefMap.type): Factory[(K, V), AnyRefMap[K, V]] = ToFactory.asInstanceOf[Factory[(K, V), AnyRefMap[K, V]]] + implicit def toFactory[K <: AnyRef, V](dummy: AnyRefMap.type): Factory[(K, V), AnyRefMap[K, V]] = ToFactory.asInstanceOf[Factory[(K, V), AnyRefMap[K, V]]] @SerialVersionUID(3L) private[this] object ToFactory extends Factory[(AnyRef, AnyRef), AnyRefMap[AnyRef, AnyRef]] with Serializable { @@ -592,12 +592,12 @@ object AnyRefMap { def newBuilder: Builder[(AnyRef, AnyRef), AnyRefMap[AnyRef, AnyRef]] = AnyRefMap.newBuilder[AnyRef, AnyRef] } - implicit def toBuildFrom[K <: AnyRef, V](factory: AnyRefMap.type): BuildFrom[Any, (K, V), AnyRefMap[K, V]] = ToBuildFrom.asInstanceOf[BuildFrom[Any, (K, V), AnyRefMap[K, V]]] + implicit def toBuildFrom[K <: AnyRef, V](factory: AnyRefMap.type): BuildFrom[Any, (K, V), AnyRefMap[K, V]] = ToBuildFrom.asInstanceOf[BuildFrom[Any, (K, V), AnyRefMap[K, V]]] private[this] object ToBuildFrom extends BuildFrom[Any, (AnyRef, AnyRef), AnyRefMap[AnyRef, AnyRef]] { def fromSpecific(from: Any)(it: IterableOnce[(AnyRef, AnyRef)]^) = AnyRefMap.from(it) def newBuilder(from: Any) = AnyRefMap.newBuilder[AnyRef, AnyRef] } - implicit def iterableFactory[K <: AnyRef, V]: Factory[(K, V), AnyRefMap[K, V]] = toFactory[K, V](this) - implicit def buildFromAnyRefMap[K <: AnyRef, V]: BuildFrom[AnyRefMap[_, _], (K, V), AnyRefMap[K, V]] = toBuildFrom(this) + implicit def iterableFactory[K <: AnyRef, V]: Factory[(K, V), AnyRefMap[K, V]] = toFactory[K, V](this) + implicit def buildFromAnyRefMap[K <: AnyRef, V]: BuildFrom[AnyRefMap[_, _], (K, V), AnyRefMap[K, V]] = toBuildFrom(this) } diff --git a/tests/pos-special/stdlib/collection/mutable/ArrayBuffer.scala b/scala2-library-cc/src/scala/collection/mutable/ArrayBuffer.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/ArrayBuffer.scala rename to scala2-library-cc/src/scala/collection/mutable/ArrayBuffer.scala diff --git a/tests/pos-special/stdlib/collection/mutable/ArrayBuilder.scala b/scala2-library-cc/src/scala/collection/mutable/ArrayBuilder.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/ArrayBuilder.scala rename to scala2-library-cc/src/scala/collection/mutable/ArrayBuilder.scala diff --git a/tests/pos-special/stdlib/collection/mutable/ArrayDeque.scala b/scala2-library-cc/src/scala/collection/mutable/ArrayDeque.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/ArrayDeque.scala rename to scala2-library-cc/src/scala/collection/mutable/ArrayDeque.scala diff --git a/tests/pos-special/stdlib/collection/mutable/ArraySeq.scala b/scala2-library-cc/src/scala/collection/mutable/ArraySeq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/ArraySeq.scala rename to scala2-library-cc/src/scala/collection/mutable/ArraySeq.scala diff --git a/tests/pos-special/stdlib/collection/mutable/BitSet.scala b/scala2-library-cc/src/scala/collection/mutable/BitSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/BitSet.scala rename to scala2-library-cc/src/scala/collection/mutable/BitSet.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Buffer.scala b/scala2-library-cc/src/scala/collection/mutable/Buffer.scala similarity index 99% rename from tests/pos-special/stdlib/collection/mutable/Buffer.scala rename to scala2-library-cc/src/scala/collection/mutable/Buffer.scala index 1f7fc76972a2..f9aa9cf28c72 100644 --- a/tests/pos-special/stdlib/collection/mutable/Buffer.scala +++ b/scala2-library-cc/src/scala/collection/mutable/Buffer.scala @@ -104,7 +104,6 @@ trait Buffer[A] @throws[IndexOutOfBoundsException] @throws[IllegalArgumentException] def remove(idx: Int, count: Int): Unit - /** Removes a single element from this buffer, at its first occurrence. * If the buffer does not contain that element, it is unchanged. * diff --git a/tests/pos-special/stdlib/collection/mutable/Builder.scala b/scala2-library-cc/src/scala/collection/mutable/Builder.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Builder.scala rename to scala2-library-cc/src/scala/collection/mutable/Builder.scala diff --git a/tests/pos-special/stdlib/collection/mutable/CheckedIndexedSeqView.scala b/scala2-library-cc/src/scala/collection/mutable/CheckedIndexedSeqView.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/CheckedIndexedSeqView.scala rename to scala2-library-cc/src/scala/collection/mutable/CheckedIndexedSeqView.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Cloneable.scala b/scala2-library-cc/src/scala/collection/mutable/Cloneable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Cloneable.scala rename to scala2-library-cc/src/scala/collection/mutable/Cloneable.scala diff --git a/tests/pos-special/stdlib/collection/mutable/CollisionProofHashMap.scala b/scala2-library-cc/src/scala/collection/mutable/CollisionProofHashMap.scala similarity index 95% rename from tests/pos-special/stdlib/collection/mutable/CollisionProofHashMap.scala rename to scala2-library-cc/src/scala/collection/mutable/CollisionProofHashMap.scala index 0679ab7be201..ff3bab1dd818 100644 --- a/tests/pos-special/stdlib/collection/mutable/CollisionProofHashMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/CollisionProofHashMap.scala @@ -33,7 +33,7 @@ import language.experimental.captureChecking * @define mayNotTerminateInf * @define willNotTerminateInf */ -final class CollisionProofHashMap[K, V](initialCapacity: Int, loadFactor: Double)(implicit ordering: Ordering[K]) +final class CollisionProofHashMap[K, V](initialCapacity: Int, loadFactor: Double)(implicit ordering: Ordering[K]) extends AbstractMap[K, V] with MapOps[K, V, Map, CollisionProofHashMap[K, V]] //-- with StrictOptimizedIterableOps[(K, V), Iterable, CollisionProofHashMap[K, V]] @@ -744,17 +744,17 @@ final class CollisionProofHashMap[K, V](initialCapacity: Int, loadFactor: Doubl object CollisionProofHashMap extends SortedMapFactory[CollisionProofHashMap] { private[collection] final val ordMsg = "No implicit Ordering[${K2}] found to build a CollisionProofHashMap[${K2}, ${V2}]. You may want to upcast to a Map[${K}, ${V}] first by calling `unsorted`." - def from[K : Ordering, V](it: scala.collection.IterableOnce[(K, V)]^): CollisionProofHashMap[K, V] = { + def from[K : Ordering, V](it: scala.collection.IterableOnce[(K, V)]^): CollisionProofHashMap[K, V] = { val k = it.knownSize val cap = if(k > 0) ((k + 1).toDouble / defaultLoadFactor).toInt else defaultInitialCapacity new CollisionProofHashMap[K, V](cap, defaultLoadFactor) ++= it } - def empty[K : Ordering, V]: CollisionProofHashMap[K, V] = new CollisionProofHashMap[K, V] + def empty[K : Ordering, V]: CollisionProofHashMap[K, V] = new CollisionProofHashMap[K, V] - def newBuilder[K : Ordering, V]: Builder[(K, V), CollisionProofHashMap[K, V]] = newBuilder(defaultInitialCapacity, defaultLoadFactor) + def newBuilder[K : Ordering, V]: Builder[(K, V), CollisionProofHashMap[K, V]] = newBuilder(defaultInitialCapacity, defaultLoadFactor) - def newBuilder[K : Ordering, V](initialCapacity: Int, loadFactor: Double): Builder[(K, V), CollisionProofHashMap[K, V]] = + def newBuilder[K : Ordering, V](initialCapacity: Int, loadFactor: Double): Builder[(K, V), CollisionProofHashMap[K, V]] = new GrowableBuilder[(K, V), CollisionProofHashMap[K, V]](new CollisionProofHashMap[K, V](initialCapacity, loadFactor)) { override def sizeHint(size: Int) = elems.sizeHint(size) } @@ -766,7 +766,7 @@ object CollisionProofHashMap extends SortedMapFactory[CollisionProofHashMap] { final def defaultInitialCapacity: Int = 16 @SerialVersionUID(3L) - private final class DeserializationFactory[K, V](val tableLength: Int, val loadFactor: Double, val ordering: Ordering[K]) extends Factory[(K, V), CollisionProofHashMap[K, V]] with Serializable { + private final class DeserializationFactory[K, V](val tableLength: Int, val loadFactor: Double, val ordering: Ordering[K]) extends Factory[(K, V), CollisionProofHashMap[K, V]] with Serializable { def fromSpecific(it: IterableOnce[(K, V)]^): CollisionProofHashMap[K, V] = new CollisionProofHashMap[K, V](tableLength, loadFactor)(ordering) ++= it def newBuilder: Builder[(K, V), CollisionProofHashMap[K, V]] = CollisionProofHashMap.newBuilder(tableLength, loadFactor)(ordering) } @@ -789,7 +789,7 @@ object CollisionProofHashMap extends SortedMapFactory[CollisionProofHashMap] { /////////////////////////// Red-Black Tree Node - final class RBNode[K, V](var key: K, var hash: Int, var value: V, var red: Boolean, var left: RBNode[K, V], var right: RBNode[K, V], var parent: RBNode[K, V]) extends Node { + final class RBNode[K, V](var key: K, var hash: Int, var value: V, var red: Boolean, var left: RBNode[K, V], var right: RBNode[K, V], var parent: RBNode[K, V]) extends Node { override def toString: String = "RBNode(" + key + ", " + hash + ", " + value + ", " + red + ", " + left + ", " + right + ")" @tailrec def getNode(k: K, h: Int)(implicit ord: Ordering[K]): RBNode[K, V] = { @@ -820,17 +820,17 @@ object CollisionProofHashMap extends SortedMapFactory[CollisionProofHashMap] { } } - @`inline` private def leaf[A, B](key: A, hash: Int, value: B, red: Boolean, parent: RBNode[A, B]): RBNode[A, B] = + @`inline` private def leaf[A, B](key: A, hash: Int, value: B, red: Boolean, parent: RBNode[A, B]): RBNode[A, B] = new RBNode(key, hash, value, red, null, null, parent) - @tailrec private def minNodeNonNull[A, B](node: RBNode[A, B]): RBNode[A, B] = + @tailrec private def minNodeNonNull[A, B](node: RBNode[A, B]): RBNode[A, B] = if (node.left eq null) node else minNodeNonNull(node.left) /** * Returns the node that follows `node` in an in-order tree traversal. If `node` has the maximum key (and is, * therefore, the last node), this method returns `null`. */ - private def successor[A, B](node: RBNode[A, B]): RBNode[A, B] = { + private def successor[A, B](node: RBNode[A, B]): RBNode[A, B] = { if (node.right ne null) minNodeNonNull(node.right) else { var x = node @@ -843,7 +843,7 @@ object CollisionProofHashMap extends SortedMapFactory[CollisionProofHashMap] { } } - private final class RBNodesIterator[A, B](tree: RBNode[A, B])(implicit @unused ord: Ordering[A]) extends AbstractIterator[RBNode[A, B]] { + private final class RBNodesIterator[A, B](tree: RBNode[A, B])(implicit @unused ord: Ordering[A]) extends AbstractIterator[RBNode[A, B]] { private[this] var nextNode: RBNode[A, B] = if(tree eq null) null else minNodeNonNull(tree) def hasNext: Boolean = nextNode ne null @@ -859,7 +859,7 @@ object CollisionProofHashMap extends SortedMapFactory[CollisionProofHashMap] { /////////////////////////// Linked List Node - private final class LLNode[K, V](var key: K, var hash: Int, var value: V, var next: LLNode[K, V]) extends Node { + private final class LLNode[K, V](var key: K, var hash: Int, var value: V, var next: LLNode[K, V]) extends Node { override def toString = s"LLNode($key, $value, $hash) -> $next" private[this] def eq(a: Any, b: Any): Boolean = diff --git a/tests/pos-special/stdlib/collection/mutable/Growable.scala b/scala2-library-cc/src/scala/collection/mutable/Growable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Growable.scala rename to scala2-library-cc/src/scala/collection/mutable/Growable.scala diff --git a/tests/pos-special/stdlib/collection/mutable/GrowableBuilder.scala b/scala2-library-cc/src/scala/collection/mutable/GrowableBuilder.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/GrowableBuilder.scala rename to scala2-library-cc/src/scala/collection/mutable/GrowableBuilder.scala diff --git a/tests/pos-special/stdlib/collection/mutable/HashMap.scala b/scala2-library-cc/src/scala/collection/mutable/HashMap.scala similarity index 97% rename from tests/pos-special/stdlib/collection/mutable/HashMap.scala rename to scala2-library-cc/src/scala/collection/mutable/HashMap.scala index 1ba651b47819..89a9f3f186f7 100644 --- a/tests/pos-special/stdlib/collection/mutable/HashMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/HashMap.scala @@ -33,7 +33,7 @@ import language.experimental.captureChecking * @define willNotTerminateInf */ @deprecatedInheritance("HashMap will be made final; use .withDefault for the common use case of computing a default value", "2.13.0") -class HashMap[K, V](initialCapacity: Int, loadFactor: Double) +class HashMap[K, V](initialCapacity: Int, loadFactor: Double) extends AbstractMap[K, V] with MapOps[K, V, HashMap, HashMap[K, V]] with StrictOptimizedIterableOps[(K, V), Iterable, HashMap[K, V]] @@ -597,17 +597,17 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Double) @SerialVersionUID(3L) object HashMap extends MapFactory[HashMap] { - def empty[K, V]: HashMap[K, V] = new HashMap[K, V] + def empty[K, V]: HashMap[K, V] = new HashMap[K, V] - def from[K, V](it: collection.IterableOnce[(K, V)]^): HashMap[K, V] = { + def from[K, V](it: collection.IterableOnce[(K, V)]^): HashMap[K, V] = { val k = it.knownSize val cap = if(k > 0) ((k + 1).toDouble / defaultLoadFactor).toInt else defaultInitialCapacity new HashMap[K, V](cap, defaultLoadFactor).addAll(it) } - def newBuilder[K, V]: Builder[(K, V), HashMap[K, V]] = newBuilder(defaultInitialCapacity, defaultLoadFactor) + def newBuilder[K, V]: Builder[(K, V), HashMap[K, V]] = newBuilder(defaultInitialCapacity, defaultLoadFactor) - def newBuilder[K, V](initialCapacity: Int, loadFactor: Double): Builder[(K, V), HashMap[K, V]] = + def newBuilder[K, V](initialCapacity: Int, loadFactor: Double): Builder[(K, V), HashMap[K, V]] = new GrowableBuilder[(K, V), HashMap[K, V]](new HashMap[K, V](initialCapacity, loadFactor)) { override def sizeHint(size: Int) = elems.sizeHint(size) } @@ -619,7 +619,7 @@ object HashMap extends MapFactory[HashMap] { final def defaultInitialCapacity: Int = 16 @SerialVersionUID(3L) - private final class DeserializationFactory[K, V](val tableLength: Int, val loadFactor: Double) extends Factory[(K, V), HashMap[K, V]] with Serializable { + private final class DeserializationFactory[K, V](val tableLength: Int, val loadFactor: Double) extends Factory[(K, V), HashMap[K, V]] with Serializable { def fromSpecific(it: IterableOnce[(K, V)]^): HashMap[K, V] = new HashMap[K, V](tableLength, loadFactor).addAll(it) def newBuilder: Builder[(K, V), HashMap[K, V]] = HashMap.newBuilder(tableLength, loadFactor) } diff --git a/tests/pos-special/stdlib/collection/mutable/HashSet.scala b/scala2-library-cc/src/scala/collection/mutable/HashSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/HashSet.scala rename to scala2-library-cc/src/scala/collection/mutable/HashSet.scala diff --git a/tests/pos-special/stdlib/collection/mutable/HashTable.scala b/scala2-library-cc/src/scala/collection/mutable/HashTable.scala similarity index 99% rename from tests/pos-special/stdlib/collection/mutable/HashTable.scala rename to scala2-library-cc/src/scala/collection/mutable/HashTable.scala index 64af941eac1f..461df6cea22c 100644 --- a/tests/pos-special/stdlib/collection/mutable/HashTable.scala +++ b/scala2-library-cc/src/scala/collection/mutable/HashTable.scala @@ -412,7 +412,7 @@ private[collection] object HashTable { /** Class used internally. */ -private[collection] trait HashEntry[A, E <: HashEntry[A, E]] { +private[collection] trait HashEntry[A, E <: HashEntry[A, E]] { val key: A var next: E = _ } diff --git a/tests/pos-special/stdlib/collection/mutable/ImmutableBuilder.scala b/scala2-library-cc/src/scala/collection/mutable/ImmutableBuilder.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/ImmutableBuilder.scala rename to scala2-library-cc/src/scala/collection/mutable/ImmutableBuilder.scala diff --git a/tests/pos-special/stdlib/collection/mutable/IndexedSeq.scala b/scala2-library-cc/src/scala/collection/mutable/IndexedSeq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/IndexedSeq.scala rename to scala2-library-cc/src/scala/collection/mutable/IndexedSeq.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Iterable.scala b/scala2-library-cc/src/scala/collection/mutable/Iterable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Iterable.scala rename to scala2-library-cc/src/scala/collection/mutable/Iterable.scala diff --git a/tests/pos-special/stdlib/collection/mutable/LinkedHashMap.scala b/scala2-library-cc/src/scala/collection/mutable/LinkedHashMap.scala similarity index 98% rename from tests/pos-special/stdlib/collection/mutable/LinkedHashMap.scala rename to scala2-library-cc/src/scala/collection/mutable/LinkedHashMap.scala index 528c39e49bdf..e3fc9d6aefd6 100644 --- a/tests/pos-special/stdlib/collection/mutable/LinkedHashMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/LinkedHashMap.scala @@ -34,7 +34,7 @@ import language.experimental.captureChecking * @define orderDependentFold */ @deprecatedInheritance("LinkedHashMap will be made final; use .withDefault for the common use case of computing a default value", "2.13.11") -class LinkedHashMap[K, V] +class LinkedHashMap[K, V] extends AbstractMap[K, V] with SeqMap[K, V] with MapOps[K, V, LinkedHashMap, LinkedHashMap[K, V]] @@ -477,20 +477,20 @@ class LinkedHashMap[K, V] @SerialVersionUID(3L) object LinkedHashMap extends MapFactory[LinkedHashMap] { - def empty[K, V] = new LinkedHashMap[K, V] + def empty[K, V] = new LinkedHashMap[K, V] - def from[K, V](it: collection.IterableOnce[(K, V)]^) = { + def from[K, V](it: collection.IterableOnce[(K, V)]^) = { val newlhm = empty[K, V] newlhm.sizeHint(it.knownSize) newlhm.addAll(it) newlhm } - def newBuilder[K, V] = new GrowableBuilder(empty[K, V]) + def newBuilder[K, V] = new GrowableBuilder(empty[K, V]) /** Class for the linked hash map entry, used internally. */ - private[mutable] final class LinkedEntry[K, V](val key: K, val hash: Int, var value: V) { + private[mutable] final class LinkedEntry[K, V](val key: K, val hash: Int, var value: V) { var earlier: LinkedEntry[K, V] = null var later: LinkedEntry[K, V] = null var next: LinkedEntry[K, V] = null diff --git a/tests/pos-special/stdlib/collection/mutable/LinkedHashSet.scala b/scala2-library-cc/src/scala/collection/mutable/LinkedHashSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/LinkedHashSet.scala rename to scala2-library-cc/src/scala/collection/mutable/LinkedHashSet.scala diff --git a/tests/pos-special/stdlib/collection/mutable/ListBuffer.scala b/scala2-library-cc/src/scala/collection/mutable/ListBuffer.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/ListBuffer.scala rename to scala2-library-cc/src/scala/collection/mutable/ListBuffer.scala diff --git a/tests/pos-special/stdlib/collection/mutable/ListMap.scala b/scala2-library-cc/src/scala/collection/mutable/ListMap.scala similarity index 90% rename from tests/pos-special/stdlib/collection/mutable/ListMap.scala rename to scala2-library-cc/src/scala/collection/mutable/ListMap.scala index e4f9322050d5..26e904e271a1 100644 --- a/tests/pos-special/stdlib/collection/mutable/ListMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/ListMap.scala @@ -31,7 +31,7 @@ import language.experimental.captureChecking * @define orderDependentFold */ @deprecated("Use an immutable.ListMap assigned to a var instead of mutable.ListMap", "2.13.0") -class ListMap[K, V] +class ListMap[K, V] extends AbstractMap[K, V] with MapOps[K, V, ListMap, ListMap[K, V]] with StrictOptimizedIterableOps[(K, V), Iterable, ListMap[K, V]] @@ -77,7 +77,7 @@ class ListMap[K, V] @SerialVersionUID(3L) @deprecated("Use an immutable.ListMap assigned to a var instead of mutable.ListMap", "2.13.0") object ListMap extends MapFactory[ListMap] { - def empty[K, V]: ListMap[K, V] = new ListMap[K, V] - def from[K, V](it: IterableOnce[(K, V)]^): ListMap[K,V] = Growable.from(empty[K, V], it) - def newBuilder[K, V]: Builder[(K, V), ListMap[K,V]] = new GrowableBuilder(empty[K, V]) + def empty[K, V]: ListMap[K, V] = new ListMap[K, V] + def from[K, V](it: IterableOnce[(K, V)]^): ListMap[K,V] = Growable.from(empty[K, V], it) + def newBuilder[K, V]: Builder[(K, V), ListMap[K,V]] = new GrowableBuilder(empty[K, V]) } diff --git a/tests/pos-special/stdlib/collection/mutable/LongMap.scala b/scala2-library-cc/src/scala/collection/mutable/LongMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/LongMap.scala rename to scala2-library-cc/src/scala/collection/mutable/LongMap.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Map.scala b/scala2-library-cc/src/scala/collection/mutable/Map.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Map.scala rename to scala2-library-cc/src/scala/collection/mutable/Map.scala diff --git a/tests/pos-special/stdlib/collection/mutable/MultiMap.scala b/scala2-library-cc/src/scala/collection/mutable/MultiMap.scala similarity index 98% rename from tests/pos-special/stdlib/collection/mutable/MultiMap.scala rename to scala2-library-cc/src/scala/collection/mutable/MultiMap.scala index 93b0d6ae4d73..0b250a5548ef 100644 --- a/tests/pos-special/stdlib/collection/mutable/MultiMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/MultiMap.scala @@ -52,7 +52,7 @@ import language.experimental.captureChecking * @define Coll `MultiMap` */ @deprecated("Use a scala.collection.mutable.MultiDict in the scala-collection-contrib module", "2.13.0") -trait MultiMap[K, V] extends Map[K, Set[V]] { +trait MultiMap[K, V] extends Map[K, Set[V]] { /** Creates a new set. * * Classes that use this trait as a mixin can override this method diff --git a/tests/pos-special/stdlib/collection/mutable/MutationTracker.scala b/scala2-library-cc/src/scala/collection/mutable/MutationTracker.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/MutationTracker.scala rename to scala2-library-cc/src/scala/collection/mutable/MutationTracker.scala diff --git a/tests/pos-special/stdlib/collection/mutable/OpenHashMap.scala b/scala2-library-cc/src/scala/collection/mutable/OpenHashMap.scala similarity index 97% rename from tests/pos-special/stdlib/collection/mutable/OpenHashMap.scala rename to scala2-library-cc/src/scala/collection/mutable/OpenHashMap.scala index 978245d5bffb..d29be3ffea5e 100644 --- a/tests/pos-special/stdlib/collection/mutable/OpenHashMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/OpenHashMap.scala @@ -26,10 +26,10 @@ import language.experimental.captureChecking @SerialVersionUID(3L) object OpenHashMap extends MapFactory[OpenHashMap] { - def empty[K, V] = new OpenHashMap[K, V] - def from[K, V](it: IterableOnce[(K, V)]^): OpenHashMap[K,V] = empty ++= it + def empty[K, V] = new OpenHashMap[K, V] + def from[K, V](it: IterableOnce[(K, V)]^): OpenHashMap[K,V] = empty ++= it - def newBuilder[K, V]: Builder[(K, V), OpenHashMap[K,V]] = + def newBuilder[K, V]: Builder[(K, V), OpenHashMap[K,V]] = new GrowableBuilder[(K, V), OpenHashMap[K, V]](empty) /** A hash table entry. @@ -39,7 +39,7 @@ object OpenHashMap extends MapFactory[OpenHashMap] { * If its `key` is not the default value of type `Key`, the entry is occupied. * If the entry is occupied, `hash` contains the hash value of `key`. */ - final private class OpenEntry[Key, Value](var key: Key, + final private class OpenEntry[Key, Value](var key: Key, var hash: Int, var value: Option[Value]) @@ -62,7 +62,7 @@ object OpenHashMap extends MapFactory[OpenHashMap] { * @define willNotTerminateInf */ @deprecated("Use HashMap or one of the specialized versions (LongMap, AnyRefMap) instead of OpenHashMap", "2.13.0") -class OpenHashMap[Key, Value](initialSize : Int) +class OpenHashMap[Key, Value](initialSize : Int) extends AbstractMap[Key, Value] with MapOps[Key, Value, OpenHashMap, OpenHashMap[Key, Value]] with StrictOptimizedIterableOps[(Key, Value), Iterable, OpenHashMap[Key, Value]] diff --git a/tests/pos-special/stdlib/collection/mutable/PriorityQueue.scala b/scala2-library-cc/src/scala/collection/mutable/PriorityQueue.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/PriorityQueue.scala rename to scala2-library-cc/src/scala/collection/mutable/PriorityQueue.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Queue.scala b/scala2-library-cc/src/scala/collection/mutable/Queue.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Queue.scala rename to scala2-library-cc/src/scala/collection/mutable/Queue.scala diff --git a/tests/pos-special/stdlib/collection/mutable/RedBlackTree.scala b/scala2-library-cc/src/scala/collection/mutable/RedBlackTree.scala similarity index 93% rename from tests/pos-special/stdlib/collection/mutable/RedBlackTree.scala rename to scala2-library-cc/src/scala/collection/mutable/RedBlackTree.scala index 4e079bca3245..f808a4257eef 100644 --- a/tests/pos-special/stdlib/collection/mutable/RedBlackTree.scala +++ b/scala2-library-cc/src/scala/collection/mutable/RedBlackTree.scala @@ -32,25 +32,25 @@ private[collection] object RedBlackTree { // Therefore, while obtaining the size of the whole tree is O(1), knowing the number of entries inside a range is O(n) // on the size of the range. - final class Tree[A, B](var root: Node[A, B], var size: Int) { + final class Tree[A, B](var root: Node[A, B], var size: Int) { def treeCopy(): Tree[A, B] = new Tree(copyTree(root), size) } - final class Node[A, B](var key: A, var value: B, var red: Boolean, var left: Node[A, B], var right: Node[A, B], var parent: Node[A, B]) { + final class Node[A, B](var key: A, var value: B, var red: Boolean, var left: Node[A, B], var right: Node[A, B], var parent: Node[A, B]) { override def toString: String = "Node(" + key + ", " + value + ", " + red + ", " + left + ", " + right + ")" } object Tree { - def empty[A, B]: Tree[A, B] = new Tree(null, 0) + def empty[A, B]: Tree[A, B] = new Tree(null, 0) } object Node { - @`inline` def apply[A, B](key: A, value: B, red: Boolean, + @`inline` def apply[A, B](key: A, value: B, red: Boolean, left: Node[A, B], right: Node[A, B], parent: Node[A, B]): Node[A, B] = new Node(key, value, red, left, right, parent) - @`inline` def leaf[A, B](key: A, value: B, red: Boolean, parent: Node[A, B]): Node[A, B] = + @`inline` def leaf[A, B](key: A, value: B, red: Boolean, parent: Node[A, B]): Node[A, B] = new Node(key, value, red, null, null, parent) def unapply[A, B](t: Node[A, B]) = Some((t.key, t.value, t.left, t.right, t.parent)) @@ -181,7 +181,7 @@ private[collection] object RedBlackTree { // ---- insertion ---- - def insert[A, B](tree: Tree[A, B], key: A, value: B)(implicit ord: Ordering[A]): Unit = { + def insert[A, B](tree: Tree[A, B], key: A, value: B)(implicit ord: Ordering[A]): Unit = { var y: Node[A, B] = null var x = tree.root var cmp = 1 @@ -477,16 +477,16 @@ private[collection] object RedBlackTree { if (node.right ne null) transformNodeNonNull(node.right, f) } - def iterator[A: Ordering, B](tree: Tree[A, B], start: Option[A] = None, end: Option[A] = None): Iterator[(A, B)] = + def iterator[A: Ordering, B](tree: Tree[A, B], start: Option[A] = None, end: Option[A] = None): Iterator[(A, B)] = new EntriesIterator(tree, start, end) def keysIterator[A: Ordering](tree: Tree[A, _], start: Option[A] = None, end: Option[A] = None): Iterator[A] = new KeysIterator(tree, start, end) - def valuesIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A] = None, end: Option[A] = None): Iterator[B] = + def valuesIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A] = None, end: Option[A] = None): Iterator[B] = new ValuesIterator(tree, start, end) - private[this] abstract class TreeIterator[A, B, R](tree: Tree[A, B], start: Option[A], end: Option[A]) + private[this] abstract class TreeIterator[A, B, R](tree: Tree[A, B], start: Option[A], end: Option[A]) (implicit ord: Ordering[A]) extends AbstractIterator[R] { protected def nextResult(node: Node[A, B]): R @@ -514,19 +514,19 @@ private[collection] object RedBlackTree { setNullIfAfterEnd() } - private[this] final class EntriesIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A], end: Option[A]) + private[this] final class EntriesIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A], end: Option[A]) extends TreeIterator[A, B, (A, B)](tree, start, end) { def nextResult(node: Node[A, B]) = (node.key, node.value) } - private[this] final class KeysIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A], end: Option[A]) + private[this] final class KeysIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A], end: Option[A]) extends TreeIterator[A, B, A](tree, start, end) { def nextResult(node: Node[A, B]) = node.key } - private[this] final class ValuesIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A], end: Option[A]) + private[this] final class ValuesIterator[A: Ordering, B](tree: Tree[A, B], start: Option[A], end: Option[A]) extends TreeIterator[A, B, B](tree, start, end) { def nextResult(node: Node[A, B]) = node.value @@ -623,7 +623,7 @@ private[collection] object RedBlackTree { } /** Build a Tree suitable for a TreeMap from an ordered sequence of key/value pairs */ - def fromOrderedEntries[A, B](xs: Iterator[(A, B)], size: Int): Tree[A, B] = { + def fromOrderedEntries[A, B](xs: Iterator[(A, B)], size: Int): Tree[A, B] = { val maxUsedDepth = 32 - Integer.numberOfLeadingZeros(size) // maximum depth of non-leaf nodes def f(level: Int, size: Int): Node[A, B] = size match { case 0 => null @@ -643,7 +643,7 @@ private[collection] object RedBlackTree { new Tree(f(1, size), size) } - def copyTree[A, B](n: Node[A, B]): Node[A, B] = + def copyTree[A, B](n: Node[A, B]): Node[A, B] = if(n eq null) null else { val c = new Node(n.key, n.value, n.red, copyTree(n.left), copyTree(n.right), null) if(c.left != null) c.left.parent = c diff --git a/tests/pos-special/stdlib/collection/mutable/ReusableBuilder.scala b/scala2-library-cc/src/scala/collection/mutable/ReusableBuilder.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/ReusableBuilder.scala rename to scala2-library-cc/src/scala/collection/mutable/ReusableBuilder.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Seq.scala b/scala2-library-cc/src/scala/collection/mutable/Seq.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Seq.scala rename to scala2-library-cc/src/scala/collection/mutable/Seq.scala diff --git a/tests/pos-special/stdlib/collection/mutable/SeqMap.scala b/scala2-library-cc/src/scala/collection/mutable/SeqMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/SeqMap.scala rename to scala2-library-cc/src/scala/collection/mutable/SeqMap.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Set.scala b/scala2-library-cc/src/scala/collection/mutable/Set.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Set.scala rename to scala2-library-cc/src/scala/collection/mutable/Set.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Shrinkable.scala b/scala2-library-cc/src/scala/collection/mutable/Shrinkable.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Shrinkable.scala rename to scala2-library-cc/src/scala/collection/mutable/Shrinkable.scala diff --git a/tests/pos-special/stdlib/collection/mutable/SortedMap.scala b/scala2-library-cc/src/scala/collection/mutable/SortedMap.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/SortedMap.scala rename to scala2-library-cc/src/scala/collection/mutable/SortedMap.scala diff --git a/tests/pos-special/stdlib/collection/mutable/SortedSet.scala b/scala2-library-cc/src/scala/collection/mutable/SortedSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/SortedSet.scala rename to scala2-library-cc/src/scala/collection/mutable/SortedSet.scala diff --git a/tests/pos-special/stdlib/collection/mutable/Stack.scala b/scala2-library-cc/src/scala/collection/mutable/Stack.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/Stack.scala rename to scala2-library-cc/src/scala/collection/mutable/Stack.scala diff --git a/tests/pos-special/stdlib/collection/mutable/StringBuilder.scala b/scala2-library-cc/src/scala/collection/mutable/StringBuilder.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/StringBuilder.scala rename to scala2-library-cc/src/scala/collection/mutable/StringBuilder.scala diff --git a/tests/pos-special/stdlib/collection/mutable/TreeMap.scala b/scala2-library-cc/src/scala/collection/mutable/TreeMap.scala similarity index 96% rename from tests/pos-special/stdlib/collection/mutable/TreeMap.scala rename to scala2-library-cc/src/scala/collection/mutable/TreeMap.scala index dbb87a950d74..d36e1b9d207d 100644 --- a/tests/pos-special/stdlib/collection/mutable/TreeMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/TreeMap.scala @@ -29,7 +29,7 @@ import language.experimental.captureChecking * @define Coll mutable.TreeMap * @define coll mutable tree map */ -sealed class TreeMap[K, V] private (tree: RB.Tree[K, V])(implicit val ordering: Ordering[K]) +sealed class TreeMap[K, V] private (tree: RB.Tree[K, V])(implicit val ordering: Ordering[K]) extends AbstractMap[K, V] with SortedMap[K, V] with SortedMapOps[K, V, TreeMap, TreeMap[K, V]] @@ -248,11 +248,11 @@ sealed class TreeMap[K, V] private (tree: RB.Tree[K, V])(implicit val ordering: @SerialVersionUID(3L) object TreeMap extends SortedMapFactory[TreeMap] { - def from[K : Ordering, V](it: IterableOnce[(K, V)]^): TreeMap[K, V] = + def from[K : Ordering, V](it: IterableOnce[(K, V)]^): TreeMap[K, V] = Growable.from(empty[K, V], it) - def empty[K : Ordering, V]: TreeMap[K, V] = new TreeMap[K, V]() + def empty[K : Ordering, V]: TreeMap[K, V] = new TreeMap[K, V]() - def newBuilder[K: Ordering, V]: Builder[(K, V), TreeMap[K, V]] = new GrowableBuilder(empty[K, V]) + def newBuilder[K: Ordering, V]: Builder[(K, V), TreeMap[K, V]] = new GrowableBuilder(empty[K, V]) } diff --git a/tests/pos-special/stdlib/collection/mutable/TreeSet.scala b/scala2-library-cc/src/scala/collection/mutable/TreeSet.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/TreeSet.scala rename to scala2-library-cc/src/scala/collection/mutable/TreeSet.scala diff --git a/tests/pos-special/stdlib/collection/mutable/UnrolledBuffer.scala b/scala2-library-cc/src/scala/collection/mutable/UnrolledBuffer.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/UnrolledBuffer.scala rename to scala2-library-cc/src/scala/collection/mutable/UnrolledBuffer.scala diff --git a/tests/pos-special/stdlib/collection/mutable/WeakHashMap.scala b/scala2-library-cc/src/scala/collection/mutable/WeakHashMap.scala similarity index 83% rename from tests/pos-special/stdlib/collection/mutable/WeakHashMap.scala rename to scala2-library-cc/src/scala/collection/mutable/WeakHashMap.scala index 1f94281a0b59..1ccd36c3e25f 100644 --- a/tests/pos-special/stdlib/collection/mutable/WeakHashMap.scala +++ b/scala2-library-cc/src/scala/collection/mutable/WeakHashMap.scala @@ -34,7 +34,7 @@ import language.experimental.captureChecking * @define willNotTerminateInf */ @SerialVersionUID(3L) -class WeakHashMap[K, V] extends JMapWrapper[K, V](new java.util.WeakHashMap) +class WeakHashMap[K, V] extends JMapWrapper[K, V](new java.util.WeakHashMap) with JMapWrapperLike[K, V, WeakHashMap, WeakHashMap[K, V]] with MapFactoryDefaults[K, V, WeakHashMap, Iterable] { override def empty = new WeakHashMap[K, V] @@ -49,8 +49,8 @@ class WeakHashMap[K, V] extends JMapWrapper[K, V](new java.util.WeakHashMap) */ @SerialVersionUID(3L) object WeakHashMap extends MapFactory[WeakHashMap] { - def empty[K, V]: WeakHashMap[K,V] = new WeakHashMap[K, V] - def from[K, V](it: collection.IterableOnce[(K, V)]^): WeakHashMap[K,V] = Growable.from(empty[K, V], it) - def newBuilder[K, V]: Builder[(K, V), WeakHashMap[K,V]] = new GrowableBuilder(WeakHashMap.empty[K, V]) + def empty[K, V]: WeakHashMap[K,V] = new WeakHashMap[K, V] + def from[K, V](it: collection.IterableOnce[(K, V)]^): WeakHashMap[K,V] = Growable.from(empty[K, V], it) + def newBuilder[K, V]: Builder[(K, V), WeakHashMap[K,V]] = new GrowableBuilder(WeakHashMap.empty[K, V]) } diff --git a/tests/pos-special/stdlib/collection/mutable/package.scala b/scala2-library-cc/src/scala/collection/mutable/package.scala similarity index 100% rename from tests/pos-special/stdlib/collection/mutable/package.scala rename to scala2-library-cc/src/scala/collection/mutable/package.scala diff --git a/tests/pos-special/stdlib/collection/package.scala b/scala2-library-cc/src/scala/collection/package.scala similarity index 100% rename from tests/pos-special/stdlib/collection/package.scala rename to scala2-library-cc/src/scala/collection/package.scala diff --git a/scala2-library-cc/src/scala/language.scala b/scala2-library-cc/src/scala/language.scala new file mode 100644 index 000000000000..757b9dac1076 --- /dev/null +++ b/scala2-library-cc/src/scala/language.scala @@ -0,0 +1,213 @@ +/* + * Scala (https://www.scala-lang.org) + * + * Copyright EPFL and Lightbend, Inc. + * + * Licensed under Apache License 2.0 + * (http://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +package scala + +/** + * The `scala.language` object controls the language features available to the programmer, as proposed in the + * [[https://docs.google.com/document/d/1nlkvpoIRkx7at1qJEZafJwthZ3GeIklTFhqmXMvTX9Q/edit '''SIP-18 document''']]. + * + * Each of these features has to be explicitly imported into the current scope to become available: + * {{{ + * import language.postfixOps // or language._ + * List(1, 2, 3) reverse + * }}} + * + * The language features are: + * - [[dynamics `dynamics`]] enables defining calls rewriting using the [[scala.Dynamic `Dynamic`]] trait + * - [[existentials `existentials`]] enables writing existential types + * - [[higherKinds `higherKinds`]] enables writing higher-kinded types + * - [[implicitConversions `implicitConversions`]] enables defining implicit methods and members + * - [[postfixOps `postfixOps`]] enables postfix operators (not recommended) + * - [[reflectiveCalls `reflectiveCalls`]] enables using structural types + * - [[experimental `experimental`]] contains newer features that have not yet been tested in production + * + * @groupname production Language Features + * @groupname experimental Experimental Language Features + * @groupprio experimental 10 + */ +object language { + + import languageFeature._ + + /** Only where this feature is enabled, can direct or indirect subclasses of trait scala.Dynamic + * be defined. If `dynamics` is not enabled, a definition of a class, trait, + * or object that has `Dynamic` as a base trait is rejected by the compiler. + * + * Selections of dynamic members of existing subclasses of trait `Dynamic` are unaffected; + * they can be used anywhere. + * + * '''Why introduce the feature?''' To enable flexible DSLs and convenient interfacing + * with dynamic languages. + * + * '''Why control it?''' Dynamic member selection can undermine static checkability + * of programs. Furthermore, dynamic member selection often relies on reflection, + * which is not available on all platforms. + * + * @group production + */ + implicit lazy val dynamics: dynamics = languageFeature.dynamics + + /** Only where this feature is enabled, is postfix operator notation `(expr op)` permitted. + * If `postfixOps` is not enabled, an expression using postfix notation is rejected by the compiler. + * + * '''Why keep the feature?''' Postfix notation is preserved for backward + * compatibility only. Historically, several DSLs written in Scala need the notation. + * + * '''Why control it?''' Postfix operators interact poorly with semicolon inference. + * Most programmers avoid them for this reason alone. Postfix syntax is + * associated with an abuse of infix notation, `a op1 b op2 c op3`, + * that can be harder to read than ordinary method invocation with judicious + * use of parentheses. It is recommended not to enable this feature except for + * legacy code. + * + * @group production + */ + implicit lazy val postfixOps: postfixOps = languageFeature.postfixOps + + /** Where this feature is enabled, accesses to members of structural types that need + * reflection are supported. If `reflectiveCalls` is not enabled, an expression + * requiring reflection will trigger a warning from the compiler. + * + * A structural type is a type of the form + * `Parents { Decls }` where `Decls` contains declarations of new members that do + * not override any member in `Parents`. To access one of these members, a + * reflective call is needed. + * + * '''Why keep the feature?''' Structural types provide great flexibility because + * they avoid the need to define inheritance hierarchies a priori. Besides, + * their definition falls out quite naturally from Scala’s concept of type refinement. + * + * '''Why control it?''' Reflection is not available on all platforms. Popular tools + * such as ProGuard have problems dealing with it. Even where reflection is available, + * reflective dispatch can lead to surprising performance degradations. + * + * @group production + */ + implicit lazy val reflectiveCalls: reflectiveCalls = languageFeature.reflectiveCalls + + /** Where this feature is enabled, definitions of implicit conversions are allowed. + * If `implicitConversions` is not enabled, the definition of an implicit + * conversion will trigger a warning from the compiler. + * + * An implicit conversion is an implicit value of unary function type `A => B`, + * or an implicit method that has in its first parameter section a single, + * non-implicit parameter. Examples: + * + * {{{ + * implicit def stringToInt(s: String): Int = s.length + * implicit val conv = (s: String) => s.length + * implicit def listToX(xs: List[T])(implicit f: T => X): X = ... + * }}} + * + * Implicit classes and implicit values of other types are not governed by this + * language feature. + * + * '''Why keep the feature?''' Implicit conversions are central to many aspects + * of Scala’s core libraries. + * + * '''Why control it?''' Implicit conversions are known to cause many pitfalls + * if over-used. And there is a tendency to over-use them because they look + * very powerful and their effects seem to be easy to understand. Also, in + * most situations using implicit parameters leads to a better design than + * implicit conversions. + * + * @group production + */ + implicit lazy val implicitConversions: implicitConversions = languageFeature.implicitConversions + + /** Where this feature is enabled, higher-kinded types can be written. + * If `higherKinds` is not enabled, a higher-kinded type such as `F[A]` + * will trigger a warning from the compiler. + * + * '''Why keep the feature?''' Higher-kinded types enable the definition of very general + * abstractions such as functor, monad, or arrow. A significant set of advanced + * libraries relies on them. Higher-kinded types are also at the core of the + * scala-virtualized effort to produce high-performance parallel DSLs through staging. + * + * '''Why control it?''' Higher kinded types in Scala lead to a Turing-complete + * type system, where compiler termination is no longer guaranteed. They tend + * to be useful mostly for type-level computation and for highly generic design + * patterns. The level of abstraction implied by these design patterns is often + * a barrier to understanding for newcomers to a Scala codebase. Some syntactic + * aspects of higher-kinded types are hard to understand for the uninitiated and + * type inference is less effective for them than for normal types. Because we are + * not completely happy with them yet, it is possible that some aspects of + * higher-kinded types will change in future versions of Scala. So an explicit + * enabling also serves as a warning that code involving higher-kinded types + * might have to be slightly revised in the future. + * + * @group production + */ + @deprecated("higherKinds no longer needs to be imported explicitly", "2.13.1") + implicit lazy val higherKinds: higherKinds = languageFeature.higherKinds + + /** Where this feature is enabled, existential types that cannot be expressed as wildcard + * types can be written and are allowed in inferred types of values or return + * types of methods. If `existentials` is not enabled, those cases will trigger + * a warning from the compiler. + * + * Existential types with wildcard type syntax such as `List[_]`, + * or `Map[String, _]` are not affected. + * + * '''Why keep the feature?''' Existential types are needed to make sense of Java’s wildcard + * types and raw types and the erased types of run-time values. + * + * '''Why control it?''' Having complex existential types in a code base usually makes + * application code very brittle, with a tendency to produce type errors with + * obscure error messages. Therefore, going overboard with existential types + * is generally perceived not to be a good idea. Also, complicated existential types + * might be no longer supported in a future simplification of the language. + * + * @group production + */ + implicit lazy val existentials: existentials = languageFeature.existentials + + /** The experimental object contains features that are known to have unstable API or + * behavior that may change in future releases. + * + * Experimental features '''may undergo API changes''' in future releases, so production + * code should not rely on them. + * + * Programmers are encouraged to try out experimental features and + * [[https://github.com/scala/bug/issues report any bugs or API inconsistencies]] + * they encounter so they can be improved in future releases. + * + * @group experimental + */ + object experimental { + + import languageFeature.experimental._ + + /** Experimental support for capture checking; implies support for pureFunctions + * + * @see [[https://dotty.epfl.ch/docs/reference/experimental/cc]] + */ + implicit lazy val captureChecking: existentials = languageFeature.existentials + + /** Only where this feature is enabled, are macro definitions allowed. + * If `macros` is not enabled, macro definitions are rejected by the compiler. + * + * Macro implementations and macro applications are not governed by this + * language feature; they can be used anywhere. + * + * '''Why introduce the feature?''' Macros promise to make the language more regular, + * replacing ad-hoc language constructs with a general powerful abstraction + * capability that can express them. Macros are also a more disciplined and + * powerful replacement for compiler plugins. + * + * '''Why control it?''' For their very power, macros can lead to code that is hard + * to debug and understand. + */ + implicit lazy val macros: macros = languageFeature.experimental.macros + } +} diff --git a/tests/pos-special/stdlib/runtime/PStatics.scala b/scala2-library-cc/src/scala/runtime/PStatics.scala similarity index 100% rename from tests/pos-special/stdlib/runtime/PStatics.scala rename to scala2-library-cc/src/scala/runtime/PStatics.scala diff --git a/tests/pos-special/stdlib/collection/concurrent/BasicNode.java b/tests/pos-special/stdlib/collection/concurrent/BasicNode.java deleted file mode 100644 index c6ec91e4fde8..000000000000 --- a/tests/pos-special/stdlib/collection/concurrent/BasicNode.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala.collection.concurrent; - -public abstract class BasicNode { - - public abstract String string(int lev); - -} diff --git a/tests/pos-special/stdlib/collection/concurrent/CNodeBase.java b/tests/pos-special/stdlib/collection/concurrent/CNodeBase.java deleted file mode 100644 index ddffa365234e..000000000000 --- a/tests/pos-special/stdlib/collection/concurrent/CNodeBase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala.collection.concurrent; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -abstract class CNodeBase extends MainNode { - - @SuppressWarnings("unchecked") - public static final AtomicIntegerFieldUpdater> updater = - AtomicIntegerFieldUpdater.newUpdater((Class>) (Class) CNodeBase.class, "csize"); - - public volatile int csize = -1; - - public boolean CAS_SIZE(int oldval, int nval) { - return updater.compareAndSet(this, oldval, nval); - } - - public void WRITE_SIZE(int nval) { - updater.set(this, nval); - } - - public int READ_SIZE() { - return updater.get(this); - } - -} diff --git a/tests/pos-special/stdlib/collection/concurrent/Gen.java b/tests/pos-special/stdlib/collection/concurrent/Gen.java deleted file mode 100644 index 07af2983f32d..000000000000 --- a/tests/pos-special/stdlib/collection/concurrent/Gen.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala.collection.concurrent; - -final class Gen {} diff --git a/tests/pos-special/stdlib/collection/concurrent/INodeBase.java b/tests/pos-special/stdlib/collection/concurrent/INodeBase.java deleted file mode 100644 index dfb99806594f..000000000000 --- a/tests/pos-special/stdlib/collection/concurrent/INodeBase.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala.collection.concurrent; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -abstract class INodeBase extends BasicNode { - - @SuppressWarnings("unchecked") - public static final AtomicReferenceFieldUpdater, MainNode> updater = - AtomicReferenceFieldUpdater.newUpdater((Class>) (Class) INodeBase.class, (Class>) (Class) MainNode.class, "mainnode"); - - static final Object RESTART = new Object(); - - static final Object NO_SUCH_ELEMENT_SENTINEL = new Object(); - - public volatile MainNode mainnode = null; - - public final Gen gen; - - public INodeBase(Gen generation) { - gen = generation; - } - - public BasicNode prev() { - return null; - } - -} diff --git a/tests/pos-special/stdlib/collection/concurrent/MainNode.java b/tests/pos-special/stdlib/collection/concurrent/MainNode.java deleted file mode 100644 index f7f022974e9e..000000000000 --- a/tests/pos-special/stdlib/collection/concurrent/MainNode.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala.collection.concurrent; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -abstract class MainNode extends BasicNode { - - @SuppressWarnings("unchecked") - public static final AtomicReferenceFieldUpdater, MainNode> updater = - AtomicReferenceFieldUpdater.newUpdater((Class>) (Class) MainNode.class, (Class>) (Class) MainNode.class, "prev"); - - public volatile MainNode prev = null; - - public abstract int cachedSize(Object ct); - - // standard contract - public abstract int knownSize(); - - public boolean CAS_PREV(MainNode oldval, MainNode nval) { - return updater.compareAndSet(this, oldval, nval); - } - - public void WRITE_PREV(MainNode nval) { - updater.set(this, nval); - } - - // do we need this? unclear in the javadocs... - // apparently not - volatile reads are supposed to be safe - // regardless of whether there are concurrent ARFU updates - @Deprecated @SuppressWarnings("unchecked") - public MainNode READ_PREV() { - return (MainNode) updater.get(this); - } - -}