cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

GraalVM native image errors out with `TypeNotPresentException` on Scala 3

Open zetashift opened this issue 3 years ago • 6 comments
trafficstars

I'm trying to run a small http4s example with scala-cli and for fun I was trying to package it through GraalVM, but I'm running into an error into (what looks like) a cats-effect error.

Steps to reproduce

If one has scala-cli installed, the following can be run to reproduce the error:

scala-cli package --native-image https://gist.github.com/zetashift/bdefce3d692e6a626e6bf2ecaf218f48 -f -- --no-fallback

Code is located here: https://gist.github.com/zetashift/bdefce3d692e6a626e6bf2ecaf218f48

Error

Short:

Fatal error: java.lang.TypeNotPresentException: Type cats.effect.kernel.Par$ParallelFImpl.T not present
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)

The long version: http://ix.io/40aH

Still having a lot of fun with Cats Effect and scala-cli so thank you all for this awesome library!

zetashift avatar Jun 14 '22 19:06 zetashift

Here's a minimization. Switching to Scala 2.13.8 makes the problem go away, so it seems to be specific to the Scala 3 encoding. If further minimized might even be a dotty issue.

//> using scala "3.1.2"
//> using lib "org.typelevel::cats-effect:3.3.12"

import cats._
import cats.effect._
import cats.syntax.all._

object MyApp extends IOApp.Simple {

  def run = foo[IO]

  def foo[F[_]: Async: Parallel] = Async[F].unit &> Async[F].unit

}

armanbilge avatar Jun 14 '22 19:06 armanbilge

Note, I had a similar issue involving https://ben.kirw.in/decline/ and cats.Applicative.F. I do not have a minimization, but for me the issue only occurred on native image 22.1.0 (not on 22.0.0.2) so I considered it a regression in native image (which are pretty common). All on Scala 3.1.2

rmgk avatar Jun 23 '22 13:06 rmgk

I still wonder if this can be classified as a regression in Scala 3 relative to Scala 2. Specifically that the backend is emitting some bytecode Graal doesn't like. There are many backend fixes in 2 that need to be ported to 3 so this could be one of them.

armanbilge avatar Jun 23 '22 13:06 armanbilge

So there was a very similar issue reported and fixed in dotty:

  • https://github.com/lampepfl/dotty/issues/15091
  • https://github.com/lampepfl/dotty/pull/15093

That fix first shipped in 3.2.0-RC1. Unfortunately, it doesn't seem to fix my minimization above 😕

armanbilge avatar Jul 13 '22 05:07 armanbilge

Unfortunately, it doesn't seem to fix my minimization above 😕

Do you mean it didn't work with released version of Scala and cats-effect? Something like

//> using scala "3.2.0-RC1"
//> using lib "org.typelevel::cats-effect:3.3.13"

For me to fix it I had to first rebuild cats-effect snapshot using Scala 3.2.0-RC1 (as the issue is in bytecode of the library).

arixmkii avatar Jul 13 '22 14:07 arixmkii

Oh, right! D'oh, that makes sense 😄 thanks!

armanbilge avatar Jul 13 '22 14:07 armanbilge