typelevel / skunk

A data access library for Scala + Postgres.
https://typelevel.org/skunk/
MIT License
1.58k stars 161 forks source link

graalvm native-image error #623

Open ohuu opened 2 years ago

ohuu commented 2 years ago

I'm trying out Skunk with graalvm's native-image feature. It's failing and I've narrowed it down to when I call Session.prepare. I've also noticed that Metals can't get any info on that function when hovering over it, perhaps these problems are related?

The error from GraalVM is below.

I took a look at Skunk source code to see if I could find anything obvious that might be causing the error and all I can think is that there appears to be some cross compilation going on here, is there anything loading classes at runtime based on the platform or anything? GraalVM really dislikes that for obvious reasons.

It would be absolutely amazing to get Skunk working in a native image. All the other database libraries rely on JDBC and I haven't been able to get them to work.

#13 84.97 Fatal error:java.lang.InternalError: Enclosing method not found
#13 84.98       at java.base/java.lang.Class.getEnclosingMethod(Class.java:1296)
#13 84.98       at java.base/sun.reflect.generics.scope.ClassScope.computeEnclosingScope(ClassScope.java:50)
#13 84.98       at java.base/sun.reflect.generics.scope.AbstractScope.getEnclosingScope(AbstractScope.java:77)
#13 84.98       at java.base/sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:95)
#13 84.98       at java.base/sun.reflect.generics.factory.CoreReflectionFactory.findTypeVariable(CoreReflectionFactory.java:110)
#13 84.98       at java.base/sun.reflect.generics.visitor.Reifier.visitTypeVariableSignature(Reifier.java:165)
#13 84.99       at java.base/sun.reflect.generics.tree.TypeVariableSignature.accept(TypeVariableSignature.java:43)
#13 84.99       at java.base/sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
#13 84.99       at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
#13 84.99       at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
#13 84.99       at java.base/sun.reflect.generics.repository.ClassRepository.computeSuperInterfaces(ClassRepository.java:117)
#13 84.99       at java.base/sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:95)
#13 84.99       at java.base/java.lang.Class.getGenericInterfaces(Class.java:1137)
#13 84.99       at com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis.fillGenericInfo(NativeImagePointsToAnalysis.java:343)
#13 84.99       at com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis.checkType(NativeImagePointsToAnalysis.java:140)
#13 84.99       at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
#13 84.99       at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
#13 84.99       at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)
#13 84.99       at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
#13 85.00       at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
#13 85.00       at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
#13 85.00       at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
#13 85.00       at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
#13 85.00       at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
#13 85.00       at com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis.checkObjectGraph(NativeImagePointsToAnalysis.java:125)
#13 85.00       at com.oracle.graal.pointsto.PointsToAnalysis.checkObjectGraph(PointsToAnalysis.java:676)
#13 85.00       at com.oracle.graal.pointsto.PointsToAnalysis.finish(PointsToAnalysis.java:644)
#13 85.00       at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:704)
#13 85.00       at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:529)
#13 85.00       at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
#13 85.00       at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
#13 85.00       at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
#13 85.00       at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
#13 85.00       at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:599)
#13 85.00 [accuheat3:25]      [total]:  83,712.94 ms,  2.26 GB
#13 85.02 # Printing build artifacts to: /app/accuheat3.build_artifacts.txt
#13 85.97 Error: Image build request failed with exit status 1
#13 85.97 com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
#13 85.98       at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1762)
#13 85.98       at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1473)
#13 85.98       at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1434)
#13 85.98       at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1421)
ohuu commented 2 years ago

In order to find out exactly what's causing the error I need to change the source in skunk, I've cloned the library but I'm struggling to create a project that uses the cloned skunk project as a dependency in SBT. I've tried the obvious things:

lazy val skunk = project.in(file("../skunk"))
lazy val root = project.in(file(".")).dependsOn(skunk)

but that doesn't work. How can I depend on skunk so I can track down this error?

davidlar commented 1 year ago

I get the same error when I update to Scala 3. I did some debugging of the native build.

The problem is https://github.com/lampepfl/dotty/issues/13568 and could probably be fixed by replacing the anonymous inner classes extending PreparedQuery for example.

armanbilge commented 1 year ago

The problem is lampepfl/dotty#13568 and could probably be fixed by replacing the anonymous inner classes extending PreparedQuery for example.

So if I'm understanding correctly, https://github.com/lampepfl/dotty/issues/13568 can cause Graal Native image to break? If so, that sounds like something that should be reported as an issue on the dotty repo.