Skip to content

prepare for Dotty #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/main/scala/scala/collection/generic/Signalling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ trait AtomicIndexFlag extends Signalling {
abstract override def setIndexFlag(f: Int) = intflag.set(f)
abstract override def setIndexFlagIfGreater(f: Int) = {
var loop = true
do {
while (loop) {
val old = intflag.get
if (f <= old) loop = false
else if (intflag.compareAndSet(old, f)) loop = false
} while (loop)
}
}
abstract override def setIndexFlagIfLesser(f: Int) = {
var loop = true
do {
while (loop) {
val old = intflag.get
if (f >= old) loop = false
else if (intflag.compareAndSet(old, f)) loop = false
} while (loop)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ self =>
}

/* convenience task operations wrapper */
protected implicit def task2ops[R, Tp](tsk: SSCTask[R, Tp]) = new TaskOps[R, Tp] {
protected implicit def task2ops[R, Tp](tsk: SSCTask[R, Tp]): TaskOps[R, Tp] = new TaskOps[R, Tp] {
def mapResult[R1](mapping: R => R1): ResultMapping[R, Tp, R1] = new ResultMapping[R, Tp, R1](tsk) {
def map(r: R): R1 = mapping(r)
}
Expand All @@ -316,14 +316,14 @@ self =>
}

/* convenience signalling operations wrapper */
protected implicit def delegatedSignalling2ops[PI <: DelegatedSignalling](it: PI) = new SignallingOps[PI] {
protected implicit def delegatedSignalling2ops[PI <: DelegatedSignalling](it: PI): SignallingOps[PI] = new SignallingOps[PI] {
def assign(cntx: Signalling): PI = {
it.signalDelegate = cntx
it
}
}

protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]) = new BuilderOps[Elem, To] {
protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]): BuilderOps[Elem, To] = new BuilderOps[Elem, To] {
def ifIs[Cmb](isbody: Cmb => Unit) = new Otherwise[Cmb] {
def otherwise(notbody: => Unit)(implicit t: ClassTag[Cmb]): Unit = {
if (cb.getClass == t.runtimeClass) isbody(cb.asInstanceOf[Cmb]) else notbody
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/scala/collection/parallel/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,16 @@ trait AdaptiveWorkStealingTasks extends Tasks {
def spawnSubtasks() = {
var last: AWSTWrappedTask[R, Tp] = null
var head: AWSTWrappedTask[R, Tp] = this
do {
while ({
val subtasks = head.split
head = subtasks.head
for (t <- subtasks.tail.reverse) {
t.next = last
last = t
t.start()
}
} while (head.body.shouldSplitFurther)
head.body.shouldSplitFurther
}) ()
head.next = last
head
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,15 @@ self =>

override def copy2builder[U >: T, Coll, Bld <: Builder[U, Coll]](cb: Bld): Bld = {
cb.sizeHint(remaining)
cb.ifIs[ResizableParArrayCombiner[T]] {
pac =>
cb.ifIs[ResizableParArrayCombiner[T]] { pac =>
// with res. combiner:
val targetarr: Array[Any] = pac.lastbuff.internalArray.asInstanceOf[Array[Any]]
Array.copy(arr, i, targetarr, pac.lastbuff.size, until - i)
pac.lastbuff.setInternalSize(remaining)
} otherwise {
cb.ifIs[UnrolledParArrayCombiner[T]] {
pac =>
// with unr. combiner:
val targetarr: Array[Any] = pac.buff.lastPtr.array.asInstanceOf[Array[Any]]
cb.ifIs[UnrolledParArrayCombiner[T]] { pac =>
// with unr. combiner:
val targetarr: Array[Any] = pac.buff.lastPtr.array.asInstanceOf[Array[Any]]
Array.copy(arr, i, targetarr, 0, until - i)
pac.buff.size = pac.buff.size + until - i
pac.buff.lastPtr.size = until - i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ package object parallel {
package parallel {
/** Implicit conversions used in the implementation of parallel collections. */
private[collection] object ParallelCollectionImplicits {
implicit def traversable2ops[T](t: scala.collection.IterableOnce[T]) = new TraversableOps[T] {
implicit def traversable2ops[T](t: scala.collection.IterableOnce[T]): TraversableOps[T] = new TraversableOps[T] {
def isParallel = t.isInstanceOf[Parallel]
def isParIterable = t.isInstanceOf[ParIterable[_]]
def asParIterable = t.asInstanceOf[ParIterable[T]]
Expand Down
21 changes: 13 additions & 8 deletions junit/src/test/scala/scala/SerializationStabilityTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package scala

import javax.xml.bind.DatatypeConverter._
import scala.reflect.io.File
import java.nio.file.{ Path, Paths, Files }
import org.junit.Test

// This test is self-modifying when run as follows:
Expand All @@ -24,7 +24,10 @@ import org.junit.Test

// based on run/t8549.scala partest
object SerializationStability extends App {
val overwrite: Option[File] = sys.props.get("overwrite.source").map(s => new File(new java.io.File(s).getAbsoluteFile))

val overwrite: Option[Path] =
sys.props.get("overwrite.source")
.map(s => Paths.get(s).toAbsolutePath)

def serialize(o: AnyRef): String = {
val bos = new java.io.ByteArrayOutputStream()
Expand All @@ -34,13 +37,15 @@ object SerializationStability extends App {
printBase64Binary(bos.toByteArray())
}

def amend(file: File)(f: String => String): Unit = {
file.writeAll(f(file.slurp()))
def amend(path: Path)(f: String => String): Unit = {
val old = new String(java.nio.file.Files.readAllBytes(path))
Files.write(path, f(old).getBytes)
}

def quote(s: String) = List("\"", s, "\"").mkString

def patch(file: File, line: Int, prevResult: String, result: String): Unit = {
amend(file) {
def patch(path: Path, line: Int, prevResult: String, result: String): Unit = {
amend(path) {
content =>
content.linesIterator.toList.zipWithIndex.map {
case (content, i) if i == line - 1 =>
Expand All @@ -53,14 +58,14 @@ object SerializationStability extends App {
}
}

def updateComment(file: File): Unit = {
def updateComment(path: Path): Unit = {
val timestamp = {
import java.text.SimpleDateFormat
val sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss")
sdf.format(new java.util.Date)
}
val newComment = s" // Generated on $timestamp with Scala ${scala.util.Properties.versionString})"
amend(file) {
amend(path) {
content =>
content.linesIterator.toList.map {
f => f.replaceAll("""^ +// Generated on.*""", newComment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ConcurrentMapSpec extends Spec {
}

def assertEqual(a: Any, b: Any) = {
if (a != b) println(a, b)
if (a != b) println((a, b))
assert(a == b)
}

Expand All @@ -79,10 +79,11 @@ class ConcurrentMapSpec extends Spec {
for (i <- 0 until sz) {
val j = (offs + i) % sz
var k = Int.MaxValue
do {
while ({
if (k != Int.MaxValue) repeats += 1
k = ct.getOrElse(new Wrap(j), 0)
} while (!ct.replace(new Wrap(j), k, -k))
!ct.replace(new Wrap(j), k, -k)
}) ()
}
//println("Thread %d repeats: %d".format(index, repeats))
}
Expand Down Expand Up @@ -154,13 +155,14 @@ class ConcurrentMapSpec extends Spec {
for (j <- 0 until sz) {
val i = (offs + j) % sz
var success = false
do {
while ({
if (ct.contains(new Wrap(i))) {
success = ct.remove(new Wrap(i)) != None
} else {
success = ct.putIfAbsent(new Wrap(i), i) == None
}
} while (!success)
!success
}) ()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SnapshotSpec extends Spec {
for (i <- 0 until sz) {
val tres = trie.get(new Wrap(i))
val ires = initial.get(new Wrap(i))
if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres))
if (tres != ires) println((i, "initially: " + ires, "traversal %d: %s".format(k, tres)))
assert(tres == ires)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ import scala.reflect.{ClassTag, classTag}

trait Spec {

implicit def implicitously = scala.language.implicitConversions
implicit def reflectively = scala.language.reflectiveCalls

implicit def str2ops(s: String) = new {
implicit class Str2ops(s: String) {
def in[U](body: =>U): Unit = {
// just execute body
body
}
}

implicit def any2ops(a: Any) = new {
implicit class Any2ops(a: Any) {
def shouldEqual(other: Any) = assert(a == other)
}

def evaluating[U](body: =>U) = new {
def shouldProduce[T <: Throwable: ClassTag]() = {
trait HasShouldProduce[U] { def shouldProduce[T <: Throwable: ClassTag](): Unit }

def evaluating[U](body: =>U): HasShouldProduce[U] = new HasShouldProduce[U] {
override def shouldProduce[T <: Throwable: ClassTag]() = {
var produced = false
try body
catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ConcurrentMapSpec extends Spec {
}

def assertEqual(a: Any, b: Any) = {
if (a != b) println(a, b)
if (a != b) println((a, b))
assert(a == b)
}

Expand All @@ -79,10 +79,11 @@ class ConcurrentMapSpec extends Spec {
for (i <- 0 until sz) {
val j = (offs + i) % sz
var k = Int.MaxValue
do {
while ({
if (k != Int.MaxValue) repeats += 1
k = ct.getOrElse(new Wrap(j), 0)
} while (!ct.replace(new Wrap(j), k, -k))
!ct.replace(new Wrap(j), k, -k)
}) ()
}
//println("Thread %d repeats: %d".format(index, repeats))
}
Expand Down Expand Up @@ -154,13 +155,14 @@ class ConcurrentMapSpec extends Spec {
for (j <- 0 until sz) {
val i = (offs + j) % sz
var success = false
do {
while ({
if (ct.contains(new Wrap(i))) {
success = ct.remove(new Wrap(i)) != None
} else {
success = ct.putIfAbsent(new Wrap(i), i) == None
}
} while (!success)
!success
}) ()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SnapshotSpec extends Spec {
for (i <- 0 until sz) {
val tres = trie.get(new Wrap(i))
val ires = initial.get(new Wrap(i))
if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres))
if (tres != ires) println((i, "initially: " + ires, "traversal %d: %s".format(k, tres)))
assert(tres == ires)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@

package scala.collection.concurrent.ctries_old

import scala.reflect.ClassTag
import scala.reflect.{ClassTag, classTag}

trait Spec {

implicit def implicitously = scala.language.implicitConversions
implicit def reflectively = scala.language.reflectiveCalls

implicit def str2ops(s: String) = new {
implicit class Str2ops(s: String) {
def in[U](body: =>U): Unit = {
// just execute body
body
}
}

implicit def any2ops(a: Any) = new {
implicit class Any2ops(a: Any) {
def shouldEqual(other: Any) = assert(a == other)
}

def evaluating[U](body: =>U) = new {
def shouldProduce[T <: Throwable: ClassTag]() = {
trait HasShouldProduce[U] { def shouldProduce[T <: Throwable: ClassTag](): Unit }

def evaluating[U](body: =>U): HasShouldProduce[U] = new HasShouldProduce[U] {
override def shouldProduce[T <: Throwable: ClassTag]() = {
var produced = false
try body
catch {
Expand Down
3 changes: 1 addition & 2 deletions scalacheck/src/test/scala/ParallelIterableCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("drop " + n + " elements") |: t.drop(n).iterator.sameElements(coll.drop(n))
}

if (hasStrictOrder) property("slices must be equal") = forAllNoShrink(collectionPairsWith2Indices)
{ case (t, coll, fr, slicelength) =>
if (hasStrictOrder) property("slices must be equal") = forAllNoShrink(collectionPairsWith2Indices) { case (t, coll, fr, slicelength) =>
val from = if (fr < 0) 0 else fr
val until = if (from + slicelength > t.size) t.size else from + slicelength
val tsl = t.slice(from, until)
Expand Down