summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Doeraene <sjrdoeraene@gmail.com>2016-04-13 11:54:47 +0200
committerSébastien Doeraene <sjrdoeraene@gmail.com>2016-04-13 12:03:45 +0200
commit6090f53ee9ab2677f732ea5cc7144cb9684b2593 (patch)
tree283d7922bb9b39480c1ebc0655087e077d191961
parent00050c6bd06928b045e583c7f15f1223faf6fbee (diff)
downloadscala-6090f53ee9ab2677f732ea5cc7144cb9684b2593.tar.gz
scala-6090f53ee9ab2677f732ea5cc7144cb9684b2593.tar.bz2
scala-6090f53ee9ab2677f732ea5cc7144cb9684b2593.zip
Remove dead-code runtime hash() methods.
ScalaRunTime had a bunch of overloads of the `hash()` method, but only the `Any` version is ever used by the codegen. Worse, their implementation was not in sync with the actual implementations in BoxesRunTime, called by the `Any` version. For example, hash(0x80000000L) != hash(0x80000000L: Any) This commit simply removes all of this dead code. Similarly, we remove BoxesRunTime.hashFromObject(), which was never called either.
-rw-r--r--src/library/scala/runtime/BoxesRunTime.java4
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala41
-rw-r--r--test/files/pos/t5644/BoxesRunTime.java4
-rw-r--r--test/files/run/hashCodeBoxesRunTime.scala5
-rw-r--r--test/instrumented/library/scala/runtime/BoxesRunTime.java4
-rw-r--r--test/instrumented/library/scala/runtime/ScalaRunTime.scala41
6 files changed, 5 insertions, 94 deletions
diff --git a/src/library/scala/runtime/BoxesRunTime.java b/src/library/scala/runtime/BoxesRunTime.java
index 9ae118f43f..b6b512d529 100644
--- a/src/library/scala/runtime/BoxesRunTime.java
+++ b/src/library/scala/runtime/BoxesRunTime.java
@@ -257,10 +257,6 @@ public final class BoxesRunTime
else if (n instanceof java.lang.Float) return hashFromFloat((java.lang.Float)n);
else return n.hashCode();
}
- public static int hashFromObject(Object a) {
- if (a instanceof Number) return hashFromNumber((Number)a);
- else return a.hashCode();
- }
private static int unboxCharOrInt(Object arg1, int code) {
if (code == CHAR)
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 4c85eaa9ee..9a2c917ae2 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -193,51 +193,12 @@ object ScalaRunTime {
case _ => false
}
- // hashcode -----------------------------------------------------------
- //
- // Note that these are the implementations called by ##, so they
- // must not call ## themselves.
-
+ /** Implementation of `##`. */
def hash(x: Any): Int =
if (x == null) 0
else if (x.isInstanceOf[java.lang.Number]) BoxesRunTime.hashFromNumber(x.asInstanceOf[java.lang.Number])
else x.hashCode
- def hash(dv: Double): Int = {
- val iv = dv.toInt
- if (iv == dv) return iv
-
- val lv = dv.toLong
- if (lv == dv) return lv.hashCode
-
- val fv = dv.toFloat
- if (fv == dv) fv.hashCode else dv.hashCode
- }
- def hash(fv: Float): Int = {
- val iv = fv.toInt
- if (iv == fv) return iv
-
- val lv = fv.toLong
- if (lv == fv) hash(lv)
- else fv.hashCode
- }
- def hash(lv: Long): Int = {
- val low = lv.toInt
- val lowSign = low >>> 31
- val high = (lv >>> 32).toInt
- low ^ (high + lowSign)
- }
- def hash(x: Number): Int = runtime.BoxesRunTime.hashFromNumber(x)
-
- // The remaining overloads are here for completeness, but the compiler
- // inlines these definitions directly so they're not generally used.
- def hash(x: Int): Int = x
- def hash(x: Short): Int = x.toInt
- def hash(x: Byte): Int = x.toInt
- def hash(x: Char): Int = x.toInt
- def hash(x: Boolean): Int = if (x) true.hashCode else false.hashCode
- def hash(x: Unit): Int = 0
-
/** A helper method for constructing case class equality methods,
* because existential types get in the way of a clean outcome and
* it's performing a series of Any/Any equals comparisons anyway.
diff --git a/test/files/pos/t5644/BoxesRunTime.java b/test/files/pos/t5644/BoxesRunTime.java
index 74c4c6b4b9..2b931519aa 100644
--- a/test/files/pos/t5644/BoxesRunTime.java
+++ b/test/files/pos/t5644/BoxesRunTime.java
@@ -267,10 +267,6 @@ public final class BoxesRunTime
else if (n instanceof java.lang.Float) return hashFromFloat((java.lang.Float)n);
else return n.hashCode();
}
- public static int hashFromObject(Object a) {
- if (a instanceof Number) return hashFromNumber((Number)a);
- else return a.hashCode();
- }
private static int unboxCharOrInt(Object arg1, int code) {
if (code == CHAR)
diff --git a/test/files/run/hashCodeBoxesRunTime.scala b/test/files/run/hashCodeBoxesRunTime.scala
index ba1a30f5fb..8ad94c252a 100644
--- a/test/files/run/hashCodeBoxesRunTime.scala
+++ b/test/files/run/hashCodeBoxesRunTime.scala
@@ -3,7 +3,8 @@
object Test
{
import java.{ lang => jl }
- import scala.runtime.BoxesRunTime.{ hashFromNumber, hashFromObject }
+ import scala.runtime.BoxesRunTime.hashFromNumber
+ import scala.runtime.ScalaRunTime.{ hash => hashFromAny }
def allSame[T](xs: List[T]) = assert(xs.distinct.size == 1, "failed: " + xs)
@@ -17,7 +18,7 @@ object Test
val hashes = mkNumbers(n) map hashFromNumber
allSame(hashes)
if (n >= 0) {
- val charCode = hashFromObject(n.toChar: Character)
+ val charCode = hashFromAny(n.toChar: Character)
assert(charCode == hashes.head)
}
}
diff --git a/test/instrumented/library/scala/runtime/BoxesRunTime.java b/test/instrumented/library/scala/runtime/BoxesRunTime.java
index 57799bd9b1..05ce2941a8 100644
--- a/test/instrumented/library/scala/runtime/BoxesRunTime.java
+++ b/test/instrumented/library/scala/runtime/BoxesRunTime.java
@@ -278,10 +278,6 @@ public final class BoxesRunTime
else if (n instanceof java.lang.Float) return hashFromFloat((java.lang.Float)n);
else return n.hashCode();
}
- public static int hashFromObject(Object a) {
- if (a instanceof Number) return hashFromNumber((Number)a);
- else return a.hashCode();
- }
private static int unboxCharOrInt(Object arg1, int code) {
if (code == CHAR)
diff --git a/test/instrumented/library/scala/runtime/ScalaRunTime.scala b/test/instrumented/library/scala/runtime/ScalaRunTime.scala
index ca59fc1509..9df3bea5d9 100644
--- a/test/instrumented/library/scala/runtime/ScalaRunTime.scala
+++ b/test/instrumented/library/scala/runtime/ScalaRunTime.scala
@@ -205,51 +205,12 @@ object ScalaRunTime {
case _ => false
}
- // hashcode -----------------------------------------------------------
- //
- // Note that these are the implementations called by ##, so they
- // must not call ## themselves.
-
+ /** Implementation of `##`. */
def hash(x: Any): Int =
if (x == null) 0
else if (x.isInstanceOf[java.lang.Number]) BoxesRunTime.hashFromNumber(x.asInstanceOf[java.lang.Number])
else x.hashCode
- def hash(dv: Double): Int = {
- val iv = dv.toInt
- if (iv == dv) return iv
-
- val lv = dv.toLong
- if (lv == dv) return lv.hashCode
-
- val fv = dv.toFloat
- if (fv == dv) fv.hashCode else dv.hashCode
- }
- def hash(fv: Float): Int = {
- val iv = fv.toInt
- if (iv == fv) return iv
-
- val lv = fv.toLong
- if (lv == fv) return hash(lv)
- else fv.hashCode
- }
- def hash(lv: Long): Int = {
- val low = lv.toInt
- val lowSign = low >>> 31
- val high = (lv >>> 32).toInt
- low ^ (high + lowSign)
- }
- def hash(x: Number): Int = runtime.BoxesRunTime.hashFromNumber(x)
-
- // The remaining overloads are here for completeness, but the compiler
- // inlines these definitions directly so they're not generally used.
- def hash(x: Int): Int = x
- def hash(x: Short): Int = x.toInt
- def hash(x: Byte): Int = x.toInt
- def hash(x: Char): Int = x.toInt
- def hash(x: Boolean): Int = if (x) true.hashCode else false.hashCode
- def hash(x: Unit): Int = 0
-
/** A helper method for constructing case class equality methods,
* because existential types get in the way of a clean outcome and
* it's performing a series of Any/Any equals comparisons anyway.