Skip to content

Commit

Permalink
Almost fix issue with anyHash (rebase)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmulder committed Aug 9, 2017
1 parent 2ae0ed0 commit 8a21c3d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,15 @@ object StdNames {
val ArrayAnnotArg: N = "ArrayAnnotArg"
val Constant: N = "Constant"
val ConstantType: N = "ConstantType"
val doubleHash: N = "doubleHash"
val ExistentialTypeTree: N = "ExistentialTypeTree"
val Flag : N = "Flag"
val floatHash: N = "floatHash"
val Ident: N = "Ident"
val Import: N = "Import"
val Literal: N = "Literal"
val LiteralAnnotArg: N = "LiteralAnnotArg"
val longHash: N = "longHash"
val Modifiers: N = "Modifiers"
val NestedAnnotArg: N = "NestedAnnotArg"
val NoFlags: N = "NoFlags"
Expand All @@ -353,6 +356,7 @@ object StdNames {
val UNIT : N = "UNIT"
val add_ : N = "add"
val annotation: N = "annotation"
val anyHash: N = "anyHash"
val anyValClass: N = "anyValClass"
val append: N = "append"
val apply: N = "apply"
Expand Down
30 changes: 9 additions & 21 deletions compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.ast.{untpd, tpd}
import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Types.MethodType
import dotty.tools.dotc.core.Names.Name
import dotty.tools.dotc.core.Names.{ Name, TermName }
import scala.collection.mutable.ListBuffer
import dotty.tools.dotc.core.Denotations.SingleDenotation
import dotty.tools.dotc.core.SymDenotations.SymDenotation
Expand Down Expand Up @@ -64,30 +64,18 @@ class InterceptedMethods extends MiniPhaseTransform {
else tree
}

// TODO: add missing cases from scalac
private def poundPoundValue(tree: Tree)(implicit ctx: Context) = {
val s = tree.tpe.widen.typeSymbol
if (s == defn.NullClass) Literal(Constant(0))
else {
// Since we are past typer, we need to avoid creating trees carrying
// overloaded types. This logic is custom (and technically incomplete,
// although serviceable) for def hash. What is really needed is for
// the overloading logic presently hidden away in a few different
// places to be properly exposed so we can just call "resolveOverload"
// after typer. Until then:

def alts = defn.ScalaRuntimeModule.info.member(nme.hash_)

// if tpe is a primitive value type, alt1 will match on the exact value,
// taking in account that null.asInstanceOf[Int] == 0
def alt1 = alts.suchThat(_.info.firstParamTypes.head =:= tree.tpe.widen)

// otherwise alt2 will match. alt2 also knows how to handle 'null' runtime value
def alt2 = defn.ScalaRuntimeModule.info.member(nme.hash_)
.suchThat(_.info.firstParamTypes.head.typeSymbol == defn.AnyClass)
def staticsCall(methodName: TermName): Tree =
ref(defn.staticsMethodRef(methodName)).appliedTo(tree)

Ident((if (s.isNumericValueClass) alt1 else alt2).termRef)
.appliedTo(tree)
}
if (s == defn.NullClass) Literal(Constant(0))
else if (s == defn.DoubleClass) staticsCall(nme.doubleHash)
else if (s == defn.LongClass) staticsCall(nme.longHash)
else if (s == defn.FloatClass) staticsCall(nme.floatHash)
else staticsCall(nme.anyHash)
}

override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = {
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ object Build {

// get libraries onboard
libraryDependencies ++= Seq("com.typesafe.sbt" % "sbt-interface" % sbtVersion.value,
("org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6").withDottyCompat(),
("org.scala-lang.modules" %% "scala-xml" % "1.0.6").withDottyCompat(),
"com.novocode" % "junit-interface" % "0.11" % "test",
"org.scala-lang" % "scala-library" % scalacVersion % "test"),

Expand Down
2 changes: 2 additions & 0 deletions sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ object DottyPlugin extends AutoPlugin {
moduleID.crossVersion match {
case _: CrossVersion.Binary =>
moduleID.cross(CrossVersion.binaryMapped {
// TODO: this will break on release of >= 0.4
case version if version.startsWith("0.3") => "2.12"
case version if version.startsWith("0.") => "2.11"
case version => version
})
Expand Down

0 comments on commit 8a21c3d

Please sign in to comment.