typelevel / scala

Typelevel Scala, a fork of Scala
http://typelevel.org/scala/
372 stars 21 forks source link

Scalac hanging (during the typer phase) #174

Closed jtownson closed 6 years ago

jtownson commented 6 years ago

I have encountered a scenario where both typelevel and lightbend versions of scalac hang.

It is something to do with implicit resolution (poss involving Enumeration) but rather than me speculate, you can reproduce the problem by cloning the code here: https://bitbucket.org/jtownson/swakka/commits/0f8c017d61ed4d2ed87898d4907cc089d1aad171 , running sbt test, and noting that compilation will hang at net.jtownson.swakka.Petstore2Spec.

To reproduce add/remove fields from the 'Order' case class (and adjust the associated sprayjson format according to the number of fields). You can make scalac compile by removing fields from the case class. When adding them back, it will hang.

The presence of an implicit Enumeration is suspicious but my experiments suggest it is simply when the number of fields in the class rises above 3. I suppose the compiler is hanging whilst resolving implicits, however, I have other tests that prove implicit resolution works fine for each individual field type.

I am stumped and this is beyond my scalac knowledge hence I am raising it with you guys. This blocks my project so if you have any idea what could be going wrong in the compiler and any workarounds or fixes I'd be most grateful.

jtownson commented 6 years ago

Attaching a core dump from my system. scalac-core-dump.txt

milessabin commented 6 years ago

If this behaves the same way with the Lightbend compiler then I think the best place to report this issue is the scala/scala issue tracker here: https://github.com/scala/bug

jtownson commented 6 years ago

I thought this was more up your street because the core dump shows implicit resolution failing under shapeless.LazyMacrosRef.mkLazyImpl whilst calling the compiler tooling.

milessabin commented 6 years ago

Ahh ... it wasn't clear from what you posted that shapeless's Lazy was involved. Arguably that make this is shapeless issue rather than a compiler issue.

Either way, it would really help you could try and reduce to a small standalone (with the exception of shapeless if you need Lazy to show the issue) example.

jtownson commented 6 years ago

In cutting down to size, I realize my own code was missing an implicit. On a smaller project when adding/removing that same implicit, the compiler behaves as expected -- compilation either succeeds or fails without hanging.

Anecdotally, then, the problem is something to do with missing implicits under shapeless's Lazy but I cannot pin it down to either shapeless or scalac.

That being the case, I will close the bug. The git SHA above is there in case anybody encounters a similar problem in future.