Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dotty compile with 2.12.3 #2827

Merged
merged 21 commits into from Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/config/CompilerCommand.scala
Expand Up @@ -6,6 +6,7 @@ import Settings._
import core.Contexts._
import util.DotClass
import Properties._
import scala.collection.JavaConverters._

object CompilerCommand extends DotClass {

Expand Down Expand Up @@ -43,10 +44,9 @@ object CompilerCommand extends DotClass {
if (!Files.exists(path))
throw new java.io.FileNotFoundException("argument file %s could not be found" format path.getFileName)

import scala.collection.JavaConversions._
val lines = Files.readAllLines(path) // default to UTF-8 encoding

val params = lines map stripComment mkString " "
val params = lines.asScala map stripComment mkString " "
CommandLineParser.tokenize(params)
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
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
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/parsing/MarkupParsers.scala
Expand Up @@ -85,9 +85,9 @@ object MarkupParsers {

var xEmbeddedBlock = false

private var debugLastStartElement = new mutable.Stack[(Int, String)]
private def debugLastPos = debugLastStartElement.top._1
private def debugLastElem = debugLastStartElement.top._2
private var debugLastStartElement = List.empty[(Int, String)]
private def debugLastPos = debugLastStartElement.head._1
private def debugLastElem = debugLastStartElement.head._2

private def errorBraces() = {
reportSyntaxError("in XML content, please use '}}' to express '}'")
Expand Down Expand Up @@ -280,10 +280,10 @@ object MarkupParsers {
if (qname == "xml:unparsed")
return xUnparsed

debugLastStartElement.push((start, qname))
debugLastStartElement = (start, qname) :: debugLastStartElement
val ts = content
xEndTag(qname)
debugLastStartElement.pop()
debugLastStartElement = debugLastStartElement.tail
val pos = Position(start, curOffset, start)
qname match {
case "xml:group" => handle.group(pos, ts)
Expand Down Expand Up @@ -417,7 +417,7 @@ object MarkupParsers {
def xPattern: Tree = {
var start = curOffset
val qname = xName
debugLastStartElement.push((start, qname))
debugLastStartElement = (start, qname) :: debugLastStartElement
xSpaceOpt()

val ts = new ArrayBuffer[Tree]
Expand Down Expand Up @@ -457,7 +457,7 @@ object MarkupParsers {

while (doPattern) { } // call until false
xEndTag(qname)
debugLastStartElement.pop()
debugLastStartElement = debugLastStartElement.tail
}

handle.makeXMLpat(Position(start, curOffset, start), qname, ts)
Expand Down
30 changes: 9 additions & 21 deletions compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala
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
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala
Expand Up @@ -50,9 +50,18 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisTran

/** Copy definitions from implementation class to trait itself */
private def augmentScala_2_12_Trait(mixin: ClassSymbol)(implicit ctx: Context): Unit = {
def info_2_12(sym: Symbol) = sym.info match {
case mt @ MethodType(paramNames @ nme.SELF :: _) =>
// 2.12 seems to always assume the enclsing mixin class as self type parameter,
// whereas 2.11 used the self type of this class instead.
val selfType :: otherParamTypes = mt.paramInfos
MethodType(paramNames, mixin.typeRef :: otherParamTypes, mt.resType)
case info => info
}
def newImpl(sym: TermSymbol): Symbol = sym.copy(
owner = mixin,
name = if (sym.isConstructor) sym.name else ImplMethName(sym.name)
name = if (sym.isConstructor) sym.name else ImplMethName(sym.name),
info = info_2_12(sym)
)
for (sym <- mixin.implClass.info.decls)
newImpl(sym.asTerm).enteredAfter(thisTransform)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala
Expand Up @@ -112,10 +112,10 @@ class VarianceChecker()(implicit ctx: Context) {
case Some(VarianceError(tvar, required)) =>
def msg = i"${varianceString(tvar.flags)} $tvar occurs in ${varianceString(required)} position in type ${sym.info} of $sym"
if (ctx.scala2Mode && sym.owner.isConstructor) {
ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", sym.pos)
ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", pos)
patch(Position(pos.end), " @scala.annotation.unchecked.uncheckedVariance") // TODO use an import or shorten if possible
}
else ctx.error(msg, sym.pos)
else ctx.error(msg, pos)
case None =>
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/test/dotc/scala-collections.blacklist
@@ -1,3 +1,6 @@
scala/runtime/ScalaRunTime.scala
# Doesn't compile since we're not on 2.11 anymore

## Errors having to do with bootstrap

scala/Function1.scala
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotc/tests.scala
Expand Up @@ -224,7 +224,7 @@ class tests extends CompilerTest {
|../scala2-library/src/library/scala/package.scala
|../scala2-library/src/library/scala/collection/GenSeqLike.scala
|../scala2-library/src/library/scala/collection/SeqLike.scala
|../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala""".stripMargin)
|../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala""".stripMargin)(scala2mode ++ defaultOptions)
@Test def compileIndexedSeq = compileLine("../scala2-library/src/library/scala/collection/immutable/IndexedSeq.scala")
@Test def compileParSetLike = compileLine("../scala2-library/src/library/scala/collection/parallel/mutable/ParSetLike.scala")
@Test def compileParSetSubset = compileLine(
Expand Down
16 changes: 8 additions & 8 deletions compiler/test/dotty/tools/ShowClassTests.scala
Expand Up @@ -64,14 +64,14 @@ class ShowClassTests extends DottyTest {
if (blackList contains path)
debug_println(s"blacklisted package: $path")
else {
for (
sym <- pkg.info.decls if sym.owner == pkg.moduleClass && !(sym.name.toString contains '$')
) {
debug_println(s"showing $sym in ${pkg.fullName}")
if (sym is PackageVal) showPackage(sym.asTerm)
else if (sym.isClass && !(sym is Module)) showClass(sym)
else if (sym is ModuleVal) showClass(sym.moduleClass)
}
pkg.info.decls
.filter(sym => sym.owner == pkg.moduleClass && !(sym.name.toString contains '$'))
.foreach { sym =>
debug_println(s"showing $sym in ${pkg.fullName}")
if (sym is PackageVal) showPackage(sym.asTerm)
else if (sym.isClass && !(sym is Module)) showClass(sym)
else if (sym is ModuleVal) showClass(sym.moduleClass)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Expand Up @@ -57,7 +57,7 @@ class CompilationTests extends ParallelTesting {
"../scala2-library/src/library/scala/collection/SeqLike.scala",
"../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala"
),
defaultOptions
scala2Mode
) +
compileFilesInDir("../tests/pos-special/spec-t5545", defaultOptions) +
compileFilesInDir("../tests/pos-special/strawman-collections", defaultOptions) +
Expand Down
10 changes: 5 additions & 5 deletions compiler/test/dotty/tools/vulpix/SummaryReport.scala
Expand Up @@ -59,7 +59,7 @@ final class NoSummaryReport extends SummaryReporting {
* which outputs to a log file in `./testlogs/`
*/
final class SummaryReport extends SummaryReporting {
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

private val startingMessages = new java.util.concurrent.ConcurrentLinkedDeque[String]
private val failedTests = new java.util.concurrent.ConcurrentLinkedDeque[String]
Expand Down Expand Up @@ -102,9 +102,9 @@ final class SummaryReport extends SummaryReporting {
|""".stripMargin
)

startingMessages.foreach(rep.append)
startingMessages.asScala.foreach(rep.append)

failedTests.map(x => s" $x\n").foreach(rep.append)
failedTests.asScala.map(x => s" $x\n").foreach(rep.append)

// If we're compiling locally, we don't need instructions on how to
// reproduce failures
Expand All @@ -121,15 +121,15 @@ final class SummaryReport extends SummaryReporting {

rep += '\n'

reproduceInstructions.foreach(rep.append)
reproduceInstructions.asScala.foreach(rep.append)

// If we're on the CI, we want everything
if (!isInteractive) println(rep.toString)

TestReporter.logPrintln(rep.toString)

// Perform cleanup callback:
if (cleanUps.nonEmpty) cleanUps.foreach(_.apply())
if (!cleanUps.isEmpty()) cleanUps.asScala.foreach(_.apply())
}

private def removeColors(msg: String): String =
Expand Down
16 changes: 14 additions & 2 deletions library/src/dotty/runtime/LazyVals.scala
Expand Up @@ -6,7 +6,19 @@ import scala.annotation.tailrec
* Helper methods used in thread-safe lazy vals.
*/
object LazyVals {
private val unsafe = scala.concurrent.util.Unsafe.instance
private val unsafe: sun.misc.Unsafe =
classOf[sun.misc.Unsafe].getDeclaredFields.find { field =>
field.getType == classOf[sun.misc.Unsafe] && {
field.setAccessible(true)
true
}
}
.map(_.get(null).asInstanceOf[sun.misc.Unsafe])
.getOrElse {
throw new ExceptionInInitializerError {
new IllegalStateException("Can't find instance of sun.misc.Unsafe")
}
}

final val BITS_PER_LAZY_VAL = 2L
final val LAZY_VAL_MASK = 3L
Expand All @@ -22,7 +34,7 @@ object LazyVals {
if (debug)
println(s"CAS($t, $offset, $e, $v, $ord)")
val mask = ~(LAZY_VAL_MASK << ord * BITS_PER_LAZY_VAL)
val n = (e & mask) | (v << (ord * BITS_PER_LAZY_VAL))
val n = (e & mask) | (v.toLong << (ord * BITS_PER_LAZY_VAL))
compareAndSet(t, offset, e, n)
}
@inline def setFlag(t: Object, offset: Long, v: Int, ord: Int) = {
Expand Down
5 changes: 2 additions & 3 deletions library/src/scala/compat/java8/JFunction1.java
Expand Up @@ -13,13 +13,12 @@ public interface JFunction1<T1, R> extends scala.Function1<T1, R> {
@Override
@SuppressWarnings("unchecked")
default <A> scala.Function1<T1, A> andThen(scala.Function1<R, A> g) {
return scala.Function1$class.andThen(this, g);
return x -> g.apply(this.apply(x));
}

@Override
@SuppressWarnings("unchecked")
default <A> scala.Function1<A, R> compose(scala.Function1<A, T1> g) {
return scala.Function1$class.compose(this, g);
return x -> this.apply(g.apply(x));
}
@SuppressWarnings("unchecked")
default void apply$mcVI$sp(int v1) {
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/compat/java8/JFunction10.java
Expand Up @@ -12,12 +12,12 @@ public interface JFunction10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> extends

@SuppressWarnings("unchecked")
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, R>>>>>>>>>> curried() {
return scala.Function10$class.curried(this);
throw new UnsupportedOperationException("todo");
}

@SuppressWarnings("unchecked")
default scala.Function1<scala.Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, R> tupled() {
return scala.Function10$class.tupled(this);
throw new UnsupportedOperationException("todo");
}


Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/compat/java8/JFunction11.java
Expand Up @@ -12,12 +12,12 @@ public interface JFunction11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R> ex

@SuppressWarnings("unchecked")
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, R>>>>>>>>>>> curried() {
return scala.Function11$class.curried(this);
throw new UnsupportedOperationException("todo");
}

@SuppressWarnings("unchecked")
default scala.Function1<scala.Tuple11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, R> tupled() {
return scala.Function11$class.tupled(this);
throw new UnsupportedOperationException("todo");
}


Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/compat/java8/JFunction12.java
Expand Up @@ -12,12 +12,12 @@ public interface JFunction12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,

@SuppressWarnings("unchecked")
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, R>>>>>>>>>>>> curried() {
return scala.Function12$class.curried(this);
throw new UnsupportedOperationException("todo");
}

@SuppressWarnings("unchecked")
default scala.Function1<scala.Tuple12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, R> tupled() {
return scala.Function12$class.tupled(this);
throw new UnsupportedOperationException("todo");
}


Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/compat/java8/JFunction13.java
Expand Up @@ -12,12 +12,12 @@ public interface JFunction13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,

@SuppressWarnings("unchecked")
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, scala.Function1<T13, R>>>>>>>>>>>>> curried() {
return scala.Function13$class.curried(this);
throw new UnsupportedOperationException("todo");
}

@SuppressWarnings("unchecked")
default scala.Function1<scala.Tuple13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, R> tupled() {
return scala.Function13$class.tupled(this);
throw new UnsupportedOperationException("todo");
}


Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/compat/java8/JFunction14.java
Expand Up @@ -12,12 +12,12 @@ public interface JFunction14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,

@SuppressWarnings("unchecked")
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, scala.Function1<T13, scala.Function1<T14, R>>>>>>>>>>>>>> curried() {
return scala.Function14$class.curried(this);
throw new UnsupportedOperationException("todo");
}

@SuppressWarnings("unchecked")
default scala.Function1<scala.Tuple14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, R> tupled() {
return scala.Function14$class.tupled(this);
throw new UnsupportedOperationException("todo");
}


Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/compat/java8/JFunction15.java
Expand Up @@ -12,12 +12,12 @@ public interface JFunction15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,

@SuppressWarnings("unchecked")
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, scala.Function1<T13, scala.Function1<T14, scala.Function1<T15, R>>>>>>>>>>>>>>> curried() {
return scala.Function15$class.curried(this);
throw new UnsupportedOperationException("todo");
}

@SuppressWarnings("unchecked")
default scala.Function1<scala.Tuple15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, R> tupled() {
return scala.Function15$class.tupled(this);
throw new UnsupportedOperationException("todo");
}


Expand Down