Skip to content

Commit 39357a3

Browse files
authored
Merge pull request #117 from SethTisue/cleanups-for-dotty
prepare for Dotty
2 parents 86e8703 + 2395540 commit 39357a3

File tree

13 files changed

+58
-53
lines changed

13 files changed

+58
-53
lines changed

core/src/main/scala/scala/collection/generic/Signalling.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ trait AtomicIndexFlag extends Signalling {
131131
abstract override def setIndexFlag(f: Int) = intflag.set(f)
132132
abstract override def setIndexFlagIfGreater(f: Int) = {
133133
var loop = true
134-
do {
134+
while (loop) {
135135
val old = intflag.get
136136
if (f <= old) loop = false
137137
else if (intflag.compareAndSet(old, f)) loop = false
138-
} while (loop)
138+
}
139139
}
140140
abstract override def setIndexFlagIfLesser(f: Int) = {
141141
var loop = true
142-
do {
142+
while (loop) {
143143
val old = intflag.get
144144
if (f >= old) loop = false
145145
else if (intflag.compareAndSet(old, f)) loop = false
146-
} while (loop)
146+
}
147147
}
148148
}
149149

core/src/main/scala/scala/collection/parallel/ParIterableLike.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ self =>
296296
}
297297

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

318318
/* convenience signalling operations wrapper */
319-
protected implicit def delegatedSignalling2ops[PI <: DelegatedSignalling](it: PI) = new SignallingOps[PI] {
319+
protected implicit def delegatedSignalling2ops[PI <: DelegatedSignalling](it: PI): SignallingOps[PI] = new SignallingOps[PI] {
320320
def assign(cntx: Signalling): PI = {
321321
it.signalDelegate = cntx
322322
it
323323
}
324324
}
325325

326-
protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]) = new BuilderOps[Elem, To] {
326+
protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]): BuilderOps[Elem, To] = new BuilderOps[Elem, To] {
327327
def ifIs[Cmb](isbody: Cmb => Unit) = new Otherwise[Cmb] {
328328
def otherwise(notbody: => Unit)(implicit t: ClassTag[Cmb]): Unit = {
329329
if (cb.getClass == t.runtimeClass) isbody(cb.asInstanceOf[Cmb]) else notbody

core/src/main/scala/scala/collection/parallel/Tasks.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,16 @@ trait AdaptiveWorkStealingTasks extends Tasks {
180180
def spawnSubtasks() = {
181181
var last: AWSTWrappedTask[R, Tp] = null
182182
var head: AWSTWrappedTask[R, Tp] = this
183-
do {
183+
while ({
184184
val subtasks = head.split
185185
head = subtasks.head
186186
for (t <- subtasks.tail.reverse) {
187187
t.next = last
188188
last = t
189189
t.start()
190190
}
191-
} while (head.body.shouldSplitFurther)
191+
head.body.shouldSplitFurther
192+
}) ()
192193
head.next = last
193194
head
194195
}

core/src/main/scala/scala/collection/parallel/mutable/ParArray.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,15 @@ self =>
461461

462462
override def copy2builder[U >: T, Coll, Bld <: Builder[U, Coll]](cb: Bld): Bld = {
463463
cb.sizeHint(remaining)
464-
cb.ifIs[ResizableParArrayCombiner[T]] {
465-
pac =>
464+
cb.ifIs[ResizableParArrayCombiner[T]] { pac =>
466465
// with res. combiner:
467466
val targetarr: Array[Any] = pac.lastbuff.internalArray.asInstanceOf[Array[Any]]
468467
Array.copy(arr, i, targetarr, pac.lastbuff.size, until - i)
469468
pac.lastbuff.setInternalSize(remaining)
470469
} otherwise {
471-
cb.ifIs[UnrolledParArrayCombiner[T]] {
472-
pac =>
473-
// with unr. combiner:
474-
val targetarr: Array[Any] = pac.buff.lastPtr.array.asInstanceOf[Array[Any]]
470+
cb.ifIs[UnrolledParArrayCombiner[T]] { pac =>
471+
// with unr. combiner:
472+
val targetarr: Array[Any] = pac.buff.lastPtr.array.asInstanceOf[Array[Any]]
475473
Array.copy(arr, i, targetarr, 0, until - i)
476474
pac.buff.size = pac.buff.size + until - i
477475
pac.buff.lastPtr.size = until - i

core/src/main/scala/scala/collection/parallel/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ package object parallel {
6666
package parallel {
6767
/** Implicit conversions used in the implementation of parallel collections. */
6868
private[collection] object ParallelCollectionImplicits {
69-
implicit def traversable2ops[T](t: scala.collection.IterableOnce[T]) = new TraversableOps[T] {
69+
implicit def traversable2ops[T](t: scala.collection.IterableOnce[T]): TraversableOps[T] = new TraversableOps[T] {
7070
def isParallel = t.isInstanceOf[Parallel]
7171
def isParIterable = t.isInstanceOf[ParIterable[_]]
7272
def asParIterable = t.asInstanceOf[ParIterable[T]]

junit/src/test/scala/scala/SerializationStabilityTest.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala
1414

1515
import javax.xml.bind.DatatypeConverter._
16-
import scala.reflect.io.File
16+
import java.nio.file.{ Path, Paths, Files }
1717
import org.junit.Test
1818

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

2525
// based on run/t8549.scala partest
2626
object SerializationStability extends App {
27-
val overwrite: Option[File] = sys.props.get("overwrite.source").map(s => new File(new java.io.File(s).getAbsoluteFile))
27+
28+
val overwrite: Option[Path] =
29+
sys.props.get("overwrite.source")
30+
.map(s => Paths.get(s).toAbsolutePath)
2831

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

37-
def amend(file: File)(f: String => String): Unit = {
38-
file.writeAll(f(file.slurp()))
40+
def amend(path: Path)(f: String => String): Unit = {
41+
val old = new String(java.nio.file.Files.readAllBytes(path))
42+
Files.write(path, f(old).getBytes)
3943
}
44+
4045
def quote(s: String) = List("\"", s, "\"").mkString
4146

42-
def patch(file: File, line: Int, prevResult: String, result: String): Unit = {
43-
amend(file) {
47+
def patch(path: Path, line: Int, prevResult: String, result: String): Unit = {
48+
amend(path) {
4449
content =>
4550
content.linesIterator.toList.zipWithIndex.map {
4651
case (content, i) if i == line - 1 =>
@@ -53,14 +58,14 @@ object SerializationStability extends App {
5358
}
5459
}
5560

56-
def updateComment(file: File): Unit = {
61+
def updateComment(path: Path): Unit = {
5762
val timestamp = {
5863
import java.text.SimpleDateFormat
5964
val sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss")
6065
sdf.format(new java.util.Date)
6166
}
6267
val newComment = s" // Generated on $timestamp with Scala ${scala.util.Properties.versionString})"
63-
amend(file) {
68+
amend(path) {
6469
content =>
6570
content.linesIterator.toList.map {
6671
f => f.replaceAll("""^ +// Generated on.*""", newComment)

junit/src/test/scala/scala/collection/concurrent/ctries_new/ConcurrentMapSpec.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ConcurrentMapSpec extends Spec {
6464
}
6565

6666
def assertEqual(a: Any, b: Any) = {
67-
if (a != b) println(a, b)
67+
if (a != b) println((a, b))
6868
assert(a == b)
6969
}
7070

@@ -79,10 +79,11 @@ class ConcurrentMapSpec extends Spec {
7979
for (i <- 0 until sz) {
8080
val j = (offs + i) % sz
8181
var k = Int.MaxValue
82-
do {
82+
while ({
8383
if (k != Int.MaxValue) repeats += 1
8484
k = ct.getOrElse(new Wrap(j), 0)
85-
} while (!ct.replace(new Wrap(j), k, -k))
85+
!ct.replace(new Wrap(j), k, -k)
86+
}) ()
8687
}
8788
//println("Thread %d repeats: %d".format(index, repeats))
8889
}
@@ -154,13 +155,14 @@ class ConcurrentMapSpec extends Spec {
154155
for (j <- 0 until sz) {
155156
val i = (offs + j) % sz
156157
var success = false
157-
do {
158+
while ({
158159
if (ct.contains(new Wrap(i))) {
159160
success = ct.remove(new Wrap(i)) != None
160161
} else {
161162
success = ct.putIfAbsent(new Wrap(i), i) == None
162163
}
163-
} while (!success)
164+
!success
165+
}) ()
164166
}
165167
}
166168
}

junit/src/test/scala/scala/collection/concurrent/ctries_new/SnapshotSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class SnapshotSpec extends Spec {
8888
for (i <- 0 until sz) {
8989
val tres = trie.get(new Wrap(i))
9090
val ires = initial.get(new Wrap(i))
91-
if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres))
91+
if (tres != ires) println((i, "initially: " + ires, "traversal %d: %s".format(k, tres)))
9292
assert(tres == ires)
9393
}
9494
}

junit/src/test/scala/scala/collection/concurrent/ctries_new/Spec.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ import scala.reflect.{ClassTag, classTag}
1616

1717
trait Spec {
1818

19-
implicit def implicitously = scala.language.implicitConversions
20-
implicit def reflectively = scala.language.reflectiveCalls
21-
22-
implicit def str2ops(s: String) = new {
19+
implicit class Str2ops(s: String) {
2320
def in[U](body: =>U): Unit = {
2421
// just execute body
2522
body
2623
}
2724
}
2825

29-
implicit def any2ops(a: Any) = new {
26+
implicit class Any2ops(a: Any) {
3027
def shouldEqual(other: Any) = assert(a == other)
3128
}
3229

33-
def evaluating[U](body: =>U) = new {
34-
def shouldProduce[T <: Throwable: ClassTag]() = {
30+
trait HasShouldProduce[U] { def shouldProduce[T <: Throwable: ClassTag](): Unit }
31+
32+
def evaluating[U](body: =>U): HasShouldProduce[U] = new HasShouldProduce[U] {
33+
override def shouldProduce[T <: Throwable: ClassTag]() = {
3534
var produced = false
3635
try body
3736
catch {

junit/src/test/scala/scala/collection/concurrent/ctries_old/ConcurrentMapSpec.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ConcurrentMapSpec extends Spec {
6464
}
6565

6666
def assertEqual(a: Any, b: Any) = {
67-
if (a != b) println(a, b)
67+
if (a != b) println((a, b))
6868
assert(a == b)
6969
}
7070

@@ -79,10 +79,11 @@ class ConcurrentMapSpec extends Spec {
7979
for (i <- 0 until sz) {
8080
val j = (offs + i) % sz
8181
var k = Int.MaxValue
82-
do {
82+
while ({
8383
if (k != Int.MaxValue) repeats += 1
8484
k = ct.getOrElse(new Wrap(j), 0)
85-
} while (!ct.replace(new Wrap(j), k, -k))
85+
!ct.replace(new Wrap(j), k, -k)
86+
}) ()
8687
}
8788
//println("Thread %d repeats: %d".format(index, repeats))
8889
}
@@ -154,13 +155,14 @@ class ConcurrentMapSpec extends Spec {
154155
for (j <- 0 until sz) {
155156
val i = (offs + j) % sz
156157
var success = false
157-
do {
158+
while ({
158159
if (ct.contains(new Wrap(i))) {
159160
success = ct.remove(new Wrap(i)) != None
160161
} else {
161162
success = ct.putIfAbsent(new Wrap(i), i) == None
162163
}
163-
} while (!success)
164+
!success
165+
}) ()
164166
}
165167
}
166168
}

junit/src/test/scala/scala/collection/concurrent/ctries_old/SnapshotSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class SnapshotSpec extends Spec {
8989
for (i <- 0 until sz) {
9090
val tres = trie.get(new Wrap(i))
9191
val ires = initial.get(new Wrap(i))
92-
if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres))
92+
if (tres != ires) println((i, "initially: " + ires, "traversal %d: %s".format(k, tres)))
9393
assert(tres == ires)
9494
}
9595
}

junit/src/test/scala/scala/collection/concurrent/ctries_old/Spec.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@
1212

1313
package scala.collection.concurrent.ctries_old
1414

15-
import scala.reflect.ClassTag
15+
import scala.reflect.{ClassTag, classTag}
1616

1717
trait Spec {
1818

19-
implicit def implicitously = scala.language.implicitConversions
20-
implicit def reflectively = scala.language.reflectiveCalls
21-
22-
implicit def str2ops(s: String) = new {
19+
implicit class Str2ops(s: String) {
2320
def in[U](body: =>U): Unit = {
2421
// just execute body
2522
body
2623
}
2724
}
2825

29-
implicit def any2ops(a: Any) = new {
26+
implicit class Any2ops(a: Any) {
3027
def shouldEqual(other: Any) = assert(a == other)
3128
}
3229

33-
def evaluating[U](body: =>U) = new {
34-
def shouldProduce[T <: Throwable: ClassTag]() = {
30+
trait HasShouldProduce[U] { def shouldProduce[T <: Throwable: ClassTag](): Unit }
31+
32+
def evaluating[U](body: =>U): HasShouldProduce[U] = new HasShouldProduce[U] {
33+
override def shouldProduce[T <: Throwable: ClassTag]() = {
3534
var produced = false
3635
try body
3736
catch {

scalacheck/src/test/scala/ParallelIterableCheck.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
275275
("drop " + n + " elements") |: t.drop(n).iterator.sameElements(coll.drop(n))
276276
}
277277

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

0 commit comments

Comments
 (0)