Fork me on GitHub
#clara
<
2020-05-30
>
narkisr17:05:36

Hi Clara team, iv been trying to use Clara rules within a graalvm native image and iv managed to compile it however its failing during runtime on the use of eval, is there an option iv missed to not use eval? (compile the rules ahead of time) https://github.com/cerner/clara-rules/blob/master/src/main/clojure/clara/rules/compiler.clj#L223

[{:type clojure.lang.ExceptionInfo
   :message Failed compiling alpha node
{:expr (clojure.core/fn [?__fact__ ?__env__] (clojure.core/let [{:keys [?wildcard]} ?__fact__ ?__bindings__ (clojure.core/atom {:?e ?__fact__})] (clojure.core/let [?wildcard true] (clojure.core/swap! ?__bindings__ clojure.core/assoc :?wildcard ?wildcard) (clojure.core/deref ?__bindings__)))), :condition {:type :grant.rules/user-spec, :constraints [(= ?wildcard true)], :args [{:keys [?wildcard]}], :fact-binding :?e}, :env nil}

   :data {:expr (clojure.core/fn [?__fact__ ?__env__] (clojure.core/let [{:keys [?wildcard]} ?__fact__ ?__bindings__ (clojure.core/atom {:?e ?__fact__})] (clojure.core/let [?wildcard true] (clojure.core/swap! ?__bindings__ clojure.core/assoc :?wildcard ?wildcard) (clojure.core/deref ?__bindings__)))), :condition {:type :grant.rules/user-spec, :constraints [(= ?wildcard true)], :args [{:keys [?wildcard]}], :fact-binding :?e}, :env nil}
   :at [clara.rules.compiler$try_eval invokeStatic compiler.clj 238]}
  {:type clojure.lang.Compiler$CompilerException
   :message Syntax error compiling at (grant/rules.clj:15:0).
   :data {:clojure.error/phase :compile-syntax-check, :clojure.error/line 15, :clojure.error/column 0, :clojure.error/source grant/rules.clj}
   :at [clojure.lang.Compiler analyzeSeq Compiler.java 7115]}
  {:type java.lang.ClassNotFoundException
   :message clojure.lang.PersistentHashMap
   :at [com.oracle.svm.core.hub.ClassForNameSupport forName ClassForNameSupport.java 60]}]
 :trace
 [[com.oracle.svm.core.hub.ClassForNameSupport forName ClassForNameSupport.java 60]
  [java.lang.Class forName DynamicHub.java 1207]
  [clojure.lang.RT classForName RT.java 2211]
  [clojure.lang.RT classForNameNonLoading RT.java 2224]
  [clojure.lang.Compiler$HostExpr maybeClass Compiler.java 1041]
  [clojure.lang.Compiler macroexpand1 Compiler.java 7045]
  [clojure.lang.Compiler analyzeSeq Compiler.java 7093]

ethanc18:05:54

@narkisr Currently there is no such flag to disable eval, that mainly comes down to the fact that we have to evaluate user provided functions(RHS) and generated functions from the LHS of rules on the fly. Otherwise the forms produced by larger sessions would likely exceed some of the constraints of generated code sizes set by java. I am curious as to the use-case, are you AOT compiling the sessions themselves or are you trying to generate the sessions during runtime? I know @mikerod has been trying to untangle eval from rule compilation, but i believe that has been focused on Cljs as clara has been doing that wrong.

mikerod18:05:05

Cljs is closer to meeting that sort of requirement. The clj impl would not be easy to make happen. Unless it also went through a macro expansion type cljs like flow. Then again. I don’t even know exactly the constraints we’d have to use graal for this

mikerod18:05:55

I’m guessing if macros could expand to code that avoided any eval and all fn instantiations were done via the compiler directly from the expanded code it’d work. Which is basically what cljs has to do

mikerod18:05:15

But only my current side branch of cljs at the moment. And it’s not functional yet.