oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.37k stars 1.63k forks source link

Unable to find language by ID despite registration, adding classpath, and jar #8823

Open msp-gh opened 6 months ago

msp-gh commented 6 months ago

Output of java -Xinternalversion:

Java HotSpot(TM) 64-Bit Server VM (22.0.1+8-jvmci-b01) for bsd-aarch64 JRE (22.0.1+8-jvmci-b01), built on 2024-03-14T12:26:11Z by "graal1" with clang Apple LLVM 14.0.3 (clang-1403.0.22.14.1)

Was obtained from/using: sdk install java 22.0.1-graal.

Issue: I'm using Truffle to build my own language and I've annotated the TruffleLanguage subtype using the Registration annotation. I've also added the jar using -Dtruffle.class.path.append= option. However, Truffle still complains that it can't find my language by the ID.

Here's the build file:

lazy val root = project
  .in(file("."))
  .settings(
    name := "truffle-lang",
    scalaVersion := "3.4.0",
    run / fork := true,
    javaOptions += "-Dtruffle.class.path.append=/Users/username/Repos/truffle-lang/target/scala-3.4.0/truffle_lang_3-0.1.0-SNAPSHOT.jar",

    // Dependencies
    libraryDependencies += "org.graalvm.truffle" % "truffle-api" % "24.0.1",
    libraryDependencies += "org.graalvm.truffle" % "truffle-dsl-processor" % "24.0.1",
  )

Error:

Exception in thread "main" java.lang.IllegalArgumentException: A language with id '<lang ID>' is not installed. Installed languages are: [].

Here's how my TruffleLanguage sub type looks like:

// ID, name, and version are redacted. They're filled in correctly.
@TruffleLanguage.Registration(id = "<lang ID>", name = "<lang name>", version = "<version>")
final class TruffleLanguage extends TruffleLanguage[TruffleContext] {
  // ...
}

I'd be glad if someone could help me out.

ZynoZin commented 6 months ago

Hello @msp-gh, we are working on this. We will get back to you as soon as we can.

msp-gh commented 6 months ago

Hi @ZynoZin. Do you have any update for me?

hamzaGhaissi commented 6 months ago

Hi @msp-gh, can you please share a reproducer with steps, as this is complicated to reproduce without one

msp-gh commented 6 months ago

I've attached the build.sbt file and the TruffleLanguage class in the above description. Just the class and the build file is all you need to reproduce the issue. Are you able to use the Registration annotation and register the language in Scala?

ZynoZin commented 6 months ago

Hi @msp-gh we apologize for the late response. You are using JDK22, so all languages should be proper modules and put on the JVM module path. This blog post should be relevant to your use case.

I think @chumer might have more info to help you about this.

msp-gh commented 5 months ago

@ZynoZin I have an update for you. If TruffleLanguage class (that's mentioned in the above description) is changed to Java file (with the exact same setup and no other changes), Truffle is able to see my language. If I change it to Scala, Truffle has problems finding it. The registration annotation is present in the bytecode generated by the Scala compiler. Any idea what's happening here? I think the problem is related to the annotation processing and the subsequent finding by Truffle.

cc @chumer