From 17077dd4603c54a7735645c90f4f13d771d2772f Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Mon, 25 Sep 2017 22:14:43 +0200 Subject: [PATCH 01/13] move 'return outside method definition' to error class --- .../dotc/reporting/diagnostic/ErrorMessageID.java | 1 + .../tools/dotc/reporting/diagnostic/messages.scala | 8 ++++++++ compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../tools/dotc/reporting/ErrorMessagesTests.scala | 13 +++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index b4dbd031bea9..ee1dc683c088 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -97,6 +97,7 @@ public enum ErrorMessageID { DuplicatePrivateProtectedQualifierID, ExpectedStartOfTopLevelDefinitionID, MissingReturnTypeWithReturnStatementID, + ReturnOutsideMethodDefinitionID, ; public int errorNumber() { diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 301c9d1582d2..eecc75de16bd 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1737,4 +1737,12 @@ object messages { hl"you have to provide either ${"class"}, ${"trait"}, ${"object"}, or ${"enum"} definitions after qualifiers" } + case class ReturnOutsideMethodDefinition()(implicit ctx: Context) + extends Message(ReturnOutsideMethodDefinitionID) { + val kind = "Syntax" + val msg = s"return outside method definition" + val explanation = + hl"${"return"} is a keyword and may only be used within methods" + } + } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index d94a5851574e..a92f87a0e606 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -980,7 +980,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def enclMethInfo(cx: Context): (Tree, Type) = { val owner = cx.owner if (cx == NoContext || owner.isType) { - ctx.error("return outside method definition", tree.pos) + ctx.error(ReturnOutsideMethodDefinition(), tree.pos) (EmptyTree, WildcardType) } else if (owner != cx.outer.owner && owner.isRealMethod) { diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index aa473912ed7d..724bf2122957 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -970,4 +970,17 @@ class ErrorMessagesTests extends ErrorMessagesTest { val MissingReturnTypeWithReturnStatement(method) :: Nil = messages assertEquals(method.name.show, "bad") } + + @Test def returnOutsideMethodDefinition = + checkMessagesAfter("frontend") { + """object A { + | return 5 + |} + """.stripMargin + }.expect { (ictx, messages) => + implicit val ctx: Context = ictx + assertMessageCount(1, messages) + val ReturnOutsideMethodDefinition() :: Nil = messages + } + } From 6d64e1e54ad36c20cf188e51042fd82394100e0d Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Tue, 26 Sep 2017 11:15:48 +0200 Subject: [PATCH 02/13] move 'return outside method declaration': more details in explanation --- .../tools/dotc/reporting/diagnostic/messages.scala | 14 ++++++++++---- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../tools/dotc/reporting/ErrorMessagesTests.scala | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 8e3d84e3b11d..44c71228f44a 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -4,7 +4,7 @@ package reporting package diagnostic import dotc.core._ -import Contexts.Context +import Contexts.{Context, NoContext} import Decorators._ import Symbols._ import Names._ @@ -23,6 +23,7 @@ import dotty.tools.dotc.ast.Trees import dotty.tools.dotc.ast.untpd.Modifiers import dotty.tools.dotc.core.Flags.{FlagSet, Mutable} import dotty.tools.dotc.core.SymDenotations.SymDenotation + import scala.util.control.NonFatal object messages { @@ -1748,11 +1749,16 @@ object messages { |""" } - case class ReturnOutsideMethodDefinition()(implicit ctx: Context) + case class ReturnOutsideMethodDefinition(checkedContext: Context)(implicit ctx: Context) extends Message(ReturnOutsideMethodDefinitionID) { val kind = "Syntax" - val msg = s"return outside method definition" + val msg = hl"${"return"} outside method definition" + private val contextInfo = + if (checkedContext == NoContext) "outside any declaration" + else s"in ${checkedContext.owner.show}" val explanation = - hl"${"return"} is a keyword and may only be used within methods" + hl"""You used ${"return"} $contextInfo. + |${"return"} is a keyword and may only be used within method declarations. + |""" } } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index ab215b3ab7e3..c6b372d29a9e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -980,7 +980,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def enclMethInfo(cx: Context): (Tree, Type) = { val owner = cx.owner if (cx == NoContext || owner.isType) { - ctx.error(ReturnOutsideMethodDefinition(), tree.pos) + ctx.error(ReturnOutsideMethodDefinition(cx), tree.pos) (EmptyTree, WildcardType) } else if (owner != cx.outer.owner && owner.isRealMethod) { diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index b5e842041286..c401de5c8264 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -995,7 +995,8 @@ class ErrorMessagesTests extends ErrorMessagesTest { }.expect { (ictx, messages) => implicit val ctx: Context = ictx assertMessageCount(1, messages) - val ReturnOutsideMethodDefinition() :: Nil = messages + val ReturnOutsideMethodDefinition(checkedContext) :: Nil = messages + assertEquals("object A", checkedContext.owner.show) } } From aace0019ba8a29c64f857d5a460eb7890820a484 Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Tue, 26 Sep 2017 21:04:46 +0200 Subject: [PATCH 03/13] move 'return outside method declaration': def it is --- .../src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 44c71228f44a..64c528be1744 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1753,7 +1753,7 @@ object messages { extends Message(ReturnOutsideMethodDefinitionID) { val kind = "Syntax" val msg = hl"${"return"} outside method definition" - private val contextInfo = + private def contextInfo = if (checkedContext == NoContext) "outside any declaration" else s"in ${checkedContext.owner.show}" val explanation = From 496c56a12ccc03fe2d7edce3b272b4c96a9bbfe7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 25 Sep 2017 13:53:08 +0200 Subject: [PATCH 04/13] Revert "Revert "Add regression tests on optimise"" This reverts commit 1943f4e4985ebd1d9bbd5f06418fef0f2b79dd21. --- compiler/test/dotty/tools/dotc/CompilationTests.scala | 4 ++++ tests/neg/{ => no-optimise}/patmat.scala | 0 tests/neg/{ => no-optimise}/tryPatternMatchError.scala | 0 3 files changed, 4 insertions(+) rename tests/neg/{ => no-optimise}/patmat.scala (100%) rename tests/neg/{ => no-optimise}/tryPatternMatchError.scala (100%) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 2863bff4e48d..dd7af3d14186 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -91,6 +91,7 @@ class CompilationTests extends ParallelTesting { compileFilesInDir("../tests/new", defaultOptions) + compileFilesInDir("../tests/pos-scala2", scala2Mode) + compileFilesInDir("../tests/pos", defaultOptions) + + compileFilesInDir("../tests/pos", defaultOptimised) + compileFilesInDir("../tests/pos-deep-subtype", allowDeepSubtypes) + compileFile( // succeeds despite -Xfatal-warnings because of -nowarn @@ -159,6 +160,8 @@ class CompilationTests extends ParallelTesting { @Test def compileNeg: Unit = { compileShallowFilesInDir("../tests/neg", defaultOptions) + + compileShallowFilesInDir("../tests/neg/no-optimise", defaultOptions) + + compileShallowFilesInDir("../tests/neg", defaultOptimised) + compileFile("../tests/neg/customArgs/typers.scala", allowDoubleBindings) + compileFile("../tests/neg/customArgs/overrideClass.scala", scala2Mode) + compileFile("../tests/neg/customArgs/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")) + @@ -186,6 +189,7 @@ class CompilationTests extends ParallelTesting { @Test def runAll: Unit = { compileFilesInDir("../tests/run", defaultOptions) + + compileFilesInDir("../tests/run", defaultOptimised) + compileFile("../tests/run/i3018.scala", defaultOptimised) + compileFile("../tests/run/blame_eye_triple_eee-double.scala", defaultOptimised) + compileFile("../tests/run/blame_eye_triple_eee-float.scala", defaultOptimised) + diff --git a/tests/neg/patmat.scala b/tests/neg/no-optimise/patmat.scala similarity index 100% rename from tests/neg/patmat.scala rename to tests/neg/no-optimise/patmat.scala diff --git a/tests/neg/tryPatternMatchError.scala b/tests/neg/no-optimise/tryPatternMatchError.scala similarity index 100% rename from tests/neg/tryPatternMatchError.scala rename to tests/neg/no-optimise/tryPatternMatchError.scala From f1a54cb74eac259c305d08c7513d99af9a0c96bb Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 25 Sep 2017 15:16:14 +0200 Subject: [PATCH 05/13] Re-encode vulpix implicit output directory --- compiler/test/dotc/comptest.scala | 5 ++--- .../test/dotty/tools/dotc/CompilationTests.scala | 1 + .../test/dotty/tools/dotc/LinkOptimiseTests.scala | 1 + .../test/dotty/tools/vulpix/ParallelTesting.scala | 13 ++++++++----- .../test/dotty/tools/vulpix/TestConfiguration.scala | 1 - 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/compiler/test/dotc/comptest.scala b/compiler/test/dotc/comptest.scala index 318f9cd80612..de9fb0b1e515 100644 --- a/compiler/test/dotc/comptest.scala +++ b/compiler/test/dotc/comptest.scala @@ -12,8 +12,6 @@ object comptest extends ParallelTesting { def isInteractive = true def testFilter = None - implicit val defaultOutputDir: String = "." - val posDir = "./tests/pos/" val negDir = "./tests/neg/" val dotcDir = "./src/dotty/" @@ -26,6 +24,7 @@ object comptest extends ParallelTesting { dotcDir + "tools/dotc/core/Types.scala", dotcDir + "tools/dotc/ast/Trees.scala" ), - TestFlags("", Array("-Ylog:frontend", "-Xprompt")) + TestFlags("", Array("-Ylog:frontend", "-Xprompt")), + outDirectory = "." ) } diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index dd7af3d14186..a55a5e88a9c2 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -15,6 +15,7 @@ import dotty.tools.io.JFile class CompilationTests extends ParallelTesting { + import ParallelTesting._ import TestConfiguration._ import CompilationTests._ diff --git a/compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala b/compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala index 70fa01c5f053..7aa2f0bcb651 100644 --- a/compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala +++ b/compiler/test/dotty/tools/dotc/LinkOptimiseTests.scala @@ -13,6 +13,7 @@ import scala.concurrent.duration._ import scala.collection.JavaConverters._ class LinkOptimiseTests extends ParallelTesting { + import ParallelTesting._ import TestConfiguration._ import LinkOptimiseTests._ diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index b5534337e82b..2fad926c0a79 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -1057,7 +1057,7 @@ trait ParallelTesting extends RunnerOrchestration { self => } /** Compiles a single file from the string path `f` using the supplied flags */ - def compileFile(f: String, flags: TestFlags)(implicit outDirectory: String): CompilationTest = { + def compileFile(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = { val callingMethod = getCallingMethod() val sourceFile = new JFile(f) val parent = sourceFile.getParentFile @@ -1087,7 +1087,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * By default, files are compiled in alphabetical order. An optional seed * can be used for randomization. */ - def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None)(implicit outDirectory: String): CompilationTest = { + def compileDir(f: String, flags: TestFlags, randomOrder: Option[Int] = None, outDirectory: String = defaultOutputDir): CompilationTest = { val callingMethod = getCallingMethod() val outDir = outDirectory + callingMethod + "/" val sourceDir = new JFile(f) @@ -1116,7 +1116,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * `testName` since files can be in separate directories and or be otherwise * dissociated */ - def compileList(testName: String, files: List[String], flags: TestFlags, callingMethod: String = getCallingMethod())(implicit outDirectory: String): CompilationTest = { + def compileList(testName: String, files: List[String], flags: TestFlags, callingMethod: String = getCallingMethod(), outDirectory: String = defaultOutputDir): CompilationTest = { val outDir = outDirectory + callingMethod + "/" + testName + "/" // Directories in which to compile all containing files with `flags`: @@ -1147,7 +1147,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * - Directories can have an associated check-file, where the check file has * the same name as the directory (with the file extension `.check`) */ - def compileFilesInDir(f: String, flags: TestFlags)(implicit outDirectory: String): CompilationTest = { + def compileFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = { val callingMethod = getCallingMethod() val outDir = outDirectory + callingMethod + "/" val sourceDir = new JFile(f) @@ -1167,7 +1167,7 @@ trait ParallelTesting extends RunnerOrchestration { self => * sub-directories and as such, does **not** perform separate compilation * tests. */ - def compileShallowFilesInDir(f: String, flags: TestFlags)(implicit outDirectory: String): CompilationTest = { + def compileShallowFilesInDir(f: String, flags: TestFlags, outDirectory: String = defaultOutputDir): CompilationTest = { val callingMethod = getCallingMethod() val outDir = outDirectory + callingMethod + "/" val sourceDir = new JFile(f) @@ -1185,6 +1185,9 @@ trait ParallelTesting extends RunnerOrchestration { self => } object ParallelTesting { + + def defaultOutputDir: String = "../out/" + def isSourceFile(f: JFile): Boolean = { val name = f.getName name.endsWith(".scala") || name.endsWith(".java") diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index 1c94ba230a10..9ebd7a6cae91 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -3,7 +3,6 @@ package tools package vulpix object TestConfiguration { - implicit val defaultOutputDir: String = "../out/" val noCheckOptions = Array( "-pagewidth", "120", From 2e3056c56381fee3ec9c54146b64eb16773ba061 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 25 Sep 2017 15:47:48 +0200 Subject: [PATCH 06/13] Fix output paths for optimised tests --- .../dotty/tools/dotc/CompilationTests.scala | 18 ++++++++---------- tests/{run => run-no-optimise}/2772.scala | 0 2 files changed, 8 insertions(+), 10 deletions(-) rename tests/{run => run-no-optimise}/2772.scala (100%) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index a55a5e88a9c2..3eba2b1e7e8a 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -69,7 +69,6 @@ class CompilationTests extends ParallelTesting { compileFilesInDir("../tests/pos-special/strawman-collections", defaultOptions) + compileFile("../scala2-library/src/library/scala/collection/immutable/IndexedSeq.scala", defaultOptions) + compileFile("../scala2-library/src/library/scala/collection/parallel/mutable/ParSetLike.scala", defaultOptions) + - compileFile("../tests/pos/t2171.scala", defaultOptimised) + compileList( "parSetSubset", List( @@ -92,7 +91,6 @@ class CompilationTests extends ParallelTesting { compileFilesInDir("../tests/new", defaultOptions) + compileFilesInDir("../tests/pos-scala2", scala2Mode) + compileFilesInDir("../tests/pos", defaultOptions) + - compileFilesInDir("../tests/pos", defaultOptimised) + compileFilesInDir("../tests/pos-deep-subtype", allowDeepSubtypes) + compileFile( // succeeds despite -Xfatal-warnings because of -nowarn @@ -162,7 +160,6 @@ class CompilationTests extends ParallelTesting { @Test def compileNeg: Unit = { compileShallowFilesInDir("../tests/neg", defaultOptions) + compileShallowFilesInDir("../tests/neg/no-optimise", defaultOptions) + - compileShallowFilesInDir("../tests/neg", defaultOptimised) + compileFile("../tests/neg/customArgs/typers.scala", allowDoubleBindings) + compileFile("../tests/neg/customArgs/overrideClass.scala", scala2Mode) + compileFile("../tests/neg/customArgs/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")) + @@ -190,13 +187,7 @@ class CompilationTests extends ParallelTesting { @Test def runAll: Unit = { compileFilesInDir("../tests/run", defaultOptions) + - compileFilesInDir("../tests/run", defaultOptimised) + - compileFile("../tests/run/i3018.scala", defaultOptimised) + - compileFile("../tests/run/blame_eye_triple_eee-double.scala", defaultOptimised) + - compileFile("../tests/run/blame_eye_triple_eee-float.scala", defaultOptimised) + - compileFile("../tests/run/run-bug4840.scala", defaultOptimised) + - compileFile("../tests/run/optimizer-array-load.scala", defaultOptimised) + - compileFile("../tests/run/constant-optimization.scala", defaultOptimised) + compileFilesInDir("../tests/run-no-optimise", defaultOptions) }.checkRuns() // Pickling Tests ------------------------------------------------------------ @@ -303,6 +294,13 @@ class CompilationTests extends ParallelTesting { tests.foreach(_.delete()) } + @Test def testOptimised: Unit = { + val outputDir = defaultOutputDir + "optimised/" + compileFilesInDir("../tests/pos", defaultOptimised, outputDir).checkCompile() + compileFilesInDir("../tests/run", defaultOptimised, outputDir).checkRuns() + compileShallowFilesInDir("../tests/neg", defaultOptimised, outputDir).checkExpectedErrors() + } + private val (compilerSources, backendSources, backendJvmSources) = { val compilerDir = Paths.get("../compiler/src") val compilerSources0 = sources(Files.walk(compilerDir)) diff --git a/tests/run/2772.scala b/tests/run-no-optimise/2772.scala similarity index 100% rename from tests/run/2772.scala rename to tests/run-no-optimise/2772.scala From 7c92f3a394874ecc82fe1620c6a33e18fe80364c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 22 Sep 2017 17:01:09 +0200 Subject: [PATCH 07/13] Re-enable DropNoEffects after erasure --- compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala index c8fc99ff6322..b1ce5ef36c6f 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala @@ -62,6 +62,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer { new Devalify :: new Jumpjump :: new DropGoodCasts :: + new DropNoEffects(this) :: new ConstantFold(this) :: Nil From bb7d88903df49d1d2f2d2173b25a5e9436d8f6d9 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Tue, 26 Sep 2017 15:06:41 +0200 Subject: [PATCH 08/13] Fix #3172: sbt-dotty breaks aggregrated tasks Workaround https://github.com/sbt/sbt/issues/3580 by not using Def.derive --- project/Build.scala | 2 +- .../tools/sbtplugin/DottyIDEPlugin.scala | 59 ++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index e8b8a7e1e3b6..c01c80a82b5b 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -871,7 +871,7 @@ object Build { sbtPlugin := true, - version := "0.1.5", + version := "0.1.6-SNAPSHOT", ScriptedPlugin.scriptedSettings, ScriptedPlugin.sbtTestDirectory := baseDirectory.value / "sbt-test", ScriptedPlugin.scriptedBufferLog := false, diff --git a/sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala b/sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala index 8b7eedb0b9a6..c9f3c4e72062 100644 --- a/sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala +++ b/sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala @@ -1,6 +1,7 @@ package dotty.tools.sbtplugin import sbt._ +import sbt.Def.Initialize import sbt.Keys._ import java.io._ import java.lang.ProcessBuilder @@ -196,34 +197,38 @@ object DottyIDEPlugin extends AutoPlugin { origState } + private def projectConfigTask(config: Configuration): Initialize[Task[Option[ProjectConfig]]] = Def.task { + if ((sources in config).value.isEmpty) None + else { + // Not needed to generate the config, but this guarantees that the + // generated config is usable by an IDE without any extra compilation + // step. + val _ = (compile in config).value + + val id = s"${thisProject.value.id}/${config.name}" + val compilerVersion = (scalaVersion in config).value + val compilerArguments = (scalacOptions in config).value + val sourceDirectories = (unmanagedSourceDirectories in config).value ++ (managedSourceDirectories in config).value + val depClasspath = Attributed.data((dependencyClasspath in config).value) + val classDir = (classDirectory in config).value + + Some(new ProjectConfig( + id, + compilerVersion, + compilerArguments.toArray, + sourceDirectories.toArray, + depClasspath.toArray, + classDir + )) + } + } + override def projectSettings: Seq[Setting[_]] = Seq( - // Use Def.derive so `projectConfig` is only defined in the configurations where the - // tasks/settings it depends on are defined. - Def.derive(projectConfig := { - if (sources.value.isEmpty) None - else { - // Not needed to generate the config, but this guarantees that the - // generated config is usable by an IDE without any extra compilation - // step. - val _ = compile.value - - val id = s"${thisProject.value.id}/${configuration.value.name}" - val compilerVersion = scalaVersion.value - val compilerArguments = scalacOptions.value - val sourceDirectories = unmanagedSourceDirectories.value ++ managedSourceDirectories.value - val depClasspath = Attributed.data(dependencyClasspath.value) - val classDir = classDirectory.value - - Some(new ProjectConfig( - id, - compilerVersion, - compilerArguments.toArray, - sourceDirectories.toArray, - depClasspath.toArray, - classDir - )) - } - }) + // TODO: It would be better to use Def.derive to define projectConfig in + // every configuration where the keys it depends on exist, however this + // currently breaks aggregated tasks: https://github.com/sbt/sbt/issues/3580 + projectConfig in Compile := projectConfigTask(Compile).value, + projectConfig in Test := projectConfigTask(Test).value ) override def buildSettings: Seq[Setting[_]] = Seq( From 19d2c19ed80dfc9ebc1b265a09283b11a593fa90 Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Tue, 26 Sep 2017 15:35:17 +0200 Subject: [PATCH 09/13] Add chat widget in the dotty website Inspired from the cats documentation The button color is changed to gray to make it less intrusive --- doc-tool/resources/_layouts/main.html | 7 +++++++ doc-tool/resources/css/dottydoc.css | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/doc-tool/resources/_layouts/main.html b/doc-tool/resources/_layouts/main.html index 364da6fb7ade..137d517f1bbf 100644 --- a/doc-tool/resources/_layouts/main.html +++ b/doc-tool/resources/_layouts/main.html @@ -61,5 +61,12 @@ } }); + + + diff --git a/doc-tool/resources/css/dottydoc.css b/doc-tool/resources/css/dottydoc.css index 46055f35bc34..350559355141 100644 --- a/doc-tool/resources/css/dottydoc.css +++ b/doc-tool/resources/css/dottydoc.css @@ -270,3 +270,7 @@ aside.success { border-left: 3px solid #36bf1d; background-color: #ebfddd; } + +.gitter-open-chat-button { + background-color: gray; +} From 27ce14ab3a5d9491e40f6ea0258154eb587970f2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 26 Sep 2017 19:35:04 +0200 Subject: [PATCH 10/13] Optimize away erased phantom statements --- .../tools/dotc/core/PhantomErasure.scala | 5 ++++- .../dotc/transform/localopt/Simplify.scala | 20 +++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/PhantomErasure.scala b/compiler/src/dotty/tools/dotc/core/PhantomErasure.scala index 9821c69713c0..0e1e159846f7 100644 --- a/compiler/src/dotty/tools/dotc/core/PhantomErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/PhantomErasure.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc.core import dotty.tools.dotc.ast.tpd._ import dotty.tools.dotc.core.Contexts.Context -import dotty.tools.dotc.core.Symbols.defn +import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.core.Types.Type /** Phantom erasure erases: @@ -27,4 +27,7 @@ object PhantomErasure { /** Returns the default erased tree for a phantom parameter ref */ def erasedParameterRef(implicit ctx: Context): Tree = ref(defn.ErasedPhantom_UNIT) + /** Is it a pure term inserted by the phantom erasure? */ + def isErasedPhantom(sym: Symbol)(implicit ctx: Context): Boolean = sym eq defn.ErasedPhantom_UNIT + } diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala index b1ce5ef36c6f..c78536c3b4fc 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala @@ -11,6 +11,7 @@ import core.NameOps._ import transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo} import config.Printers.simplify import ast.tpd +import dotty.tools.dotc.core.PhantomErasure import scala.annotation.tailrec @@ -175,13 +176,16 @@ object Simplify { } def isImmutableAccessor(t: Tree)(implicit ctx: Context): Boolean = { - val isImmutableGetter = t.symbol.isGetter && !t.symbol.is(Mutable | Lazy) - val isCaseAccessor = t.symbol.is(CaseAccessor) && !t.symbol.is(Mutable | Lazy) - val isProductAccessor = t.symbol.exists && - t.symbol.owner.derivesFrom(defn.ProductClass) && - t.symbol.owner.is(CaseClass) && - t.symbol.name.isSelectorName && - !t.symbol.info.decls.exists(_.is(Mutable | Lazy)) // Conservatively covers case class A(var x: Int) - isImmutableGetter || isCaseAccessor || isProductAccessor + val sym = t.symbol + val isImmutableGetter = sym.isGetter && !sym.is(Mutable | Lazy) + val isCaseAccessor = sym.is(CaseAccessor) && !sym.is(Mutable | Lazy) + val isProductAccessor = sym.exists && + sym.owner.derivesFrom(defn.ProductClass) && + sym.owner.is(CaseClass) && + sym.name.isSelectorName && + !sym.info.decls.exists(_.is(Mutable | Lazy)) // Conservatively covers case class A(var x: Int) + val isErasedPhantom = PhantomErasure.isErasedPhantom(sym) + + isImmutableGetter || isCaseAccessor || isProductAccessor || isErasedPhantom } } From 2c14200f2bf48ad88d15cd772f8aa4e1929c4b93 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Wed, 27 Sep 2017 14:03:26 +0200 Subject: [PATCH 11/13] Remove unnecessary check in `typedReturn` `return` outside a type definition would result in a parsing error. Therefore the context cannot be `NoContext`. --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index c6b372d29a9e..31c1924e2e1d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -979,7 +979,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def enclMethInfo(cx: Context): (Tree, Type) = { val owner = cx.owner - if (cx == NoContext || owner.isType) { + if (owner.isType) { ctx.error(ReturnOutsideMethodDefinition(cx), tree.pos) (EmptyTree, WildcardType) } From 4a67f188f2cd0392324401f383f65177332d4588 Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Mon, 25 Sep 2017 22:14:43 +0200 Subject: [PATCH 12/13] move 'return outside method definition' to error class --- .../src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 64c528be1744..9356b94233fb 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -23,7 +23,6 @@ import dotty.tools.dotc.ast.Trees import dotty.tools.dotc.ast.untpd.Modifiers import dotty.tools.dotc.core.Flags.{FlagSet, Mutable} import dotty.tools.dotc.core.SymDenotations.SymDenotation - import scala.util.control.NonFatal object messages { From 61170fda9520a8d75edfcb33599c2cf5fc72702c Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Wed, 27 Sep 2017 16:43:22 +0200 Subject: [PATCH 13/13] move 'return outside method declaration': removed NoContext case --- .../dotty/tools/dotc/reporting/diagnostic/messages.scala | 7 ++----- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../dotty/tools/dotc/reporting/ErrorMessagesTests.scala | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 9356b94233fb..c6baa509f179 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1748,15 +1748,12 @@ object messages { |""" } - case class ReturnOutsideMethodDefinition(checkedContext: Context)(implicit ctx: Context) + case class ReturnOutsideMethodDefinition(owner: Symbol)(implicit ctx: Context) extends Message(ReturnOutsideMethodDefinitionID) { val kind = "Syntax" val msg = hl"${"return"} outside method definition" - private def contextInfo = - if (checkedContext == NoContext) "outside any declaration" - else s"in ${checkedContext.owner.show}" val explanation = - hl"""You used ${"return"} $contextInfo. + hl"""You used ${"return"} in ${owner}. |${"return"} is a keyword and may only be used within method declarations. |""" } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 31c1924e2e1d..ab63b6f51580 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -980,7 +980,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def enclMethInfo(cx: Context): (Tree, Type) = { val owner = cx.owner if (owner.isType) { - ctx.error(ReturnOutsideMethodDefinition(cx), tree.pos) + ctx.error(ReturnOutsideMethodDefinition(owner), tree.pos) (EmptyTree, WildcardType) } else if (owner != cx.outer.owner && owner.isRealMethod) { diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index c401de5c8264..c00d971a83e6 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -995,8 +995,8 @@ class ErrorMessagesTests extends ErrorMessagesTest { }.expect { (ictx, messages) => implicit val ctx: Context = ictx assertMessageCount(1, messages) - val ReturnOutsideMethodDefinition(checkedContext) :: Nil = messages - assertEquals("object A", checkedContext.owner.show) + val ReturnOutsideMethodDefinition(owner) :: Nil = messages + assertEquals("object A", owner.show) } }