com-lihaoyi / mill

Mill is a fast JVM build tool that supports Java and Scala. 2-3x faster than Gradle and 5-10x faster than Maven for common workflows, Mill aims to make your project’s build process performant, maintainable, and flexible
https://mill-build.org/
MIT License
2.04k stars 331 forks source link

StackOverflow in compiler when using mill + tapir + zio-json #3104

Open leon-becker-secforge opened 6 months ago

leon-becker-secforge commented 6 months ago

Hi,

I am experiencing a compiler bug, which I wasn't able to reproduce with scala-cli yet. So first wanted to report it here as it acutually might be caused by mill itself.

Code to reproduce

It is a mill project setup with two files. Execute rm -rf out && mill demo.run to see the problem.

Used mill version is 0.11.7, used Java versions are 11.0.22 and 17.0.10 on Ubuntu. All other version are fixed in the provided build file.

Code `build.sc` ```scala import mill._, scalalib._, scalajslib._ object demo extends ScalaModule { def scalaVersion = "3.3.3" def scalacOptions = super.scalacOptions() ++ Agg("-Xmax-inlines", "64") def ivyDeps = Agg( ivy"dev.zio::zio-json::0.6.2", ivy"com.softwaremill.sttp.tapir::tapir-zio::1.10.0", ivy"com.softwaremill.sttp.tapir::tapir-core::1.10.0", ivy"com.softwaremill.sttp.tapir::tapir-json-zio::1.10.0" ) } ``` `demo/file.scala` ```scala //> using scala "3.3.3" //> using option "-Xmax-inlines" "64" //> using dep "dev.zio::zio-json::0.6.2" //> using dep "com.softwaremill.sttp.tapir::tapir-zio::1.10.0" //> using dep "com.softwaremill.sttp.tapir::tapir-core::1.10.0" //> using dep "com.softwaremill.sttp.tapir::tapir-json-zio::1.10.0" import zio.json.* import sttp.tapir.* import sttp.tapir.json.zio.* // Commen out next line import sttp.tapir.generic.auto.* enum Size { case Small case Medium case Big } enum Position { case TopLeft case TopRight case BottomLeft case BottomRight } sealed case class C( qrCodeSize: Size, qrCodePosition: Position ) sealed case class B() sealed case class A(c: C, bs: List[B]) enum UpdateMessage { case Initial(data: A) } given JsonDecoder[B] = DeriveJsonDecoder.gen[B] given JsonDecoder[C] = DeriveJsonDecoder.gen[C] given JsonDecoder[A] = DeriveJsonDecoder.gen[A] given JsonDecoder[UpdateMessage] = DeriveJsonDecoder.gen[UpdateMessage] given JsonDecoder[Size] = DeriveJsonDecoder.gen[Size] given JsonDecoder[Position] = DeriveJsonDecoder.gen[Position] given JsonEncoder[B] = DeriveJsonEncoder.gen[B] given JsonEncoder[C] = DeriveJsonEncoder.gen[C] given JsonEncoder[A] = DeriveJsonEncoder.gen[A] given JsonEncoder[UpdateMessage] = DeriveJsonEncoder.gen[UpdateMessage] given JsonEncoder[Size] = DeriveJsonEncoder.gen[Size] given JsonEncoder[Position] = DeriveJsonEncoder.gen[Position] // Comment in following lines // given Schema[B] = Schema.derived // given Schema[C] = Schema.derived // given Schema[A] = Schema.derived // given Schema[UpdateMessage] = Schema.derived // given Schema[Size] = Schema.derived // given Schema[Position] = Schema.derived @main def main = { val ep = endpoint .out(jsonBody[UpdateMessage]) println(ep.show) } ```

Observed behavior

Compilation produces a compiler bug, compiling the code again usually works, I guess due to caching. I tried to reproduce the problem using scala-cli, hence the directives in file.scala, yet it didn't occur.

When removing import sttp.tapir.generic.auto.* and providing tapir manually with the needed schemas the bug vanishes, so I assume it is connect with to deep inlining.

Expected behavior

The compiler bug should not occur, or it should also occur when using scala-ci.

Bug logs

These logs where recorded using GitHub Actions on ubuntu-latest.

Mill Log ``` cd misc/compiler_bug && ./../../millw demo.run shell: /usr/bin/bash -e {0} No mill version specified. You should provide a version via '.mill-version' file or --mill-version option. find: ‘/home/runner/.cache/mill/download/.latest’: No such file or directory Retrieving latest mill version ... Using mill version 0.11.7 Downloading mill 0.11.7 from https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/0.11.7/mill-dist-0.11.7.jar ... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 57.0M 100 57.0M 0 0 209M 0 --:--:-- --:--:-- --:--:-- 209M Preparing Java 11.0.22 runtime; this may take a minute or two ... [info] compiling 1 Scala source to /home/runner/work/networking-application/networking-application/misc/compiler_bug/out/mill-build/compile.dest/classes ... [info] done compiling [info] compiling 1 Scala source to /home/runner/work/networking-application/networking-application/misc/compiler_bug/out/demo/compile.dest/classes ... unhandled exception while running inlining on /home/runner/work/networking-application/networking-application/misc/compiler_bug/demo/src/file.scala An unhandled exception was thrown in the compiler. Please file a crash report here: https://github.com/lampepfl/dotty/issues/new/choose while compiling: /home/runner/work/networking-application/networking-application/misc/compiler_bug/demo/src/file.scala during phase: inlining mode: Mode(ImplicitsEnabled) library version: version 2.13.12 compiler version: version 3.3.3 settings: -Wunused List(imports, params, implicits) -Xmax-inlines 64 -bootclasspath /home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -classpath /home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-json_3/0.6.2/zio-json_3-0.6.2.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/tapir/tapir-zio_3/1.10.0/tapir-zio_3-1.10.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/tapir/tapir-core_3/1.10.0/tapir-core_3-1.10.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/tapir/tapir-json-zio_3/1.10.0/tapir-json-zio_3-1.10.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio_3/2.0.21/zio_3-2.0.21.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-streams_3/2.0.21/zio-streams_3-2.0.21.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_3/2.9.0/scala-collection-compat_3-2.9.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/magnolia1_3/magnolia_3/1.3.4/magnolia_3-1.3.4.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/shared/zio_3/1.3.17/zio_3-1.3.17.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/model/core_3/1.7.7/core_3-1.7.7.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/shared/core_3/1.3.17/core_3-1.3.17.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/shared/ws_3/1.3.17/ws_3-1.3.17.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-internal-macros_3/2.0.21/zio-internal-macros_3-2.0.21.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-stacktracer_3/2.0.21/zio-stacktracer_3-2.0.21.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/izumi-reflect_3/2.3.8/izumi-reflect_3-2.3.8.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/izumi-reflect-thirdparty-boopickle-shaded_3/2.3.8/izumi-reflect-thirdparty-boopickle-shaded_3-2.3.8.jar:/home/runner/work/networking-application/networking-application/misc/compiler_bug/demo/compile-resources:/home/runner/work/networking-application/networking-application/misc/compiler_bug/out/demo/compile.dest/classes -d /home/runner/work/networking-application/networking-application/misc/compiler_bug/out/demo/compile.dest/classes Error: ## Exception when compiling 1 sources to /home/runner/work/networking-application/networking-application/misc/compiler_bug/out/demo/compile.dest/classes Error: java.lang.StackOverflowError Error: dotty.tools.dotc.ast.Positioned.sourcePos(Positioned.scala:52) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.recur$1(report.scala:128) Error: dotty.tools.dotc.report$.addInlineds(report.scala:130) Error: dotty.tools.dotc.report$.error(report.scala:78) Error: dotty.tools.dotc.typer.ErrorReporting$.errorType(ErrorReporting.scala:36) Error: dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:28) Error: dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3592) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) Error: dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100) Error: dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3072) Error: dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115) Error: dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedSelect(Inliner.scala:774) [...] Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) Error: dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedMatchFinish(Inliner.scala:886) Error: dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:1746) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedMatch(Inliner.scala:851) Error: dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3064) Error: dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115) Error: dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) Error: dotty.tools.dotc.inlines.Inliner.inlined(Inliner.scala:681) Error: dotty.tools.dotc.inlines.Inlines$InlineCall.expand(Inlines.scala:449) Error: dotty.tools.dotc.inlines.Inlines$.inlineCall(Inlines.scala:152) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.inlineIfNeeded(Inliner.scala:911) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedApply(Inliner.scala:820) Error: dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3050) Error: dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115) Error: dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedSelect(Inliner.scala:774) Error: dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3019) Error: dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3114) Error: dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) Error: dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303) Error: dotty.tools.dotc.typer.Applications.typedTypeApply(Applications.scala:1153) Error: dotty.tools.dotc.typer.Applications.typedTypeApply$(Applications.scala:352) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedTypeApply(Inliner.scala:824) Error: dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3069) Error: dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115) Error: dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187) Error: dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) Error: dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303) Error: dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:941) Error: dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101) Error: dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedApply(Inliner.scala:820) Error: dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3050) Error: dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115) Error: dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915) Error: dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115) Error: dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153) Error: dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915) Error: dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$7(ProtoTypes.scala:495) Error: dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:418) Error: dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:496) Error: dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897) Error: dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897) Error: dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:589) Error: Exception in thread "MillServerActionRunner" java.lang.StackOverflowError at dotty.tools.dotc.ast.Positioned.sourcePos(Positioned.scala:52) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.recur$1(report.scala:128) at dotty.tools.dotc.report$.addInlineds(report.scala:130) at dotty.tools.dotc.report$.error(report.scala:78) at dotty.tools.dotc.typer.ErrorReporting$.errorType(ErrorReporting.scala:36) at dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:28) at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3592) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191) at dotty.tools.dotc.typer.ReTyper.typedInlined(ReTyper.scala:100) Error: Process completed with exit code 1. ```