From 6b16ade94b6c354e8a776f1434dbfe76d131dbee Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Mon, 18 Apr 2016 12:15:54 -0400 Subject: [PATCH 1/3] Adding sleep in scripted test to make sure timestamp bumps Fixes #2546. Ref #958 scripted compiler-project/error-in-invalidated has been failing frequently on Travis CI. It seems like incremental compiler is not catching the change in source occasionally for `changes/A2.scala`. --- .../compiler-project/error-in-invalidated/build.sbt | 6 +++++- sbt/src/sbt-test/compiler-project/error-in-invalidated/test | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sbt/src/sbt-test/compiler-project/error-in-invalidated/build.sbt b/sbt/src/sbt-test/compiler-project/error-in-invalidated/build.sbt index f06e1de7d..8a40ded0c 100644 --- a/sbt/src/sbt-test/compiler-project/error-in-invalidated/build.sbt +++ b/sbt/src/sbt-test/compiler-project/error-in-invalidated/build.sbt @@ -1 +1,5 @@ -incOptions := sbt.inc.IncOptions.Default +lazy val root = (project in file(".")). + settings( + incOptions := sbt.inc.IncOptions.Default, + scalaVersion := "2.11.7" + ) diff --git a/sbt/src/sbt-test/compiler-project/error-in-invalidated/test b/sbt/src/sbt-test/compiler-project/error-in-invalidated/test index 5f4cf63f8..9f4537091 100644 --- a/sbt/src/sbt-test/compiler-project/error-in-invalidated/test +++ b/sbt/src/sbt-test/compiler-project/error-in-invalidated/test @@ -1,9 +1,13 @@ > compile + # comment out `initialized` method in A $ copy-file changes/A1.scala src/main/scala/A.scala +$ sleep 1000 # compilation of A.scala succeeds but B.scala gets invalidated (properly) and B.scala fails to compile -> compile + # we change A.scala to its original shape so compilation should succeed again $ copy-file changes/A2.scala src/main/scala/A.scala +$ sleep 1000 # this fails at the moment due to use of stale class file for A, see #958 for details > compile From 8c819fea6d6b51d4adf3f91aff450f83b65f270c Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Mon, 18 Apr 2016 02:31:24 -0400 Subject: [PATCH 2/3] Reproduce sbt/sbt#2560 Unlike other scripted macro tests, the call site of this macro is `Provider.tree(0)`, which does not introduce internal member reference. Instead the macro itself calls `Bar.bar(0)`. Due to #2560, the expanded tree is not traversed, and thus the reference to `Bar` is not caught during incremental compilation. --- .../macro-nonarg-dep/build.sbt | 22 +++++++++++++++++++ .../macro-nonarg-dep/changes/Bar.scala | 5 +++++ .../macro-nonarg-dep/macro-client/Bar.scala | 5 +++++ .../macro-client/Client.scala | 5 +++++ .../macro-provider/Provider.scala | 16 ++++++++++++++ .../source-dependencies/macro-nonarg-dep/test | 11 ++++++++++ 6 files changed, 64 insertions(+) create mode 100644 sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/build.sbt create mode 100644 sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/changes/Bar.scala create mode 100644 sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Bar.scala create mode 100644 sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Client.scala create mode 100644 sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-provider/Provider.scala create mode 100644 sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/test diff --git a/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/build.sbt b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/build.sbt new file mode 100644 index 000000000..0010b66e6 --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/build.sbt @@ -0,0 +1,22 @@ +val defaultSettings = Seq( + scalaVersion := "2.11.8", + libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _ )//, + //incOptions := incOptions.value.withNameHashing(true) +) + +lazy val root = (project in file(".")). + aggregate(macroProvider, macroClient). + settings( + defaultSettings + ) + +lazy val macroProvider = (project in file("macro-provider")). + settings( + defaultSettings + ) + +lazy val macroClient = (project in file("macro-client")). + dependsOn(macroProvider). + settings( + defaultSettings + ) diff --git a/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/changes/Bar.scala b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/changes/Bar.scala new file mode 100644 index 000000000..87c79e7fd --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/changes/Bar.scala @@ -0,0 +1,5 @@ +package example + +object Bar { + def bar(x: Int, y: Int): Int = x +} diff --git a/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Bar.scala b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Bar.scala new file mode 100644 index 000000000..10c5b02b0 --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Bar.scala @@ -0,0 +1,5 @@ +package example + +object Bar { + def bar(x: Int): Int = x +} diff --git a/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Client.scala b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Client.scala new file mode 100644 index 000000000..366bed2bd --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-client/Client.scala @@ -0,0 +1,5 @@ +package example + +object Client { + def foo: Unit = Provider.tree(0) +} diff --git a/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-provider/Provider.scala b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-provider/Provider.scala new file mode 100644 index 000000000..b80848166 --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/macro-provider/Provider.scala @@ -0,0 +1,16 @@ +package example + +import scala.language.experimental.macros +import scala.reflect.macros._ + +object Provider { + def tree(args: Any): Any = macro treeImpl + def treeImpl(c: Context)(args: c.Expr[Any]) = { + import c.universe._ + c.Expr[Any]( + Apply( + Select(Ident(TermName("Bar")), TermName("bar")), + List(Literal(Constant(0)))) + ) + } +} diff --git a/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/test b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/test new file mode 100644 index 000000000..10e1fbf1c --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-nonarg-dep/test @@ -0,0 +1,11 @@ +> compile + +## Replace client-side file Bar.scala to something that should not compile +$ copy-file changes/Bar.scala macro-client/Bar.scala + +## Expect failure here +-> macroClient/compile + +## It should still fail after clean +> macroClient/clean +-> macroClient/compile From c971d7f45c7475ad26fe5c18df27d9e2f9c4cac6 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Mon, 18 Apr 2016 02:34:53 -0400 Subject: [PATCH 3/3] Fix sbt/sbt#2560 traverse(tree: Tree) used to call super.traverse(tree) at the end. sbt/sbt@0f616294c4e713dc415f5dc3ae7aef257decb228 brought the traversing call to inside of the pattern matching. For the case of MacroExpansionOf(original), it amounts to not traveling the macro-expanded code. See sbt/src/sbt-test/source-dependencies/macro-nonarg-dep for the repro. --- compile/interface/src/main/scala/xsbt/Dependency.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compile/interface/src/main/scala/xsbt/Dependency.scala b/compile/interface/src/main/scala/xsbt/Dependency.scala index edcc3bd0c..b10975ec8 100644 --- a/compile/interface/src/main/scala/xsbt/Dependency.scala +++ b/compile/interface/src/main/scala/xsbt/Dependency.scala @@ -146,7 +146,9 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile { // In some cases (eg. macro annotations), `typeTree.tpe` may be null. See sbt/sbt#1593 and sbt/sbt#1655. case typeTree: TypeTree if typeTree.tpe != null => symbolsInType(typeTree.tpe) foreach addDependency - case MacroExpansionOf(original) if inspectedOriginalTrees.add(original) => traverse(original) + case m @ MacroExpansionOf(original) if inspectedOriginalTrees.add(original) => + traverse(original) + super.traverse(m) case other => super.traverse(other) }