zinc icon indicating copy to clipboard operation
zinc copied to clipboard

Unnecessary recompilation with long nested type names under -Xmax-classfile-name

Open pmpfr opened this issue 5 years ago • 2 comments

steps

sbt version: 1.3.4 (and 1.3.3) but sbt 1.2.8 works as expected (scala 2.12.8)

problem

Files with nested types whose combined names are longer than a certain limit are seen as always needing recompilation by sbt (invalidated). For me, -Xmax-classfile-name=80 gives a limit of 65 characters: at or beyond that my test file always gets recompiled.

package foo

object ABCD45678901234567890123456789012345678901234567890123456789 {
  class ABCD
}

object Test {
  val _ = new ABCD45678901234567890123456789012345678901234567890123456789.ABCD
  //          ^^^^^^^^^^^^^^^^^^^^^^ 65 characters long ^^^^^^^^^^^^^^^^^^^^^^^
}

expectation

When unchanged, the file should not be recompiled no matter how long the type names inside. This was the behaviour under sbt 1.2.8

notes

Transcript

MB19090:LengthLimit peter.robinson$ cat project/build.properties
sbt.version=1.3.4
MB19090:LengthLimit peter.robinson$ cat LengthTest.scala
package foo

object ABCD45678901234567890123456789012345678901234567890123456789 {
  class ABCD
}

object Test {
  val _ = new ABCD45678901234567890123456789012345678901234567890123456789.ABCD
  //          ^^^^^^^^^^^^^^^^^^^^^^ 65 characters long ^^^^^^^^^^^^^^^^^^^^^^^
}
MB19090:LengthLimit peter.robinson$ cat build.sbt
scalaVersion := "2.12.8"
scalacOptions ++= Seq("-Xmax-classfile-name", "80")
MB19090:LengthLimit peter.robinson$ sbt
[info] Loading settings for project global-plugins from idea.sbt ...
[info] Loading global plugins from /Users/peter.robinson/.sbt/1.0/plugins
[info] Loading project definition from /private/tmp/LengthLimit/project
[info] Loading settings for project lengthlimit from build.sbt ...
[info] Set current project to lengthlimit (in build file:/private/tmp/LengthLimit/)
[info] sbt server started at local:///Users/peter.robinson/.sbt/1.0/server/b778c582df5d59e42bb9/sock
sbt:lengthlimit> compile
[info] Compiling 1 Scala source to /private/tmp/LengthLimit/target/scala-2.12/classes ...
[success] Total time: 3 s, completed 10-Dec-2019 13:03:32
sbt:lengthlimit> compile
[info] Compiling 1 Scala source to /private/tmp/LengthLimit/target/scala-2.12/classes ...
[success] Total time: 0 s, completed 10-Dec-2019 13:03:35
sbt:lengthlimit>

pmpfr avatar Dec 10 '19 13:12 pmpfr

I can also reproduce the problem (with an even longer name) without setting -Xmax-classfile-name at all, including under scala 2.13 where that's not an option. Again it's a problem for sbt 1.3.4 but not for 1.2.8.

pmpfr avatar Dec 10 '19 13:12 pmpfr

@pmpfr Thanks for the report. I am going to transfer this issue to Zinc.

eed3si9n avatar Dec 10 '19 15:12 eed3si9n

Fixed by https://github.com/sbt/zinc/pull/1259

Friendseeker avatar Dec 19 '23 22:12 Friendseeker