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

Incremental Compilation inconsistent #13028

Closed
FabioPinheiro opened this issue Jul 7, 2021 · 2 comments · Fixed by #18310
Closed

Incremental Compilation inconsistent #13028

FabioPinheiro opened this issue Jul 7, 2021 · 2 comments · Fixed by #18310

Comments

@FabioPinheiro
Copy link
Contributor

Compiler version

ScalaVersion: 3.0.0 but also on 3.0.2-RC1-bin-20210706-6011847-NIGHTLY
dependency: io.circe:circe-generic_3:0.14.1

Minimized code

File1.scala

object DDD
case class AAA(a: DDD.type)
//case class AAA(a: Int)

File2.scala

import io.circe.generic.auto._
val test = summon[io.circe.Decoder[AAA]]

First compile with case class AAA(a: Int) on File1.
Then compile File1.scala as above.
The recompilation should fail and it did not fail!

I also create a branch with the minimal amount of code: https://github.com/FabioPinheiro/fmgp-threejs/tree/dotty_IncrementalCompilation_inconsistent/src/main/scala

Output

sbt:fmgp-geometry> clean
[success] Total time: 0 s, completed Jul 7, 2021 3:33:49 PM
sbt:fmgp-geometry> compile
[info] compiling 2 Scala sources to /home/fabio/workspace/fmgp-threejs/target/scala-3.0.0/classes ...

Change code back to case class AAA(a: DDD.type)

[success] Total time: 1 s, completed Jul 7, 2021 3:33:52 PM
sbt:fmgp-geometry> compile
[info] compiling 1 Scala source to /home/fabio/workspace/fmgp-threejs/target/scala-3.0.0/classes ...
[success] Total time: 0 s, completed Jul 7, 2021 3:34:02 PM
sbt:fmgp-geometry> clean
[success] Total time: 0 s, completed Jul 7, 2021 3:34:05 PM
sbt:fmgp-geometry> compile
[info] compiling 2 Scala sources to /home/fabio/workspace/fmgp-threejs/target/scala-3.0.0/classes ...
[error] -- Error: /home/fabio/workspace/fmgp-threejs/src/main/scala/File2.scala:3:40 ---
[error] 3 |val test = summon[io.circe.Decoder[AAA]]
[error]   |                                        ^
[error]   |       cannot reduce summonFrom with
[error]   |        patterns :  case given decodeA @ _:io.circe.Decoder[DDD.type]
[error]   |                    case given evidence$2 @ _:deriving.Mirror.Of[DDD.type]
[error]   | This location contains code that was inlined from Derivation.scala:19
[error]   | This location contains code that was inlined from Derivation.scala:32
[error]   | This location contains code that was inlined from Derivation.scala:11
[error]   | This location contains code that was inlined from Derivation.scala:70
[error]   | This location contains code that was inlined from auto.scala:16
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed Jul 7, 2021 3:34:07 PM

Note: Just File1 was recompiled.
The expectation was for File2 to be recompiled also

Expectation

The recompilation should fail and it did not fail!
It needed a clean compilation to show the error.

@FabioPinheiro
Copy link
Contributor Author

@smarter I minimized the code but it still depends on circe-generic.
I removed the cross versions. As far as I know everything is in Scala 3

@griggt
Copy link
Collaborator

griggt commented Jul 21, 2021

A self-contained example:

Foo.scala

case class Foo(x: Int)                // (1) first compile with this definition of Foo
//case class Foo(x: Int, y: String)   // (2) ...then incrementally compile with this one

Test.scala

import scala.deriving.Mirror
import scala.compiletime.{erasedValue, summonInline}

trait Decoder[A]

object Decoder:
  given Decoder[Int] = ???

  inline def derived[A](using m: Mirror.Of[A]): Decoder[A] =
    val elemDecoders = summonDecodersRec[m.MirroredElemTypes]
    new Decoder[A] {}

  inline def summonDecodersRec[T <: Tuple]: List[Decoder[_]] =
    inline erasedValue[T] match
      case _: EmptyTuple => Nil
      case _: (t *: ts) => summonInline[Decoder[t]] :: summonDecodersRec[ts]
end Decoder

object Test:
  val d: Decoder[Foo] = Decoder.derived[Foo]
// clean compilation with definition (1) of Foo
sbt:i13028> clean; compile
[info] compiling 2 Scala sources to /tmp/i13028/target/scala-3.0.3-RC1-bin-20210716-cc47c56-NIGHTLY/classes ...
[info] done compiling
[success] Total time: 5 s, completed Jul 20, 2021 8:18:30 PM

// replace definition (1) with (2) in Foo.scala and incrementally compile... expected to fail
sbt:i13028> compile
[info] compiling 1 Scala source to /tmp/i13028/target/scala-3.0.3-RC1-bin-20210716-cc47c56-NIGHTLY/classes ...
[info] done compiling
[success] Total time: 1 s, completed Jul 20, 2021 8:18:40 PM

// clean compile with definition (2)
sbt:i13028> clean; compile
[info] compiling 2 Scala sources to /tmp/i13028/target/scala-3.0.3-RC1-bin-20210716-cc47c56-NIGHTLY/classes ...
[error] -- Error: /tmp/i13028/Test.scala:20:24 -----------------------------------------
[error] 20 |  val d: Decoder[Foo] = Decoder.derived[Foo]
[error]    |                        ^^^^^^^^^^^^^^^^^^^^
[error]    |                  no implicit argument of type Decoder[String] was found
[error]    | This location contains code that was inlined from Test.scala:16
[error]    | This location contains code that was inlined from Test.scala:16
[error]    | This location contains code that was inlined from Test.scala:10
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

@griggt griggt removed the stat:needs minimization Needs a self contained minimization label Jul 21, 2021
@bishabosha bishabosha self-assigned this Jul 21, 2021
@smarter smarter linked a pull request Jul 29, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants