How to make the Scala compiler non-terminating in 1 easy step

0 views
Skip to first unread message

Ben Hutchison

unread,
Nov 6, 2025, 7:24:10 PM (8 hours ago) Nov 6
to Melbourne Compose Group
Scala is almost 25 years old, and the compiler is on its 3rd rewrite, yet still prone to non-termination:

sbt:moduel> fs2_file/compile
[info] compiling 1 Scala source to /Users/ben/workspace/moduel/fs2_file/target/scala-3.7.3/classes ...
  | => fs2_file / Compile / compileIncremental 288s


Once this happens, no remedy short of Force Quit (kill -9) seems to stop it.

I had to prise apart my code to locate the unexpected source of the problem by elimination:

extension (p: Path)
    def directoryOf[F[_]: Files as fs]: F[Path :| IsDir] =
      p.isDir.ifF(p, p.absolute.parent.liftTo(ErrorMsg(s"directoryOf ${p.absolute}")))

The problem that seems to drive Scala compiler to insanity is that effect-type F is under-constrained. It has a narrow Files capability that permits some FS operations, but no general IO-like capability. Call ifF wants F to have Functor (and liftTo needs ApplicativeThrow), and that causes Scala to spin off into an (near-)infinite search for a way to find/derive a Functor etc on F, and for some weird reason it can never just give up.


My new heuristic: slow or non-terminating compilation probably caused by pathologically under-constrained effect types.

-Ben

Reply all
Reply to author
Forward
0 new messages