Fork me on GitHub

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)

[{: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 7115]}
  {:type java.lang.ClassNotFoundException
   :message clojure.lang.PersistentHashMap
   :at [ forName 60]}]
 [[ forName 60]
  [java.lang.Class forName 1207]
  [clojure.lang.RT classForName 2211]
  [clojure.lang.RT classForNameNonLoading 2224]
  [clojure.lang.Compiler$HostExpr maybeClass 1041]
  [clojure.lang.Compiler macroexpand1 7045]
  [clojure.lang.Compiler analyzeSeq 7093]


@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.


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


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


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