summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-11-09 22:03:12 +0000
committerPaul Phillips <paulp@improving.org>2009-11-09 22:03:12 +0000
commita0159da70da18f65863947aa4d016ca52fd7bb4f (patch)
tree916acfd275d3c0bf3c59aa9d599fed37162c2c9a /src/compiler
parent26a13165f4a00ce8c0336058fbde937ddb59e718 (diff)
downloadscala-a0159da70da18f65863947aa4d016ca52fd7bb4f.tar.gz
scala-a0159da70da18f65863947aa4d016ca52fd7bb4f.tar.bz2
scala-a0159da70da18f65863947aa4d016ca52fd7bb4f.zip
Breaks down the hash function in BoxesRunTime b...
Breaks down the hash function in BoxesRunTime by type so we can do as much as possible at compile time. Documents various trouble points I've identified with trying to get the hashCodes aligned. Test case exercises the hashCode functions. Deleted all the code associated with previous equality adventures. Don't worry, I can put anything back if it turns out we have to change course again, but for now it's noise. Also, gives return types to the box and unbox methods which are added to the primitive companions, so e.g. Int.box(5) now returns a j.l.Integer instead of an Object.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala10
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala25
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala6
4 files changed, 7 insertions, 47 deletions
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 95c3a56767..0f59d9a3d9 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -839,16 +839,6 @@ trait ScalacSettings {
val YhigherKindedRaw = BooleanSetting ("-Yhigher-kinded-raw", "(temporary!) Treat raw Java types as higher-kinded types.")
val Yjenkins = BooleanSetting ("-Yjenkins-hashCodes", "Use jenkins hash algorithm for case class generated hashCodes.")
- // Equality specific
- val logEqEq = BooleanSetting ("-Ylog-eqeq", "Log all noteworthy equality tests") .
- withPostSetHook(() => scala.runtime.Equality.logEverything = true)
- val YfutureEqEq = BooleanSetting ("-Yfuture-eqeq", "Use proposed overloading-based numeric equality semantics.") .
- withPostSetHook(() => scala.runtime.Equality.use28Semantics = true)
- val YwarnEqEq = BooleanSetting ("-Ywarn-eqeq", "Warn when boxed primitives of different types are compared.") .
- withPostSetHook(() => scala.runtime.Equality.warnOnBoxedCompare = true)
- val YdieEqEq = BooleanSetting ("-Ydie-changed-eqeq", "Throw an exception if a comparison would have come back differently in scala 2.7.") .
- withPostSetHook(() => scala.runtime.Equality.dieOnBoxedCompareIfValuesAreEqual = true)
-
// Warnings
val Xwarninit = BooleanSetting ("-Xwarninit", "Warn about possible changes in initialization semantics")
val Xchecknull = BooleanSetting ("-Xcheck-null", "Emit warning on selection of nullable reference")
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index d12bf0c2c5..e1ddd260cb 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1292,9 +1292,6 @@ abstract class GenICode extends SubComponent {
elseCtx: Context): Unit =
{
def genComparisonOp(l: Tree, r: Tree, code: Int) {
- if (settings.logEqEq.value && isUniversalEqualityOp(code))
- logEqEq(tree, l, r, code)
-
val op: TestOp = code match {
case scalaPrimitives.LT => LT
case scalaPrimitives.LE => LE
@@ -1423,13 +1420,8 @@ abstract class GenICode extends SubComponent {
(rsym == ObjectClass) ||
(lsym != rsym) && (isBoxed(lsym) || isBoxed(rsym))
}
- def cannotAvoidBoxesRuntime =
- settings.logEqEq.value || settings.YwarnEqEq.value || settings.YdieEqEq.value
- /** We can avoid generating calls to BoxesRuntime only if -Yfuture-eqeq
- * is enabled AND none of the eqeq logging options are enabled.
- */
- if (mustUseAnyComparator && (!settings.YfutureEqEq.value || cannotAvoidBoxesRuntime)) {
+ if (mustUseAnyComparator) {
var equalsMethod = BoxesRunTime_equals
// when -optimise is on we call the @inline-version of equals, found in ScalaRunTime
if (settings.XO.value) {
@@ -2161,19 +2153,4 @@ abstract class GenICode extends SubComponent {
override def toString() = "[]"
override def varsInScope: Buffer[Local] = new ListBuffer
}
-
- /** Log equality tests between different primitives. */
- def logEqEq(tree: Tree, l: Tree, r: Tree, code: Int) {
- import definitions._
- val op = if (code == scalaPrimitives.EQ) "==" else if (code == scalaPrimitives.NE) "!=" else "??"
- val tkl = toTypeKind(l.tpe)
- val tkr = toTypeKind(r.tpe)
-
- if (tkl.isNumericType && tkr.isNumericType && tkl != tkr)
- runtime.Equality.logComparison(
- "Comparing actual primitives",
- "%s %s %s".format(l.tpe, op, r.tpe),
- tree.pos.source + ":" + tree.pos.line
- )
- }
}
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 365bff38e6..cb9c681075 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -557,11 +557,9 @@ trait Definitions {
mclass.setInfo(ClassInfoType(List(), new Scope, mclass))
module.setInfo(mclass.tpe)
- val box = newMethod(mclass, nme.box, List(clazz.typeConstructor),
- ObjectClass.typeConstructor)
+ val box = newMethod(mclass, nme.box, List(clazz.typeConstructor), boxedClass(clazz).tpe)
boxMethod(clazz) = box
- val unbox = newMethod(mclass, nme.unbox, List(ObjectClass.typeConstructor),
- clazz.typeConstructor)
+ val unbox = newMethod(mclass, nme.unbox, List(ObjectClass.typeConstructor), clazz.typeConstructor)
unboxMethod(clazz) = unbox
clazz
@@ -624,10 +622,11 @@ trait Definitions {
// def +(s: String): String
newMethod(clazz, nme.ADD, List(stringtype), stringtype)
- val restype = clazz match {
- case LongClass | FloatClass | DoubleClass => clazz.typeConstructor
- case _ => inttype
+ def isLongFloatOrDouble = clazz match {
+ case LongClass | FloatClass | DoubleClass => true
+ case _ => false
}
+ val restype = if (isLongFloatOrDouble) clazz.typeConstructor else inttype
// shift operations
if (isCardinal)
diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
index e8bb4581f1..ba328b9f48 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
@@ -152,12 +152,6 @@ abstract class ConstantFolder {
}
private def foldBinop(op: Name, x: Constant, y: Constant): Constant = {
- // temporarily logging folded ==/!= so the log doesn't have unexplained absences
- // Careful, these four lines added 3 minutes to the time to compile this file under -optimise
- // if ((op == nme.EQ || op == nme.NE) && x.tag != y.tag && settings.logEqEq.value) {
- // val opstr = if (op == nme.EQ) "==" else "!="
- // scala.runtime.Equality.log("Folding constant expression (%s %s %s)".format(x.value, opstr, y.value))
- // }
val optag =
if (x.tag == y.tag) x.tag
else if (isNumeric(x.tag) && isNumeric(y.tag)) Math.max(x.tag, y.tag)