diff options
author | liu fengyun <liu@fengy.me> | 2017-04-13 15:03:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-13 15:03:13 +0200 |
commit | fb4adc3c9c55476d2fe0deed22cff54e8e945406 (patch) | |
tree | b7577f66688ed793a73ff543042a140e62cbe80d /compiler | |
parent | cf37737f56db7bc2f7429f78328dc5eea1716356 (diff) | |
parent | de6461ab17562dbb46a1ff094590e051d03cb54c (diff) | |
download | dotty-fb4adc3c9c55476d2fe0deed22cff54e8e945406.tar.gz dotty-fb4adc3c9c55476d2fe0deed22cff54e8e945406.tar.bz2 dotty-fb4adc3c9c55476d2fe0deed22cff54e8e945406.zip |
Merge branch 'master' into fix-2253
Diffstat (limited to 'compiler')
13 files changed, 84 insertions, 43 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index a97589d73..eee6ba785 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -10,7 +10,6 @@ import scala.collection.{ mutable, immutable } import PartialFunction._ import collection.mutable import util.common.alwaysZero -import typer.Applications object Definitions { @@ -846,6 +845,9 @@ class Definitions { TupleType(elems.size).appliedTo(elems) } + def isProductSubType(tp: Type)(implicit ctx: Context) = + tp.derivesFrom(ProductType.symbol) + /** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN? */ def isFunctionType(tp: Type)(implicit ctx: Context) = { val arity = functionArity(tp) diff --git a/compiler/src/dotty/tools/dotc/core/NameKinds.scala b/compiler/src/dotty/tools/dotc/core/NameKinds.scala index 0f08e4701..81ac3a02f 100644 --- a/compiler/src/dotty/tools/dotc/core/NameKinds.scala +++ b/compiler/src/dotty/tools/dotc/core/NameKinds.scala @@ -209,7 +209,7 @@ object NameKinds { val InlineAccessorName = new UniqueNameKind("$_inlineAccessor_$") val TempResultName = new UniqueNameKind("ev$") val EvidenceParamName = new UniqueNameKind("evidence$") - val DepParamName = new UniqueNameKind("<param>") + val DepParamName = new UniqueNameKind("(param)") val LazyImplicitName = new UniqueNameKind("$_lazy_implicit_$") val LazyLocalName = new UniqueNameKind("$lzy") val LazyLocalInitName = new UniqueNameKind("$lzyINIT") diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 9593bfe93..4a1c3d044 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -7,6 +7,7 @@ import SymDenotations._, Denotations.SingleDenotation import config.Printers.typr import util.Positions._ import NameOps._ +import NameKinds.DepParamName import Decorators._ import StdNames._ import Annotations._ @@ -158,7 +159,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object. case tp1 => tp1 } case tp: TypeParamRef => - typerState.constraint.typeVarOfParam(tp) orElse tp + if (tp.paramName.is(DepParamName)) { + val bounds = ctx.typeComparer.bounds(tp) + if (bounds.lo.isRef(defn.NothingClass)) bounds.hi else bounds.lo + } + else typerState.constraint.typeVarOfParam(tp) orElse tp case _: ThisType | _: BoundType | NoPrefix => tp case tp: RefinedType => diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index c8c1886cc..955a5a11c 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3509,7 +3509,7 @@ object Types { def apply(tp: Type): Type - protected var variance = 1 + protected[core] var variance = 1 protected def derivedSelect(tp: NamedType, pre: Type): Type = tp.derivedSelect(pre) diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 41a1218eb..447a003e7 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -1408,7 +1408,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer { protected def seqTree(binder: Symbol) = tupleSel(binder)(firstIndexingBinder + 1) protected def tupleSel(binder: Symbol)(i: Int): Tree = { val accessors = - if (Applications.canProductMatch(binder.info)) + if (defn.isProductSubType(binder.info)) productSelectors(binder.info) else binder.caseAccessors val res = diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index c4d3e2292..7e17abbcd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -48,9 +48,6 @@ object Applications { ref.info.widenExpr.dealias } - def canProductMatch(tp: Type)(implicit ctx: Context) = - extractorMemberType(tp, nme._1).exists - /** Does `tp` fit the "product match" conditions as an unapply result type * for a pattern with `numArgs` subpatterns? * This is the case of `tp` has members `_1` to `_N` where `N == numArgs`. @@ -72,7 +69,7 @@ object Applications { } def productArity(tp: Type)(implicit ctx: Context) = - if (canProductMatch(tp)) productSelectorTypes(tp).size else -1 + if (defn.isProductSubType(tp)) productSelectorTypes(tp).size else -1 def productSelectors(tp: Type)(implicit ctx: Context): List[Symbol] = { val sels = for (n <- Iterator.from(0)) yield tp.member(nme.selectorName(n)).symbol @@ -114,7 +111,7 @@ object Applications { getUnapplySelectors(getTp, args, pos) else if (unapplyResult isRef defn.BooleanClass) Nil - else if (canProductMatch(unapplyResult)) + else if (defn.isProductSubType(unapplyResult)) productSelectorTypes(unapplyResult) // this will cause a "wrong number of arguments in pattern" error later on, // which is better than the message in `fail`. diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 398a7a17e..5d8240362 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -377,9 +377,10 @@ object ProtoTypes { * Also, if `owningTree` is non-empty, add a type variable for each parameter. * @return The added type lambda, and the list of created type variables. */ - def constrained(tl: TypeLambda, owningTree: untpd.Tree)(implicit ctx: Context): (TypeLambda, List[TypeTree]) = { + def constrained(tl: TypeLambda, owningTree: untpd.Tree, alwaysAddTypeVars: Boolean = false)(implicit ctx: Context): (TypeLambda, List[TypeTree]) = { val state = ctx.typerState - assert(!(ctx.typerState.isCommittable && owningTree.isEmpty), + val addTypeVars = alwaysAddTypeVars || !owningTree.isEmpty + assert(!(ctx.typerState.isCommittable && !addTypeVars), s"inconsistent: no typevars were added to committable constraint ${state.constraint}") def newTypeVars(tl: TypeLambda): List[TypeTree] = @@ -392,7 +393,7 @@ object ProtoTypes { val added = if (state.constraint contains tl) tl.newLikeThis(tl.paramNames, tl.paramInfos, tl.resultType) else tl - val tvars = if (owningTree.isEmpty) Nil else newTypeVars(added) + val tvars = if (addTypeVars) newTypeVars(added) else Nil ctx.typeComparer.addToConstraint(added, tvars.tpes.asInstanceOf[List[TypeVar]]) (added, tvars) } @@ -400,13 +401,13 @@ object ProtoTypes { /** Same as `constrained(tl, EmptyTree)`, but returns just the created type lambda */ def constrained(tl: TypeLambda)(implicit ctx: Context): TypeLambda = constrained(tl, EmptyTree)._1 - /** Create a new TypeParamRef that represents a dependent method parameter singleton */ - def newDepTypeParamRef(tp: Type)(implicit ctx: Context): TypeParamRef = { + /** Create a new TypeVar that represents a dependent method parameter singleton */ + def newDepTypeVar(tp: Type)(implicit ctx: Context): TypeVar = { val poly = PolyType(DepParamName.fresh().toTypeName :: Nil)( pt => TypeBounds.upper(AndType(tp, defn.SingletonType)) :: Nil, pt => defn.AnyType) - ctx.typeComparer.addToConstraint(poly, Nil) - TypeParamRef(poly, 0) + constrained(poly, untpd.EmptyTree, alwaysAddTypeVars = true) + ._2.head.tpe.asInstanceOf[TypeVar] } /** The result type of `mt`, where all references to parameters of `mt` are @@ -415,7 +416,7 @@ object ProtoTypes { def resultTypeApprox(mt: MethodType)(implicit ctx: Context): Type = if (mt.isDependent) { def replacement(tp: Type) = - if (ctx.mode.is(Mode.TypevarsMissContext)) WildcardType else newDepTypeParamRef(tp) + if (ctx.mode.is(Mode.TypevarsMissContext)) WildcardType else newDepTypeVar(tp) mt.resultType.substParams(mt, mt.paramInfos.map(replacement)) } else mt.resultType diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 4bf938fd4..02538671e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -759,7 +759,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit /** Is `formal` a product type which is elementwise compatible with `params`? */ def ptIsCorrectProduct(formal: Type) = { isFullyDefined(formal, ForceDegree.noBottom) && - Applications.canProductMatch(formal) && + defn.isProductSubType(formal) && Applications.productSelectorTypes(formal).corresponds(params) { (argType, param) => param.tpt.isEmpty || argType <:< typedAheadType(param.tpt).tpe diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index fa0c89f28..cf9b200d4 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -156,6 +156,7 @@ class CompilationTests extends ParallelTesting { compileFile("../tests/neg/customArgs/nopredef.scala", defaultOptions.and("-Yno-predef")) + compileFile("../tests/neg/customArgs/noimports.scala", defaultOptions.and("-Yno-imports")) + compileFile("../tests/neg/customArgs/noimports2.scala", defaultOptions.and("-Yno-imports")) + + compileFile("../tests/neg/customArgs/overloadsOnAbstractTypes.scala", allowDoubleBindings) + compileFile("../tests/neg/tailcall/t1672b.scala", defaultOptions) + compileFile("../tests/neg/tailcall/t3275.scala", defaultOptions) + compileFile("../tests/neg/tailcall/t6574.scala", defaultOptions) + @@ -216,9 +217,9 @@ class CompilationTests extends ParallelTesting { val opt = Array( "-classpath", // compile with bootstrapped library on cp: - defaultOutputDir + "lib$1/src/:" + + defaultOutputDir + "lib/src/:" + // as well as bootstrapped compiler: - defaultOutputDir + "dotty1$1/dotty/:" + + defaultOutputDir + "dotty1/dotty/:" + Jars.dottyInterfaces ) diff --git a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala index 8645882ca..213181b56 100644 --- a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala @@ -91,23 +91,41 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M } object TestReporter { - lazy val logWriter = { + private[this] var outFile: JFile = _ + private[this] var logWriter: PrintWriter = _ + + private[this] def initLog() = if (logWriter eq null) { val df = new SimpleDateFormat("yyyy-MM-dd-HH:mm") val timestamp = df.format(new Date) new JFile("../testlogs").mkdirs() - new PrintWriter(new FileOutputStream(new JFile(s"../testlogs/tests-$timestamp.log"), true)) + outFile = new JFile(s"../testlogs/tests-$timestamp.log") + logWriter = new PrintWriter(new FileOutputStream(outFile, true)) } - def writeToLog(str: String) = { + def logPrintln(str: String) = { + initLog() logWriter.println(str) logWriter.flush() } + def logPrint(str: String): Unit = { + initLog() + logWriter.println(str) + } + + def logFlush(): Unit = + if (logWriter ne null) logWriter.flush() + + def logPath: String = { + initLog() + outFile.getCanonicalPath + } + def reporter(ps: PrintStream, logLevel: Int): TestReporter = - new TestReporter(new PrintWriter(ps, true), writeToLog, logLevel) + new TestReporter(new PrintWriter(ps, true), logPrintln, logLevel) def simplifiedReporter(writer: PrintWriter): TestReporter = { - val rep = new TestReporter(writer, writeToLog, WARNING) { + val rep = new TestReporter(writer, logPrintln, WARNING) { /** Prints the message with the given position indication in a simplified manner */ override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = { def report() = { diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index f43462011..b0312523d 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -192,8 +192,6 @@ trait ParallelTesting extends RunnerOrchestration { self => /** A runnable that logs its contents in a buffer */ trait LoggedRunnable extends Runnable { - import TestReporter.logWriter - /** Instances of `LoggedRunnable` implement this method instead of the * `run` method */ @@ -212,8 +210,7 @@ trait ParallelTesting extends RunnerOrchestration { self => final def run(): Unit = { checkTestSource() - logBuffer.iterator.foreach(logWriter.println) - logWriter.flush() + summaryReport.echoToLog(logBuffer.iterator) } } @@ -265,7 +262,7 @@ trait ParallelTesting extends RunnerOrchestration { self => private[this] val failedTestSources = mutable.ArrayBuffer.empty[String] protected final def failTestSource(testSource: TestSource, reason: Option[String] = None) = synchronized { val extra = reason.map(" with reason: " + _).getOrElse("") - failedTestSources.append(testSource.title + s" failed (in ${testSource.name})" + extra) + failedTestSources.append(testSource.title + s" failed" + extra) fail() } @@ -309,7 +306,7 @@ trait ParallelTesting extends RunnerOrchestration { self => protected def tryCompile(testSource: TestSource)(op: => Unit): Unit = try { val testing = s"Testing ${testSource.title}" - TestReporter.logWriter.println(testing) + summaryReport.echoToLog(testing) if (!isInteractive) realStdout.println(testing) op } catch { @@ -519,6 +516,7 @@ trait ParallelTesting extends RunnerOrchestration { self => } case Failure(output) => + echo(s"Test '${testSource.title}' failed with output:") echo(output) failTestSource(testSource) @@ -574,7 +572,7 @@ trait ParallelTesting extends RunnerOrchestration { self => if (!compilerCrashed && errorCount == 0) verifier() else { - echo(s"\n Compilation failed for: '$testSource'") + echo(s" Compilation failed for: '${testSource.title}' ") val buildInstr = testSource.buildInstructions(errorCount, warningCount) addFailureInstruction(buildInstr) failTestSource(testSource) @@ -1018,6 +1016,7 @@ trait ParallelTesting extends RunnerOrchestration { self => .getOrElse { throw new IllegalStateException("Unable to reflectively find calling method") } + .takeWhile(_ != '$') } /** Compiles a single file from the string path `f` using the supplied flags */ @@ -1072,7 +1071,7 @@ trait ParallelTesting extends RunnerOrchestration { self => val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/") targetDir.mkdirs() - val target = JointCompilationSource(callingMethod, randomized, flags, targetDir) + val target = JointCompilationSource(s"compiling '$f' in test '$callingMethod'", randomized, flags, targetDir) new CompilationTest(target) } @@ -1089,7 +1088,7 @@ trait ParallelTesting extends RunnerOrchestration { self => targetDir.mkdirs() assert(targetDir.exists, s"couldn't create target directory: $targetDir") - val target = JointCompilationSource(callingMethod, files.map(new JFile(_)).toArray, flags, targetDir) + val target = JointCompilationSource(s"$testName from $callingMethod", files.map(new JFile(_)).toArray, flags, targetDir) // Create a CompilationTest and let the user decide whether to execute a pos or a neg test new CompilationTest(target) diff --git a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala index ad068e9ef..610466224 100644 --- a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala +++ b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala @@ -3,6 +3,7 @@ package tools package vulpix import java.io.{ File => JFile, InputStreamReader, BufferedReader, PrintStream } +import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.TimeoutException import scala.concurrent.duration.Duration @@ -84,11 +85,11 @@ trait RunnerOrchestration { } /** Did add hook to kill the child VMs? */ - private[this] var didAddCleanupCallback = false + private[this] val didAddCleanupCallback = new AtomicBoolean(false) /** Blocks less than `maxDuration` while running `Test.main` from `dir` */ def runMain(classPath: String)(implicit summaryReport: SummaryReporting): Status = { - if (!didAddCleanupCallback) { + if (didAddCleanupCallback.compareAndSet(false, true)) { // If for some reason the test runner (i.e. sbt) doesn't kill the VM, we // need to clean up ourselves. summaryReport.addCleanup(killAll) diff --git a/compiler/test/dotty/tools/vulpix/SummaryReport.scala b/compiler/test/dotty/tools/vulpix/SummaryReport.scala index 8f3047f49..678d88809 100644 --- a/compiler/test/dotty/tools/vulpix/SummaryReport.scala +++ b/compiler/test/dotty/tools/vulpix/SummaryReport.scala @@ -34,6 +34,12 @@ trait SummaryReporting { /** Echo the summary report to the appropriate locations */ def echoSummary(): Unit + + /** Echoes *immediately* to file */ + def echoToLog(msg: String): Unit + + /** Echoes contents of `it` to file *immediately* then flushes */ + def echoToLog(it: Iterator[String]): Unit } /** A summary report that doesn't do anything */ @@ -45,6 +51,8 @@ final class NoSummaryReport extends SummaryReporting { def addStartingMessage(msg: String): Unit = () def addCleanup(f: () => Unit): Unit = () def echoSummary(): Unit = () + def echoToLog(msg: String): Unit = () + def echoToLog(it: Iterator[String]): Unit = () } /** A summary report that logs to both stdout and the `TestReporter.logWriter` @@ -95,17 +103,18 @@ final class SummaryReport extends SummaryReporting { startingMessages.foreach(rep.append) - failedTests.map(x => " " + x).foreach(rep.append) + failedTests.map(x => s" $x\n").foreach(rep.append) // If we're compiling locally, we don't need instructions on how to // reproduce failures if (isInteractive) { println(rep.toString) if (failed > 0) println { - """| - |---------------------------------------------------------- - |Note: reproduction instructed have been dumped to log file - |----------------------------------------------------------""".stripMargin + s"""| + |-------------------------------------------------------------------------------- + |Note - reproduction instructions have been dumped to log file: + | ${TestReporter.logPath} + |--------------------------------------------------------------------------------""".stripMargin } } @@ -116,11 +125,19 @@ final class SummaryReport extends SummaryReporting { // If we're on the CI, we want everything if (!isInteractive) println(rep.toString) - TestReporter.writeToLog(rep.toString) + TestReporter.logPrintln(rep.toString) // Perform cleanup callback: if (cleanUps.nonEmpty) cleanUps.foreach(_.apply()) } + + def echoToLog(msg: String): Unit = + TestReporter.logPrintln(msg) + + def echoToLog(it: Iterator[String]): Unit = { + it.foreach(TestReporter.logPrint) + TestReporter.logFlush() + } } object SummaryReport { |