Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM native image errors out with TypeNotPresentException on Scala 3 #3030

Closed
zetashift opened this issue Jun 14, 2022 · 6 comments · Fixed by #3174
Closed

GraalVM native image errors out with TypeNotPresentException on Scala 3 #3030

zetashift opened this issue Jun 14, 2022 · 6 comments · Fixed by #3174

Comments

@zetashift
Copy link
Contributor

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!

@armanbilge
Copy link
Member

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

}

@rmgk
Copy link

rmgk commented Jun 23, 2022

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

@armanbilge
Copy link
Member

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
Copy link
Member

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

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

@armanbilge armanbilge changed the title scala-cli and Graal native image error out with TypeNotPresentException GraalVM native image errors out with TypeNotPresentException on Scala 3 Jul 13, 2022
@arixmkii
Copy link

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).

@armanbilge
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants