Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

No implicit widening conversions ... #30

Closed
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
40 changes: 40 additions & 0 deletions bincompat-backward.whitelist.conf
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,46 @@ filter {
{
matchName="scala.collection.immutable.Stream.filteredTail"
problemName=MissingMethodProblem
},
{
matchName="scala.Long.long2double"
problemName=MissingMethodProblem
},
{
matchName="scala.Long.long2float"
problemName=MissingMethodProblem
},
{
matchName="scala.Byte.byte2float"
problemName=MissingMethodProblem
},
{
matchName="scala.Byte.byte2double"
problemName=MissingMethodProblem
},
{
matchName="scala.Char.char2float"
problemName=MissingMethodProblem
},
{
matchName="scala.Char.char2double"
problemName=MissingMethodProblem
},
{
matchName="scala.Int.int2double"
problemName=MissingMethodProblem
},
{
matchName="scala.Int.int2float"
problemName=MissingMethodProblem
},
{
matchName="scala.Short.short2float"
problemName=MissingMethodProblem
},
{
matchName="scala.Short.short2double"
problemName=MissingMethodProblem
}
]
}
2 changes: 1 addition & 1 deletion src/actors/scala/actors/remote/TcpService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class TcpService(port: Int, cl: ClassLoader) extends Thread with Service {
socket.connect(new InetSocketAddress(n.address, n.port), TcpService.connectTimeoutMillis)
} catch {
case e: SocketTimeoutException =>
Debug.warning(f"Timed out connecting to $n after ${(System.nanoTime - start) / math.pow(10, 9)}%.3f seconds")
Debug.warning(f"Timed out connecting to $n after ${(System.nanoTime - start) / math.pow(10.0, 9.0)}%.3f seconds")
throw e
}
val worker = new TcpServiceWorker(this, socket)
Expand Down
7 changes: 3 additions & 4 deletions src/compiler/scala/tools/cmd/gen/AnyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import scala.language.implicitConversions"""

def implicitCoercions: List[String] = {
val coercions = this match {
case B => companionCoercions(S, I, L, F, D)
case S | C => companionCoercions(I, L, F, D)
case I => companionCoercions(L, F, D)
case L => companionCoercions(F, D)
case B => companionCoercions(S, I, L)
case S | C => companionCoercions(I, L)
case I => companionCoercions(L)
case F => companionCoercions(D)
case _ => Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
CHAR |
INT => bc.iconst(0)
case LONG => bc.lconst(0)
case FLOAT => bc.fconst(0)
case DOUBLE => bc.dconst(0)
case FLOAT => bc.fconst(0f)
case DOUBLE => bc.dconst(0d)
case UNIT => ()
case _ => emit(asm.Opcodes.ACONST_NULL)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ abstract class BCodeIdiomatic extends SubComponent {
val isDenseEnough: Boolean = {
/* Calculate in long to guard against overflow. TODO what overflow? */
val keyRangeD: Double = (keyMax.asInstanceOf[Long] - keyMin + 1).asInstanceOf[Double]
val klenD: Double = keys.length
val klenD: Double = keys.length.toDouble
val kdensity: Double = (klenD / keyRangeD)

kdensity >= minDensity
Expand Down
2 changes: 0 additions & 2 deletions src/library/scala/Byte.scala
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,5 @@ object Byte extends AnyValCompanion {
implicit def byte2short(x: Byte): Short = x.toShort
implicit def byte2int(x: Byte): Int = x.toInt
implicit def byte2long(x: Byte): Long = x.toLong
implicit def byte2float(x: Byte): Float = x.toFloat
implicit def byte2double(x: Byte): Double = x.toDouble
}

2 changes: 0 additions & 2 deletions src/library/scala/Char.scala
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,5 @@ object Char extends AnyValCompanion {
import scala.language.implicitConversions
implicit def char2int(x: Char): Int = x.toInt
implicit def char2long(x: Char): Long = x.toLong
implicit def char2float(x: Char): Float = x.toFloat
implicit def char2double(x: Char): Double = x.toDouble
}

2 changes: 0 additions & 2 deletions src/library/scala/Int.scala
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,5 @@ object Int extends AnyValCompanion {
/** Language mandated coercions from Int to "wider" types. */
import scala.language.implicitConversions
implicit def int2long(x: Int): Long = x.toLong
implicit def int2float(x: Int): Float = x.toFloat
implicit def int2double(x: Int): Double = x.toDouble
}

4 changes: 0 additions & 4 deletions src/library/scala/Long.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,5 @@ object Long extends AnyValCompanion {

/** The String representation of the scala.Long companion object. */
override def toString = "object scala.Long"
/** Language mandated coercions from Long to "wider" types. */
import scala.language.implicitConversions
implicit def long2float(x: Long): Float = x.toFloat
implicit def long2double(x: Long): Double = x.toDouble
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comment paulp.


2 changes: 0 additions & 2 deletions src/library/scala/Short.scala
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,5 @@ object Short extends AnyValCompanion {
import scala.language.implicitConversions
implicit def short2int(x: Short): Int = x.toInt
implicit def short2long(x: Short): Long = x.toLong
implicit def short2float(x: Short): Float = x.toFloat
implicit def short2double(x: Short): Double = x.toDouble
}

2 changes: 1 addition & 1 deletion src/library/scala/collection/parallel/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private[parallel] final class FutureTasks(executor: ExecutionContext) extends Ta
import scala.concurrent._
import scala.util._

private val maxdepth = (math.log(parallelismLevel) / math.log(2) + 1).toInt
private val maxdepth = (math.log(parallelismLevel.toDouble) / math.log(2.toDouble) + 1).toInt

val environment: ExecutionContext = executor

Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/parallel/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package object parallel {
/* constants */
val MIN_FOR_COPY = 512
val CHECK_RATE = 512
val SQRT2 = math.sqrt(2)
val SQRT2 = math.sqrt(2.0)
val availableProcessors = java.lang.Runtime.getRuntime.availableProcessors

/* functions */
Expand Down
6 changes: 2 additions & 4 deletions src/reflect/scala/reflect/internal/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ trait Constants extends api.Constants {
def isCharRange: Boolean = isIntRange && Char.MinValue <= intValue && intValue <= Char.MaxValue
def isIntRange: Boolean = ByteTag <= tag && tag <= IntTag
def isLongRange: Boolean = ByteTag <= tag && tag <= LongTag
def isFloatRange: Boolean = ByteTag <= tag && tag <= FloatTag
def isDoubleRange: Boolean= FloatTag == tag || tag == DoubleTag
def isNumeric: Boolean = ByteTag <= tag && tag <= DoubleTag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what's going on here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is saying that only floats and doubles fit in doubles, instead of all the numeric types. Then it renames the method. Before there wasn't an "isDoubleRange" because in the context this was being used, that was always true. And afterward I suppose there's no "isFloatRange" because it would only be true for floats and thus never checked.

def isNonUnitAnyVal = BooleanTag <= tag && tag <= DoubleTag
def isAnyVal = UnitTag <= tag && tag <= DoubleTag
Expand Down Expand Up @@ -190,9 +190,7 @@ trait Constants extends api.Constants {
Constant(intValue)
else if (target == LongClass && isLongRange)
Constant(longValue)
else if (target == FloatClass && isFloatRange)
Constant(floatValue)
else if (target == DoubleClass && isNumeric)
else if (target == DoubleClass && isDoubleRange)
Constant(doubleValue)
else
null
Expand Down
4 changes: 2 additions & 2 deletions src/reflect/scala/reflect/internal/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ trait Definitions extends api.StandardDefinitions {
tpnme.Short -> 4,
tpnme.Int -> 12,
tpnme.Long -> 24,
tpnme.Float -> 48,
tpnme.Double -> 96
tpnme.Float -> 7,
tpnme.Double -> 35
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As "diffs that would make you leave the party" go that has to be up way up there. Replace magic numbers 48 and 96 with 7 and 35. And... voila!

It's an encoding of the weak conformance relation. If B % A == 0 then A weak_<:< B. In the case of Float, all the integral types were factors of 48, and afterward none of them are factors of 7. Could have been 5.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably for efficiency. Then we stash them in a Map ... oh! wait!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the efficiency is martin and the map is me, and it effectively reflects our different priorities.


private val nameToTag = Map[Name, Char](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class DotDiagramGenerator(settings: doc.Settings) extends DiagramGenerator {
if (kind != "")
if (((g \ "a" \ "image").isEmpty)) {
DiagramStats.addBrokenImage()
val xposition = getPosition(g, "x", -22)
val xposition = getPosition(g, "x", -22.0)
val yposition = getPosition(g, "y", -11.3334)
if (xposition.isDefined && yposition.isDefined) {
val imageNode = <image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href={ ("./lib/" + kind + "_diagram.png") } width="16px" height="16px" preserveAspectRatio="xMinYMin meet" x={ xposition.get.toString } y={ yposition.get.toString }/>
Expand Down
2 changes: 1 addition & 1 deletion test/junit/scala/collection/SetMapConsistencyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class SetMapConsistencyTest {
def mhm: M = { val m = new cm.HashMap[Int, Boolean]; m ++= manyKVs; m }
def mohm: M = { val m = new cm.OpenHashMap[Int, Boolean]; m ++= manyKVs; m }
def ihm: M = ci.HashMap.empty[Int, Boolean] ++ manyKVs
val densities = List(0, 0.05, 0.2, 0.5, 0.8, 0.95, 1)
val densities = List(0.0, 0.05, 0.2, 0.5, 0.8, 0.95, 1.0)
def repeat = rn.nextInt(100) < 33
def pick(m: M, density: Double) = m.keys.filter(_ => rn.nextDouble < density).toSet
def test: Boolean = {
Expand Down
2 changes: 1 addition & 1 deletion test/junit/scala/math/BigDecimalTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class BigDecimalTest {
val bi: BigInt = 100000
val bd: BigDecimal = 100000
val l: Long = 100000
val d: Double = 100000
val d: Double = 100000.0
assert(
d.## == l.## &&
l.## == bd.## &&
Expand Down