scalameta / sbt-native-image

Plugin to generate native-image binaries with sbt
248 stars 22 forks source link

Native image tool seems to fail on Scala 2.13.7 #40

Closed Christewart closed 2 years ago

Christewart commented 2 years ago

When upgrading to Scala 2.13.7 on bitcoin-s, publishing our bitcoin-s-cli tool seems to fail:

https://github.com/bitcoin-s/bitcoin-s/runs/4091599423?check_suite_focus=true#step:5:134

SethTisue commented 2 years ago
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.LambdaForm$MH/945987348.invoke_MT(Object, Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Detailed message:
Trace: 
    at parsing scala.runtime.NonLocalReturnControl.<init>(NonLocalReturnControl.scala:19)
Call path from entry point to scala.runtime.NonLocalReturnControl.<init>(Object, Object): 
    at scala.runtime.NonLocalReturnControl.<init>(NonLocalReturnControl.scala:19)

try a newer GraalVM version, perhaps? you appear to be on 20.2.0; latest is 21.3.0

not sure if related to https://github.com/scala/bug/issues/12084 and/or https://github.com/scala/bug/issues/12116

Christewart commented 2 years ago

seems like the plugin should just work out of the box, i'm not modifying settings on the project https://github.com/scalameta/sbt-native-image#generate-native-image-binaries-with-sbt

SethTisue commented 2 years ago

indeed, but nativeImageVersion is a setting you can override, so as part of the process of getting to the bottom of this, it would be helpful to know if overriding it to a more recent version in your project improves the situation

especially if the newer version is found to help, then perhaps a pull request bumping the plugin's default version would be welcome.

note that I'm not a maintainer in this repo, I just happened to see this ticket. but I am a Scala 2 maintainer, so I'm interested because of the possibility of a Scala/GraalVM compatibility issue being the root cause.

Christewart commented 2 years ago

nativeImageVersion := "21.3.0" doesn't seem to work for me unfortunately inside of cli.sbt and it doesn't pick up the setting :-(

https://github.com/bitcoin-s/bitcoin-s/blob/master/app/cli/cli.sbt

Screenshot from 2021-11-22 10-30-53

olafurpg commented 2 years ago

Thank you for reporting! I'm unable to reproduce with a minimal hello world application. The call-stack points to this line here https://sourcegraph.com/maven/org.scala-lang/scala-library@v2.13.7/-/blob/scala/runtime/NonLocalReturnControl.scala?L19 but it doesn't seem to have changed in v2.13.7 so I'm not sure what's the root cause

This plugin already uses https://github.com/scalameta/svm-subs to fix similar issues when scala-library uses JVM runtime reflection. It's probably best to report an issue to scala/scala to get more eyeballs on this issue 👀 The error is beyond my understanding of scala-library or GraalVM

Christewart commented 2 years ago

Thank you for reporting! I'm unable to reproduce with a minimal hello world application. The call-stack points to this line here https://sourcegraph.com/maven/org.scala-lang/scala-library@v2.13.7/-/blob/scala/runtime/NonLocalReturnControl.scala?L19 but it doesn't seem to have changed in v2.13.7 so I'm not sure what's the root cause

This plugin already uses https://github.com/scalameta/svm-subs to fix similar issues when scala-library uses JVM runtime reflection. It's probably best to report an issue to scala/scala to get more eyeballs on this issue eyes The error is beyond my understanding of scala-library or GraalVM

Thanks @olafurpg . You are awesome and I appreciate all you do

Christewart commented 2 years ago

Upgrading to scalac 2.13.8 fixes this :tada: