alpha-asp / Alpha

A lazy-grounding Answer-Set Programming system
BSD 2-Clause "Simplified" License
58 stars 10 forks source link

Native Image #330

Open lorenzleutgeb opened 2 years ago

lorenzleutgeb commented 2 years ago

Add support for compiling Alpha to ELF x86_64 executables.

https://github.com/alpha-asp/Alpha/runs/4579874459?check_suite_focus=true#step:8:1

codecov[bot] commented 2 years ago

Codecov Report

Merging #330 (6366e79) into master (d42818a) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #330   +/-   ##
=========================================
  Coverage     70.23%   70.23%           
  Complexity     2123     2123           
=========================================
  Files           182      182           
  Lines          8023     8023           
  Branches       1423     1423           
=========================================
  Hits           5635     5635           
  Misses         2028     2028           
  Partials        360      360           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d42818a...6366e79. Read the comment docs.

AntoniusW commented 2 years ago

Is that really what I think it is, do we have a native binary of Alpha now? :-D

lorenzleutgeb commented 2 years ago

As discussed, there's currently a problem with resources being included. The stringtemplate resources are missing from the created image, therefore all attempts to solve programs end with a NullPointerException.

Should be resolved now, see https://github.com/alpha-asp/Alpha/runs/4585139250?check_suite_focus=true#step:9:14

Is that really what I think it is, do we have a native binary of Alpha now? :-D

Yep. But even merging this PR, it will need further testing, and quite possibly a few more tweaks (especially regarding Reflection and Resources). So consider it an "experimental feature". We're getting there.

lorenzleutgeb commented 2 years ago

I looked through the code in question and GraalVM docs and found the following: The error occurs because Externals#getStandardLibraryExternals returns an empty map. This happens because Reflections#scan does not find any annotated methods in the classpath (see line 179 of Reflections.java in `reflections-0.9.11.jar). This is consistent with the limitations of native images described here:

Any class to be accessed by name at image run time must be enumerated at image build time. For example, a call to Class.forName("myClass”) must have myClass in a configuration file.

I think to fix the issue it hand it should suffice to add AspStandardLibrary to the native-image configuration as described here.

Yes, reflection needs additional configuration to work with Native Image, I hinted that in https://github.com/alpha-asp/Alpha/pull/330#issuecomment-998025027. Probably should have been more explicit...

Note that this raises a bigger issue: With alpha being compiled to a native binary, using user-supplied externals can't work the way it currently does anymore - Since class-loading doesn't happen the way we're used to, discovery of things on the cluasspath during runtime won't work. Personally, I don't think we should treat this as a showstopper - The user-supplied externals case is more likely to occur in settings where Alpha is used as a part of a larger Java application, but [...]

Yes. Externals in Java won't work in the native image. I view the native image as a "conventional" ASP system, lacking externals.

[...] I think we should keep it in mind and think about possible alternatives.

True, but let's not just allow linking against arbitrary shared objects that supply implementations for externals...