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 Quill compatible with Scala 2.12.2 #770

Merged
merged 1 commit into from May 12, 2017

Conversation

mosyp
Copy link
Collaborator

@mosyp mosyp commented May 10, 2017

Fixes #231

Problem

Build fails against 2.12

Solution

Make Quill compatible with 2.12.2, more in todo list

  • adjust travis build
  • adjust new flags for scalac 2.12.2
  • fix failing tests (deprecations, not exhaustive match etc.)
  • workaround for bug intoduced with 2.12.2 with macros untypechek (manual creating of private[this] param with different name to accessor)
  • Unit test all changes
  • Update README.md if applicable
  • Add [WIP] to the pull request title if it's work in progress
  • Squash commits that aren't meaningful changes
  • Run sbt scalariformFormat test:scalariformFormat to make sure that the source files are formatted

@getquill/maintainers

@mosyp mosyp changed the title Scala2.12 workarounds Scala 2.12 compilation workarounds May 10, 2017
@mosyp mosyp changed the title Scala 2.12 compilation workarounds [WIP] Scala 2.12 compilation workarounds May 10, 2017
@mosyp
Copy link
Collaborator Author

mosyp commented May 10, 2017

I've been trying to add some dummy abstract methods to Quoted / make it abstract class and compile it without -Xsource:2.11 and both without success.

@mosyp mosyp force-pushed the scala2.12-workarounds branch 2 times, most recently from 07433dc to 2c1c33c Compare May 10, 2017 18:23
@fwbrasil
Copy link
Collaborator

@mentegy what's the error message?

Copy link
Collaborator Author

@mosyp mosyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@getquill/maintainers
After doing some research on this it seems like current workaround with "-Xsource:2.11" does not work for us. We need to figure out how to fix such errors introduced with 2.12

@@ -842,7 +844,7 @@ class QuotationSpec extends Spec {
}
"abritrary" in {
val q = quote(lift(String.valueOf(1)))
q.liftings.`java.this.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
//q.liftings.`java.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is required by 2.11 and fail without, opposite to 2.12 which fails with.
How should we handle that? Keep scala-2.1* different test directories or something like that. Any ideas?

build.sbt Outdated
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => Seq("-Xsource:2.11") ++ orig.map {
case "-Xlint" => "-Xlint:-unused,_"
case "-Ywarn-unused-import" => "-Ywarn-unused:imports,-patvars"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to keep only unused import flags as in 2.11

build.sbt Outdated
scalacOptions := {
val orig = scalacOptions.value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => Seq("-Xsource:2.11") ++ orig.map {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a problem with that. I have put this flag only to core module and it didn't work. Imho, forcing users to add this flag into their builds doesn't make sense.

build/build.sh Outdated
sbt coverageOff publish
else
sbt clean coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt clean coverage +test tut coverageReport coverageAggregate checkUnformattedFiles
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this didn't work also, I don't see any 2.12 appearances in travis logs

@@ -724,6 +725,7 @@ class QuotationSpec extends Spec {
quote(unquote(q)).ast match {
case Function(params, Tuple(values)) =>
values mustEqual params
case _ => require(false, "Should not happen")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match is not exhaustive

case class Test(a: String)
val t = Test("a")
case class TestEntity(a: String)
val t = TestEntity("a")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot detailed error however it is connected with suspicious shadowing of generated class name or something like that

@mosyp
Copy link
Collaborator Author

mosyp commented May 10, 2017

@fwbrasil type mismatch, 2 types - with and without stacktrace:

[error]  quill/quill-core/src/test/scala/io/getquill/dsl/EncodingDslSpec.scala:23: type mismatch;
[error]  found   : io.getquill.testContext.Quoted[io.getquill.testContext.Query[io.getquill.dsl.Address] => io.getquill.testContext.Query[Nothing]]{def ast: io.getquill.ast.Function}
[error]  required: io.getquill.testContext.Quoted[io.getquill.testContext.Query[io.getquill.dsl.Address] => io.getquill.testContext.Query[Nothing]]{def quoted: io.getquill.ast.Function; def ast: io.getquill.ast.Function; def id1252593445(): Unit; val liftings: Object}
[error]   def `inside run - query` = run {
  • 2nd type (has stack trace)
error] /home/misha/Documents/quill/quill-core/src/test/scala/io/getquill/context/ContextMacroSpec.scala:153: exception during macro expansion: 
[error] scala.reflect.macros.TypecheckException: type mismatch;
[error]  found   : io.getquill.testContext.Quoted[io.getquill.testContext.EntityQuery[io.getquill.testContext.TestEntity]]{def ast: io.getquill.ast.Entity}
[error]  required: io.getquill.testContext.Quoted[io.getquill.testContext.EntityQuery[io.getquill.testContext.TestEntity]]{def quoted: io.getquill.ast.Entity; def ast: io.getquill.ast.Entity; def id1703614372(): Unit; val liftings: Object}
...
[error]         at io.getquill.context.ContextMacro.extractAst(ContextMacro.scala:35)
[error]         at io.getquill.context.ContextMacro.extractAst$(ContextMacro.scala:34)
[error]         at io.getquill.context.QueryMacro.extractAst(QueryMacro.scala:8)

UPD. seems like stack trace is thrown only for dynamic queries

@mosyp mosyp changed the title [WIP] Scala 2.12 compilation workarounds [WIP] Make Quill compatible with Scala 2.12.2 May 10, 2017
@mosyp mosyp changed the title [WIP] Make Quill compatible with Scala 2.12.2 Make Quill compatible with Scala 2.12.2 May 11, 2017
@mosyp
Copy link
Collaborator Author

mosyp commented May 11, 2017

@getquill/maintainers Build successfully passes against 2.11/2.12 scala version. Please review.

@mosyp mosyp force-pushed the scala2.12-workarounds branch 4 times, most recently from bfc27c8 to 4452951 Compare May 12, 2017 16:58
build.sbt Outdated
if (scalaVersion.value.startsWith("2.12.")) "-Xfatal-warnings" else ""
)
)
lazy val `scala 2.12 hacks` = Seq(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the plan for removing these hacks? Are they due to scala bugs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one brings back -Xfatal-warnings for 2.12, but fails only for unused imports rather than all others (params, patvars and so on). So with this new hack we bring the behavior as with 2.11

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, it's more granular! I'm still curious how we're going to get rid of the hacks, though. Is it something we can fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will just rename it seems like it'll be persistent since scala/scala#5402

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -857,7 +859,7 @@ class QuotationSpec extends Spec {
}
"abritrary" in {
val q = quote(lift(String.valueOf(1)))
q.liftings.`java.this.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
//q.liftings.`java.this.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like my previous message has been lost with rebase. I'm not sure what should I do here. this must be present in 2.11, but in 2.12 should be removed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try to replace String.valueOf(1) with a tree that doesn't have this package naming issue. Maybe a scala object in the stdlib?

@@ -726,6 +726,7 @@ class QuotationSpec extends Spec {
quote(unquote(q)).ast match {
case Function(params, Tuple(values)) =>
values mustEqual params
case _ => require(false, "Should not happen")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use io.getquill.util.Messages.fail

q.liftings.`java.this.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
class A { def x = 1 }
val q = quote(lift(new A().x))
q.liftings.`new A().x`.value mustEqual new A().x
Copy link
Collaborator Author

@mosyp mosyp May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fwbrasil I hope this works for such test case, since using static calls as before is prohibit fr cross compilation

scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Seq("-Xlint", "-Ywarn-unused-import")
case Some((2, 12)) => Seq("-Xlint:-unused,_", "-Ywarn-unused:imports")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it should be more convenient

@fwbrasil
Copy link
Collaborator

This is awesome, thanks! :)

@fwbrasil fwbrasil merged commit af48efa into zio:master May 12, 2017
@mosyp mosyp deleted the scala2.12-workarounds branch May 13, 2017 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cross compile to Scala 2.12
3 participants