question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler hangs on infinite match type reduction

See original GitHub issue
class 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:closed
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
milessabincommented, Apr 12, 2021

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.

0reactions
oderskycommented, Apr 19, 2021

If the checks in question can have false negative (i.e. they can fail to detect infinite reductions), then we probably want to back them up with a bound to catch those cases.

Actually, no they do not have a false negative.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found