Comments (5)
Note: same output when adding the --no-fallback
option.
from graal.
For the record I also tried to compile it through Scala CLI's --native-image options, yielding the same result:
➜ ~/dotty-fresh git:(main) scala-cli --power package -o dotty-native --native-image --main-class dotty.tools.dotc.Main --classpath 'dist/target/pack/lib/*' --graalvm-args '-cp dist/target/pack/lib/*' --graalvm-args "--no-fallback"
from graal.
By the way, not directly related to the issue, but there actually is a much nicer possible setup using Scala CLI and using Dotty as a dependency, which avoids fiddling with JARs manually:
Let dotty.scala
contain:
//> using scala "3.3.1"
//> using dep "org.scala-lang::scala3-compiler:3.3.1"
@main def main(args: String*) = dotty.tools.dotc.Main.process(args.toArray)
Then we can run:
$ scala-cli --power package dotty.scala -o dotty-native --native-image --graalvm-args "--no-fallback"
This yields the same executable—which throws the same error—as the instructions in the issue description:
$ ./dotty-native -cp $SCALA_LIB hello.scala
Exception while compiling hello.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:169)
at dotty.tools.dotc.core.Definitions.ObjectClass(Definitions.scala:321)
...
from graal.
We are one step further thanks to @sjrd!
A problem was apparently due to Dotty trying to read Java standard library modules, which did not work in native image.
We instead generated a JAR with Java standard library classes using a script in tasty-query (https://github.com/scalacenter/tasty-query/blob/main/build.sbt#L176-L206). This script can be run from SBT as follows:
$ git clone [email protected]:scalacenter/tasty-query.git
$ cd tasty-query
$ sbt "tastyQueryJS / Test / javalibEntry"
Using this JAR, we can now successfully compile hello.scala
using the Dotty native image! 🥳
$ mkdir classes
$ time ./dotty-native -bootclasspath extracted-rt.jar -cp $SCALA_LIB -d classes hello.scala
./dotty-native -bootclasspath extracted-rt.jar -cp $SCALA_LIB -d classes 0.13s user 0.05s system 79% cpu 0.227 total
However, the generated class file seems to be corrupted:
$ java -cp $SCALA_LIB:$(pwd)/classes main
Error: Unable to initialize main class main
Caused by: java.lang.VerifyError: Constructor must call super() or this() before return
Exception Details:
Location:
main.<init>()V @0: return
Reason:
Error exists in the bytecode
Bytecode:
0000000: b1
Which is not the case if we generate it with the JVM version:
scala-cli dotty.scala -- -bootclasspath extracted-rt.jar -cp $SCALA_LIB -d classes-jvm hello.scala
My decompiler shows the same text for both:
// Source code is decompiled from a .class file using FernFlower decompiler.
import hello.package.;
import scala.util.CommandLineParser;
public final class main {
public main() {
}
public static void main(final String[] args) {
try {
.MODULE$.main();
} catch (CommandLineParser.ParseError var2) {
scala.util.CommandLineParser..MODULE$.showError(var2);
}
}
}
But the binaries of main.class
are indeed different:
(File truncated, end not shown)
from graal.
Hey @mbovel, thanks for digging into this! I'm not really familiar with Dotty, maybe you can help me understand the actual error a bit more. I assume asTerm()
is supposed to be called in your app, only the assertion is not supposed to fail, right?
Exception in thread "main" java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:171)
If Dotty or some other part are marked for build-time initialization, it's possible that "non-a-Term" object is created a build-time and frozen into the image. Maybe you could run with the -H:+PrintClassInitialization
option for Native Image, which should provide you with an overview of all initialization policies.
from graal.
Related Issues (20)
- [GR-52560] Size regression from GraalVM CE 23.0 to GraalVM for JDK 21 (CE) for `byte[] for code metadata` HOT 2
- JSON Metadata Versioning, Backwards Compatibility, and Evolution
- [GR-52553] Defining new classes at runtime is not supported HOT 2
- [GR-52591] Warning: Error processing trace entry map(size=5, {(tracer,reflect),(function,getSystemResource),(caller_class,org.apache.logging.log4j.core.util.Loader),(result,true),(args,[null])}): java.lang.NullPointerException HOT 3
- Caused by: java.lang.IllegalArgumentException: Method "list" could not be invoked HOT 14
- [GR-52611] Add the ability to add comments to JSON configuration file entries HOT 7
- --module-path directory: Modules Not Added HOT 5
- [GR-52818] javax.xml.transform.TransformerFactory.newTemplates(Source) NullPointerException in Native Image HOT 15
- Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: type is not available in this platform: com.oracle.svm.hosted.NativeImageSystemClassLoader HOT 1
- Instructions for building native-image-agent HOT 2
- [GR-52698] Cannot run SSL debug logs with GraalVM native image HOT 4
- the size of graal compiled program HOT 1
- Could not initialize class org.graalvm.polyglot.Engine$ImplHolder HOT 2
- [GR-52826] Non-ASCII characters in command line arguments are replaced by U+FFFD in Windows (native-image) HOT 7
- GraalVM uses getObjectVolatile and compareAndSetObject from unsafe which are removed in JDK 23 HOT 3
- MacOS native-image: No awt in java.library.path HOT 1
- ClassLoader.classes field substitution error HOT 1
- GraalVM for JDK 22 Community: ForeignFunctionsRuntime$UnregisteredForeignStubException: [FFM] Cannot perform downcall with leaf type (long,long,long,long,long)void as it was not registered at compilation time. HOT 4
- Random deadlocks when creating new context HOT 3
- [GR-52872] Confusing error when attempting to call a method annotated with HostAccess.Export on a class with private visibility
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graal.