Skip to content

Commit 19dac82

Browse files
committed
Merge pull request scala#5068 from retronym/topic/jdk8ism2
Accomodate and exploit new library, lang features JDK 8
2 parents ad36185 + 6181525 commit 19dac82

File tree

16 files changed

+82
-67
lines changed

16 files changed

+82
-67
lines changed

src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package scala.reflect.macros
22
package runtime
33

4+
import java.net.URLClassLoader
5+
46
import scala.reflect.internal.Flags._
7+
import scala.reflect.internal.util.ScalaClassLoader
58
import scala.reflect.runtime.ReflectionUtils
9+
import scala.reflect.internal.util.AbstractFileClassLoader
610

711
trait MacroRuntimes extends JavaReflectionRuntimes {
812
self: scala.tools.nsc.typechecker.Analyzer =>
@@ -44,7 +48,15 @@ trait MacroRuntimes extends JavaReflectionRuntimes {
4448
* which compiles implementations into a virtual directory (very much like REPL does) and then conjures
4549
* a classloader mapped to that virtual directory.
4650
*/
47-
lazy val defaultMacroClassloader: ClassLoader = findMacroClassLoader()
51+
private lazy val defaultMacroClassloaderCache = {
52+
def attemptClose(loader: ClassLoader): Unit = loader match {
53+
case u: URLClassLoader => debuglog("Closing macro runtime classloader"); u.close()
54+
case afcl: AbstractFileClassLoader => attemptClose(afcl.getParent)
55+
case _ => ???
56+
}
57+
perRunCaches.newGeneric(findMacroClassLoader, attemptClose _)
58+
}
59+
def defaultMacroClassloader: ClassLoader = defaultMacroClassloaderCache()
4860

4961
/** Abstracts away resolution of macro runtimes.
5062
*/

src/compiler/scala/tools/nsc/javac/JavaParsers.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
264264
}
265265
}
266266

267-
def typ(): Tree =
267+
def typ(): Tree = {
268+
annotations()
268269
optArrayBrackets {
269270
if (in.token == FINAL) in.nextToken()
270271
if (in.token == IDENTIFIER) {
@@ -287,6 +288,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
287288
basicType()
288289
}
289290
}
291+
}
290292

291293
def typeArgs(t: Tree): Tree = {
292294
val wildcards = new ListBuffer[TypeDef]
@@ -404,6 +406,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
404406

405407
def typeParam(): TypeDef =
406408
atPos(in.currentPos) {
409+
annotations()
407410
val name = identForType()
408411
val hi = if (in.token == EXTENDS) { in.nextToken() ; bound() } else EmptyTree
409412
TypeDef(Modifiers(Flags.JAVA | Flags.DEFERRED | Flags.PARAM), name, Nil, TypeBoundsTree(EmptyTree, hi))

src/library/scala/collection/generic/BitOperations.scala

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,7 @@ private[collection] object BitOperations {
2626
def complement(i: Int) = (-1) ^ i
2727
def bits(num: Int) = 31 to 0 by -1 map (i => (num >>> i & 1) != 0)
2828
def bitString(num: Int, sep: String = "") = bits(num) map (b => if (b) "1" else "0") mkString sep
29-
30-
def highestOneBit(j: Int) = {
31-
var i = j
32-
i |= (i >> 1)
33-
i |= (i >> 2)
34-
i |= (i >> 4)
35-
i |= (i >> 8)
36-
i |= (i >> 16)
37-
i - (i >>> 1)
38-
}
29+
def highestOneBit(j: Int) = java.lang.Integer.highestOneBit(j)
3930
}
4031
object Int extends Int
4132

@@ -49,17 +40,7 @@ private[collection] object BitOperations {
4940
def complement(i: Long) = (-1L) ^ i
5041
def bits(num: Long) = 63L to 0L by -1L map (i => (num >>> i & 1L) != 0L)
5142
def bitString(num: Long, sep: String = "") = bits(num) map (b => if (b) "1" else "0") mkString sep
52-
53-
def highestOneBit(j: Long) = {
54-
var i = j
55-
i |= (i >> 1)
56-
i |= (i >> 2)
57-
i |= (i >> 4)
58-
i |= (i >> 8)
59-
i |= (i >> 16)
60-
i |= (i >> 32)
61-
i - (i >>> 1)
62-
}
43+
def highestOneBit(j: Long) = java.lang.Long.highestOneBit(j)
6344
}
6445
object Long extends Long
6546
}

src/library/scala/collection/parallel/Tasks.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@ trait Task[R, +Tp] {
6666
}
6767

6868
private[parallel] def mergeThrowables(that: Task[_, _]) {
69-
// TODO: As soon as we target Java >= 7, use Throwable#addSuppressed
70-
// to pass additional Throwables to the caller, e. g.
71-
// if (this.throwable != null && that.throwable != null)
72-
// this.throwable.addSuppressed(that.throwable)
73-
// For now, we just use whatever Throwable comes across “first”.
74-
if (this.throwable == null && that.throwable != null)
75-
this.throwable = that.throwable
69+
if (this.throwable != null && that.throwable != null)
70+
this.throwable.addSuppressed(that.throwable)
71+
else if (this.throwable == null && that.throwable != null)
72+
this.throwable = that.throwable
7673
}
7774

7875
// override in concrete task implementations to signal abort to other tasks

src/library/scala/compat/Platform.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ object Platform {
105105
/** The default line separator.
106106
*
107107
* On the JVM, this is equivalent to calling the method:
108-
* `System.getProperty("line.separator")`
109-
* with a default value of "\n".
108+
* `java.lang.System.lineSeparator`
110109
*/
111110
val EOL = scala.util.Properties.lineSeparator
112111

src/library/scala/math/Ordering.scala

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,42 +224,32 @@ object Ordering extends LowPriorityOrderingImplicits {
224224
implicit object Unit extends UnitOrdering
225225

226226
trait BooleanOrdering extends Ordering[Boolean] {
227-
def compare(x: Boolean, y: Boolean) = (x, y) match {
228-
case (false, true) => -1
229-
case (true, false) => 1
230-
case _ => 0
231-
}
227+
def compare(x: Boolean, y: Boolean) = java.lang.Boolean.compare(x, y)
232228
}
233229
implicit object Boolean extends BooleanOrdering
234230

235231
trait ByteOrdering extends Ordering[Byte] {
236-
def compare(x: Byte, y: Byte) = x.toInt - y.toInt
232+
def compare(x: Byte, y: Byte) = java.lang.Byte.compare(x, y)
237233
}
238234
implicit object Byte extends ByteOrdering
239235

240236
trait CharOrdering extends Ordering[Char] {
241-
def compare(x: Char, y: Char) = x.toInt - y.toInt
237+
def compare(x: Char, y: Char) = java.lang.Character.compare(x, y)
242238
}
243239
implicit object Char extends CharOrdering
244240

245241
trait ShortOrdering extends Ordering[Short] {
246-
def compare(x: Short, y: Short) = x.toInt - y.toInt
242+
def compare(x: Short, y: Short) = java.lang.Short.compare(x, y)
247243
}
248244
implicit object Short extends ShortOrdering
249245

250246
trait IntOrdering extends Ordering[Int] {
251-
def compare(x: Int, y: Int) =
252-
if (x < y) -1
253-
else if (x == y) 0
254-
else 1
247+
def compare(x: Int, y: Int) = java.lang.Integer.compare(x, y)
255248
}
256249
implicit object Int extends IntOrdering
257250

258251
trait LongOrdering extends Ordering[Long] {
259-
def compare(x: Long, y: Long) =
260-
if (x < y) -1
261-
else if (x == y) 0
262-
else 1
252+
def compare(x: Long, y: Long) = java.lang.Long.compare(x, y)
263253
}
264254
implicit object Long extends LongOrdering
265255

src/library/scala/runtime/BoxesRunTime.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ public static int hashFromDouble(java.lang.Double n) {
236236
if (iv == dv) return iv;
237237

238238
long lv = n.longValue();
239-
if (lv == dv) return java.lang.Long.valueOf(lv).hashCode();
239+
if (lv == dv) return java.lang.Long.hashCode(lv);
240240

241241
float fv = n.floatValue();
242-
if (fv == dv) return java.lang.Float.valueOf(fv).hashCode();
242+
if (fv == dv) return java.lang.Float.hashCode(fv);
243243
else return n.hashCode();
244244
}
245245
public static int hashFromFloat(java.lang.Float n) {
@@ -248,7 +248,7 @@ public static int hashFromFloat(java.lang.Float n) {
248248
if (iv == fv) return iv;
249249

250250
long lv = n.longValue();
251-
if (lv == fv) return java.lang.Long.valueOf(lv).hashCode();
251+
if (lv == fv) return java.lang.Long.hashCode(lv);
252252
else return n.hashCode();
253253
}
254254
public static int hashFromNumber(java.lang.Number n) {

src/library/scala/sys/process/BasicIO.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object BasicIO {
3333
final val BufferSize = 8192
3434

3535
/** Used to separate lines in the `processFully` function that takes `Appendable`. */
36-
final val Newline = props("line.separator")
36+
final val Newline = System.lineSeparator
3737

3838
private[process] final class Streamed[T](
3939
val process: T => Unit,

src/library/scala/util/Properties.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private[scala] trait PropertiesTrait {
120120

121121
/** The default end of line character.
122122
*/
123-
def lineSeparator = propOrElse("line.separator", "\n")
123+
def lineSeparator = System.lineSeparator()
124124

125125
/* Various well-known properties. */
126126
def javaClassPath = propOrEmpty("java.class.path")

src/library/scala/util/control/NoStackTrace.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ package util.control
1414
* on a global basis via a system property wrapper in
1515
* [[scala.sys.SystemProperties]].
1616
*
17+
* @note Since JDK 1.7, a similar effect can be achieved with `class Ex extends Throwable(..., writableStackTrace = false)`
18+
*
1719
* @author Paul Phillips
1820
* @since 2.8
1921
*/

0 commit comments

Comments
 (0)