From 74b50a44e7a37006e5420af541a713507df6e9a6 Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Wed, 16 May 2018 15:57:42 +0200 Subject: [PATCH 1/5] Trying to reproduce "java.util.NoSuchElementException: value d" error --- benchmark/src/test/scala/specs/Issue8Spec.scala | 14 ++++++++++++++ build.sbt | 1 + 2 files changed, 15 insertions(+) create mode 100644 benchmark/src/test/scala/specs/Issue8Spec.scala diff --git a/benchmark/src/test/scala/specs/Issue8Spec.scala b/benchmark/src/test/scala/specs/Issue8Spec.scala new file mode 100644 index 0000000..1acc8d5 --- /dev/null +++ b/benchmark/src/test/scala/specs/Issue8Spec.scala @@ -0,0 +1,14 @@ +package specs + +import com.sizmek.fsi._ +import org.scalatest.{Matchers, WordSpec} +import scribe.Logging + +class Issue8Spec extends WordSpec with Matchers with Logging { + "java.util.NoSuchElementException: value d (Issue 8)" should { + "be reproduced" in { + val d = 12.3456 + logger.info(fs"Value: $d") + } + } +} diff --git a/build.sbt b/build.sbt index 7fb2761..e993c69 100644 --- a/build.sbt +++ b/build.sbt @@ -131,6 +131,7 @@ lazy val benchmark = project libraryDependencies ++= Seq( "com.dongxiguo" %% "fastring" % "1.0.0", "com.outr" %% "perfolation" % "1.0.0", + "com.outr" %% "scribe-slf4j" % "2.3.4" % Test, "org.scalatest" %% "scalatest" % "3.0.5-M1" % Test ) ) From 01a150238fb064fec7afb4c67569e2446147352a Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Wed, 16 May 2018 18:02:14 +0200 Subject: [PATCH 2/5] Reproduce "java.util.NoSuchElementException" + add workaround through indirection call --- .../src/main/scala/example/BugTest.scala | 30 +++++++++++++++++++ benchmark/src/test/scala/example/Test.scala | 19 ++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 benchmark/src/main/scala/example/BugTest.scala create mode 100644 benchmark/src/test/scala/example/Test.scala diff --git a/benchmark/src/main/scala/example/BugTest.scala b/benchmark/src/main/scala/example/BugTest.scala new file mode 100644 index 0000000..bc6dc74 --- /dev/null +++ b/benchmark/src/main/scala/example/BugTest.scala @@ -0,0 +1,30 @@ +package example + +import scala.annotation.compileTimeOnly +import scala.language.experimental.macros +import scala.reflect.macros.blackbox + +class BugTest { + def sample(message: () => String): LogRecord = macro BugTest.sample + + def example(message: => String): LogRecord = macro BugTest.example +} + +@compileTimeOnly("Enable macros to expand") +object BugTest { + def sample(c: blackbox.Context)(message: c.Tree): c.Tree = { + import c.universe._ + + q"example.LogRecord($message)" + } + + def example(c: blackbox.Context)(message: c.Tree): c.Tree = { + import c.universe._ + + q"example.LogRecord(() => $message)" + } +} + +case class LogRecord(messageFunction: () => String) { + lazy val message: String = messageFunction() +} \ No newline at end of file diff --git a/benchmark/src/test/scala/example/Test.scala b/benchmark/src/test/scala/example/Test.scala new file mode 100644 index 0000000..405a011 --- /dev/null +++ b/benchmark/src/test/scala/example/Test.scala @@ -0,0 +1,19 @@ +package example + +import com.sizmek.fsi._ + +object Test { + def main(args: Array[String]): Unit = { + val bt = new BugTest + + def sample(message: => String) = bt.sample(() => message) + + val d = 12.3456 +/* + val record = bt.example(fs"Value: $d") + println(s"Record: ${record.message}") +*/ + val record2 = sample(fs"Value: $d") + println(s"Record: ${record2.message}") + } +} \ No newline at end of file From aa83fd522eb9571f76a1d30b98567aea467b6c46 Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Wed, 16 May 2018 18:12:52 +0200 Subject: [PATCH 3/5] Reproduce "java.util.NoSuchElementException" with standard formatting string interpolator --- benchmark/src/test/scala/example/Test.scala | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/benchmark/src/test/scala/example/Test.scala b/benchmark/src/test/scala/example/Test.scala index 405a011..f194f43 100644 --- a/benchmark/src/test/scala/example/Test.scala +++ b/benchmark/src/test/scala/example/Test.scala @@ -1,7 +1,5 @@ package example -import com.sizmek.fsi._ - object Test { def main(args: Array[String]): Unit = { val bt = new BugTest @@ -9,11 +7,9 @@ object Test { def sample(message: => String) = bt.sample(() => message) val d = 12.3456 -/* - val record = bt.example(fs"Value: $d") + val record = bt.example(f"Value: $d") println(s"Record: ${record.message}") -*/ - val record2 = sample(fs"Value: $d") + val record2 = sample(f"Value: $d") println(s"Record: ${record2.message}") } } \ No newline at end of file From 83df25a7fbf43beea176854e4e9dc4a61eaacca3 Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Wed, 16 May 2018 18:29:08 +0200 Subject: [PATCH 4/5] W/A from @lihaoyi --- benchmark/src/main/scala/example/BugTest.scala | 13 +++---------- benchmark/src/test/scala/example/Test.scala | 5 ----- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/benchmark/src/main/scala/example/BugTest.scala b/benchmark/src/main/scala/example/BugTest.scala index bc6dc74..66a2f95 100644 --- a/benchmark/src/main/scala/example/BugTest.scala +++ b/benchmark/src/main/scala/example/BugTest.scala @@ -5,23 +5,16 @@ import scala.language.experimental.macros import scala.reflect.macros.blackbox class BugTest { - def sample(message: () => String): LogRecord = macro BugTest.sample - def example(message: => String): LogRecord = macro BugTest.example } @compileTimeOnly("Enable macros to expand") object BugTest { - def sample(c: blackbox.Context)(message: c.Tree): c.Tree = { - import c.universe._ - - q"example.LogRecord($message)" - } - def example(c: blackbox.Context)(message: c.Tree): c.Tree = { import c.universe._ - - q"example.LogRecord(() => $message)" + val f = c.typecheck(q"() => $message") + c.internal.changeOwner(message, c.internal.enclosingOwner, f.symbol) + q"example.LogRecord($f)" } } diff --git a/benchmark/src/test/scala/example/Test.scala b/benchmark/src/test/scala/example/Test.scala index f194f43..d508f15 100644 --- a/benchmark/src/test/scala/example/Test.scala +++ b/benchmark/src/test/scala/example/Test.scala @@ -3,13 +3,8 @@ package example object Test { def main(args: Array[String]): Unit = { val bt = new BugTest - - def sample(message: => String) = bt.sample(() => message) - val d = 12.3456 val record = bt.example(f"Value: $d") println(s"Record: ${record.message}") - val record2 = sample(f"Value: $d") - println(s"Record: ${record2.message}") } } \ No newline at end of file From 391a452fea8804de354d2e2b57a1aadddbe58db9 Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Fri, 6 Jul 2018 08:51:42 +0200 Subject: [PATCH 5/5] Switch from Scala 2.13.0-M3 to Scala 2.13.0-M4 and change names of modules and artifacts --- README.md | 5 ++-- build.sbt | 23 +++++++++---------- .../NestedConcatenationBenchmarkCore.scala | 0 .../SimpleConcatenationBenchmarkCore.scala | 0 ...NestedConcatenationBenchmarkCoreSpec.scala | 0 ...SimpleConcatenationBenchmarkCoreSpec.scala | 0 .../NestedConcatenationBenchmark.scala | 0 .../SimpleConcatenationBenchmark.scala | 0 .../src/main/scala/example/BugTest.scala | 0 .../NestedConcatenationBenchmarkSpec.scala | 0 .../SimpleConcatenationBenchmarkSpec.scala | 0 .../src/test/scala/example/Test.scala | 0 .../src/test/scala/specs/Issue8Spec.scala | 0 .../main/scala/com/sizmek/fsi/package.scala | 0 .../fsi/FastStringInterpolatorSpec.scala | 0 version.sbt | 2 +- 16 files changed, 15 insertions(+), 15 deletions(-) rename {benchmark-core => fsi-benchmark-core}/src/main/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCore.scala (100%) rename {benchmark-core => fsi-benchmark-core}/src/main/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCore.scala (100%) rename {benchmark-core => fsi-benchmark-core}/src/test/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCoreSpec.scala (100%) rename {benchmark-core => fsi-benchmark-core}/src/test/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCoreSpec.scala (100%) rename {benchmark => fsi-benchmark}/src/main/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmark.scala (100%) rename {benchmark => fsi-benchmark}/src/main/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmark.scala (100%) rename {benchmark => fsi-benchmark}/src/main/scala/example/BugTest.scala (100%) rename {benchmark => fsi-benchmark}/src/test/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmarkSpec.scala (100%) rename {benchmark => fsi-benchmark}/src/test/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmarkSpec.scala (100%) rename {benchmark => fsi-benchmark}/src/test/scala/example/Test.scala (100%) rename {benchmark => fsi-benchmark}/src/test/scala/specs/Issue8Spec.scala (100%) rename {macros => fsi-macros}/src/main/scala/com/sizmek/fsi/package.scala (100%) rename {macros => fsi-macros}/src/test/scala/com/sizmek/specs/fsi/FastStringInterpolatorSpec.scala (100%) diff --git a/README.md b/README.md index e978adf..ad051a5 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ resolvers += Resolver.jcenterRepo Add the library to a dependency list: ```sbt -libraryDependencies += "com.sizmek.fsi" %% "macros" % "0.2.0" +libraryDependencies += "com.sizmek.fsi" %% "fsi-macros" % "0.2.0" ``` Add import and replace prefix `s` by `fs` (or for a raw string interpolator `raw` by `fraw`): @@ -101,7 +101,8 @@ the following JVM system property: `com.sizmek.fsi.buffer.size`. To compile, run tests, check coverage, and check binary compatibility for different Scala versions use a command: ```sh -sbt clean +coverage +test +coverageReport +mimaReportBinaryIssues +sbt ++2.11.12 clean coverage test coverageReport mimaReportBinaryIssues +sbt ++2.12.6 clean coverage test coverageReport mimaReportBinaryIssues ``` ### Run benchmarks diff --git a/build.sbt b/build.sbt index e993c69..65fd077 100644 --- a/build.sbt +++ b/build.sbt @@ -55,7 +55,6 @@ lazy val commonSettings = Seq( "-encoding", "UTF-8", "-feature", "-unchecked", - "-Yno-adapted-args", "-Ywarn-dead-code", "-Xfuture", "-Xlint" @@ -92,38 +91,38 @@ lazy val publishSettings = Seq( ) lazy val `fast-string-interpolator` = project.in(file(".")) - .aggregate(macros, `benchmark-core`, benchmark) + .aggregate(`fsi-macros`, `fsi-benchmark-core`, `fsi-benchmark`) .settings(commonSettings: _*) .settings(noPublishSettings: _*) -lazy val macros = project +lazy val `fsi-macros` = project .settings(commonSettings: _*) .settings(mimaSettings: _*) .settings(publishSettings: _*) .settings( - crossScalaVersions := Seq("2.13.0-M3", "2.12.6", "2.11.12"), + crossScalaVersions := Seq("2.13.0-M4", "2.12.6", "2.11.12"), libraryDependencies ++= Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value, - "org.scalatest" %% "scalatest" % "3.0.5-M1" % Test + "org.scalatest" %% "scalatest" % "3.0.6-SNAP1" % Test ) ) -lazy val `benchmark-core` = project +lazy val `fsi-benchmark-core` = project .enablePlugins(JmhPlugin) - .dependsOn(macros) + .dependsOn(`fsi-macros`) .settings(commonSettings: _*) .settings(noPublishSettings: _*) .settings( - crossScalaVersions := Seq("2.13.0-M3", "2.12.6", "2.11.12"), + crossScalaVersions := Seq("2.13.0-M4", "2.12.6", "2.11.12"), libraryDependencies ++= Seq( "pl.project13.scala" % "sbt-jmh-extras" % "0.3.3", - "org.scalatest" %% "scalatest" % "3.0.5-M1" % Test + "org.scalatest" %% "scalatest" % "3.0.6-SNAP1" % Test ) ) -lazy val benchmark = project +lazy val `fsi-benchmark` = project .enablePlugins(JmhPlugin) - .dependsOn(`benchmark-core`) + .dependsOn(`fsi-benchmark-core`) .settings(commonSettings: _*) .settings(noPublishSettings: _*) .settings( @@ -132,6 +131,6 @@ lazy val benchmark = project "com.dongxiguo" %% "fastring" % "1.0.0", "com.outr" %% "perfolation" % "1.0.0", "com.outr" %% "scribe-slf4j" % "2.3.4" % Test, - "org.scalatest" %% "scalatest" % "3.0.5-M1" % Test + "org.scalatest" %% "scalatest" % "3.0.6-SNAP1" % Test ) ) diff --git a/benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCore.scala b/fsi-benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCore.scala similarity index 100% rename from benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCore.scala rename to fsi-benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCore.scala diff --git a/benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCore.scala b/fsi-benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCore.scala similarity index 100% rename from benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCore.scala rename to fsi-benchmark-core/src/main/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCore.scala diff --git a/benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCoreSpec.scala b/fsi-benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCoreSpec.scala similarity index 100% rename from benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCoreSpec.scala rename to fsi-benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/NestedConcatenationBenchmarkCoreSpec.scala diff --git a/benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCoreSpec.scala b/fsi-benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCoreSpec.scala similarity index 100% rename from benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCoreSpec.scala rename to fsi-benchmark-core/src/test/scala/com/sizmek/fsi/benchmark_core/SimpleConcatenationBenchmarkCoreSpec.scala diff --git a/benchmark/src/main/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmark.scala b/fsi-benchmark/src/main/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmark.scala similarity index 100% rename from benchmark/src/main/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmark.scala rename to fsi-benchmark/src/main/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmark.scala diff --git a/benchmark/src/main/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmark.scala b/fsi-benchmark/src/main/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmark.scala similarity index 100% rename from benchmark/src/main/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmark.scala rename to fsi-benchmark/src/main/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmark.scala diff --git a/benchmark/src/main/scala/example/BugTest.scala b/fsi-benchmark/src/main/scala/example/BugTest.scala similarity index 100% rename from benchmark/src/main/scala/example/BugTest.scala rename to fsi-benchmark/src/main/scala/example/BugTest.scala diff --git a/benchmark/src/test/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmarkSpec.scala b/fsi-benchmark/src/test/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmarkSpec.scala similarity index 100% rename from benchmark/src/test/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmarkSpec.scala rename to fsi-benchmark/src/test/scala/com/sizmek/fsi/benchmark/NestedConcatenationBenchmarkSpec.scala diff --git a/benchmark/src/test/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmarkSpec.scala b/fsi-benchmark/src/test/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmarkSpec.scala similarity index 100% rename from benchmark/src/test/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmarkSpec.scala rename to fsi-benchmark/src/test/scala/com/sizmek/fsi/benchmark/SimpleConcatenationBenchmarkSpec.scala diff --git a/benchmark/src/test/scala/example/Test.scala b/fsi-benchmark/src/test/scala/example/Test.scala similarity index 100% rename from benchmark/src/test/scala/example/Test.scala rename to fsi-benchmark/src/test/scala/example/Test.scala diff --git a/benchmark/src/test/scala/specs/Issue8Spec.scala b/fsi-benchmark/src/test/scala/specs/Issue8Spec.scala similarity index 100% rename from benchmark/src/test/scala/specs/Issue8Spec.scala rename to fsi-benchmark/src/test/scala/specs/Issue8Spec.scala diff --git a/macros/src/main/scala/com/sizmek/fsi/package.scala b/fsi-macros/src/main/scala/com/sizmek/fsi/package.scala similarity index 100% rename from macros/src/main/scala/com/sizmek/fsi/package.scala rename to fsi-macros/src/main/scala/com/sizmek/fsi/package.scala diff --git a/macros/src/test/scala/com/sizmek/specs/fsi/FastStringInterpolatorSpec.scala b/fsi-macros/src/test/scala/com/sizmek/specs/fsi/FastStringInterpolatorSpec.scala similarity index 100% rename from macros/src/test/scala/com/sizmek/specs/fsi/FastStringInterpolatorSpec.scala rename to fsi-macros/src/test/scala/com/sizmek/specs/fsi/FastStringInterpolatorSpec.scala diff --git a/version.sbt b/version.sbt index cfeb331..87c01ed 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.2.1-SNAPSHOT" +version in ThisBuild := "0.3.0-SNAPSHOT"