Compiler hangs on infinite match type reduction
See original GitHub issueclass P[X, Y]
type Swap[X] = X match
case P[x, y] => Swap[P[y, x]]
val z: P[String, Int] = ??? : Swap[P[Int, String]]
The compiler seems to hang when compiling the last line.
Expectation
The compiler should either report a stack overflow or detect the diverging expansion statically. My preference would be to try static divergence detection first. @milessabin implemented state of the art techniques for detecting divergent implicit searches - it seems that these techniques are transferable.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Match Types - Scala 3 - EPFL
Match type definitions can be recursive, which means that it's possible to run into an infinite loop while reducing match types. Since reduction...
Read more >Match Types in Scala 3 - Baeldung
If we attempted to write an infinite match type definition, we'd get the following error message at compile time: “Recursion limit exceeded.
Read more >Compile hangs endlessly in LLVM in await-heavy code when ...
The bugpoint run took around 9 hours in my case. llvm-reduce was much shorter, since the case was already minimized. One final annoyance...
Read more >Match Types in Dotty | by Knoldus Inc. - Medium
Match types can also detect infinite loop if it is defined as an endless recursion. The compiler internally detects it by stack overflows....
Read more >Scala 3 match type reduction - Stack Overflow
Let's say I want to represent a vector using a matched type like this: type V[I <: Int, N] = I match case...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There’s a detailed description of the divergence checking algorithm along with a termination proof in the by-name implicits SIP. See here for what I implemented in dotty and scalac … see also the descriptions just above of the previous scalac algorithm and the even earlier version described in the SLS.
I think a manually configured compile time option isn’t a good idea because the user has no idea how to set it other than by increasing it until the compilation is successful or until they get bored. In the case of implicit resolution, deeply buried failures can be hidden by an overall failure, so an implicit resolution step limit would be extremely confusing for users. I’m not sure to what extent that would carry over to this case, but in general these sort of limits are unhelpful.
If you are able to use this algorithm for match type reduction, then we have a termination proof, so we’re not trying to prevent an infinite loop. That being the case I think it’s better to run without a manual bound and let users hit ctrl-c when they get tired of waiting.
Actually, no they do not have a false negative.