Closed urieli closed 7 months ago
more annoyingly,
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
| => api / Compile / compileIncremental 1567s
Scala 2 PRs related to cancellation: https://github.com/scala/scala/pull/6479, https://github.com/scala/scala/pull/8448 [edit: is there a scala3 ticket already? should spin one off otherwise.]
Thread seems to be stuck in typer, might be related to #19907 (both use Tapir, but this project does. not use long list of server endpoint, instead might be coused by combination of 2 complex type systems coming from Tapir and ZIO
When working on minimization for the issue mentioned above, I'll try to minimize this one as well.
Also based on draft of #19897 I was able to track the def that takes long to typecheck
val postBatchEndpoint: ZPartialServerEndpoint[Requirements, String, ValidToken, (ProjectCode, BatchRequest), HttpError, BatchResponse, Any] = ???
The R
parameter in def basicEndpoint[R]
is inferred based on whole chain of method out
invocations. The workaround to make compilation finish quickly is to hint the compiler about the type R
Self contained minimisation of issue:
abstract class ZPartialServerEndpoint[R, A, B, I, E, O, -C]
extends EndpointOps[A, I, E, O, C]{
override type ThisType[-_R] = ZPartialServerEndpoint[R, A, B, I, E, O, _R]
override type EndpointType[_A, _I, _E, _O, -_R] =ZPartialServerEndpoint[R, _A, B, _I, _E, _O, _R]
}
trait EndpointOps[A, I, E, O, -R] {
type EndpointType[_A, _I, _E, _O, -_R]
type ThisType[-_R]
def out[T]: EndpointType[A, I, E, T, R]
def description(d: String): ThisType[R]
}
object Test {
def basicEndpoint[R](): ZPartialServerEndpoint[R, Any, Any, Unit, Any, Unit, Any] = ???
// commonts next to `.out[Any]` contain information about compilation time when chaining up to N `out` functions
val case1 =
basicEndpoint() // 1.5s
.out[Any] // 1.6s
.out[Any] // 1.7s
.out[Any] // 2s
.out[Any] // 4s
.out[Any] // 33s
.out[Any] // aborted after 5 min
val case1Workaround =
basicEndpoint[Any]() // 1.4s
.out[Any] // 1.4s
.out[Any] // 1.4s
.out[Any] // 1.4s
.out[Any] // 1.4s
.out[Any] // 1.4s
.out[Any] // 1.4s
val case2_referToThisType =
basicEndpoint()
.out[Any] // 1.6s
.out[Any] // 2.2s
.out[Any] // 5.6s
.out[Any] // 53s
.description("Comment out to make compilation eventually finish")
val case2Workaround =
basicEndpoint[Any]()
.out[Any] // 1.6s
.out[Any] // 1.6s
.out[Any] // 1.6s
.out[Any] // 1.6s
.description("Comment out to make compilation finish") // 1.6s
}
@Gedochao I suggest to move this issue to P1 similarly as other slow typer issue mentioned above @odersky @noti0na1 I'm initially assigning this issue to you as it is in the same area as the previous type-inference related bug
abstract class ZPartialServerEndpoint[R, A, B, I, E, O, -C]
It seems the number of type parameter does affect the performance. I reduce the number of type parameters of ZPartialServerEndpoint
to 3, only including the necessary types used by basicEndpoint
, out
and description
. The 30-second compilations become 4s.
abstract class Z[R, O, -C]
extends EndpointOps[O, C]{
override type ThisType[-_R] = Z[R, O, _R]
override type EndpointType[_O, -_R] =Z[R, _O, _R]
}
trait EndpointOps[O, -R] {
type EndpointType[_O, -_R]
type ThisType[-_R]
def out[T]: EndpointType[T, R]
def description(d: String): ThisType[R]
}
object Test {
def basicEndpoint[R](): Z[R, Unit, Any] = ???
...
}
Thanks for the minimizations! I turned lots of logging on, but none of the usual subjects (type inference, implicit search, inlining) showed up. Instead it seemed to do lots of complicated memberDenot/findMember/asSeenFrom operations in deep recursions with complicated types like
ZPartialServerEndpoint[R, A, B, I, E, O, -C] # EndpointType[A, I, E, T, R] ... # EndpointType[A, I, E, T, R] (6 times)
turns out those complicated types can be avoided by more aggressive dealiasing. So I am trying that as a fix.
Compiler version
3.3.3 and 3.4.0
Minimized code
The project I'm attempting to compile is here.
I removed the business modules (which compile quickly) and kept only the api module (whose compilation never ends). I haven't minimized the code further as I could find no way of determining which parts were freezing the compiler.
Output
Expectation
I would expect scala 3 to compile the code, which scala 2.13.13 compiles in 18 seconds, in a reasonable amount of time.