nextjournal / clerk

⚡️ Moldable Live Programming for Clojure
https://clerk.vision
ISC License
1.82k stars 78 forks source link

Emmy static build fails when including certain namespaces #455

Open sritchie opened 1 year ago

sritchie commented 1 year ago

In https://github.com/mentat-collective/emmy

Uncommenting any of these files: https://github.com/mentat-collective/emmy/blob/main/dev/user.clj#L42-L48

and running

bb build-static

causes errors like this:

{:clojure.main/message
 "Execution error (ExceptionInfo) at nextjournal.clerk.eval/eval+cache! (eval.clj:150).\nExecution error (IllegalArgumentException) at emmy.expression.analyze/eval76525$fn$G (analyze.cljc:135).\nNo implementation of method: :known-operation? of protocol: #'emmy.expression.analyze/ICanonicalize found for class: emmy.rational_function$reify__45179\n\n",
 :clojure.main/triage
 {:clojure.error/class clojure.lang.ExceptionInfo,
  :clojure.error/line 150,
  :clojure.error/cause
  "Execution error (IllegalArgumentException) at emmy.expression.analyze/eval76525$fn$G (analyze.cljc:135).\nNo implementation of method: :known-operation? of protocol: #'emmy.expression.analyze/ICanonicalize found for class: emmy.rational_function$reify__45179\n",
  :clojure.error/symbol nextjournal.clerk.eval/eval+cache!,
  :clojure.error/source "eval.clj",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.ExceptionInfo,
    :message
    "Execution error (IllegalArgumentException) at emmy.expression.analyze/eval76525$fn$G (analyze.cljc:135).\nNo implementation of method: :known-operation? of protocol: #'emmy.expression.analyze/ICanonicalize found for class: emmy.rational_function$reify__45179\n",
    :data
    {:clojure.error/cause
     "No implementation of method: :known-operation? of protocol: #'emmy.expression.analyze/ICanonicalize found for class: emmy.rational_function$reify__45179",
     :clojure.error/phase :execution,
     :clojure.error/symbol emmy.expression.analyze/eval76525$fn$G,
     :clojure.error/line 135,
     :clojure.error/class java.lang.IllegalArgumentException,
     :clojure.error/source "analyze.cljc",
     :line 151,
     :col 1,
     :clojure.core/eval-file "dev/emmy/notebook.clj",
     :form
     (let
      [expr (+ (square (sin 'x)) (square (cos 'x)))]
      (render [expr (simplify expr)]))},
    :at
    [nextjournal.clerk.eval$eval_PLUS_cache_BANG_
     invokeStatic
     "eval.clj"
     150]}],
  :trace
  [[nextjournal.clerk.eval$eval_PLUS_cache_BANG_
    invokeStatic
    "eval.clj"
    150]
   [nextjournal.clerk.eval$eval_PLUS_cache_BANG_ invoke "eval.clj" 122]
   [nextjournal.clerk.eval$read_PLUS_eval_cached
    invokeStatic
    "eval.clj"
    189]
   [nextjournal.clerk.eval$read_PLUS_eval_cached invoke "eval.clj" 160]
   [nextjournal.clerk.eval$eval_analyzed_doc$fn__15098
    invoke
    "eval.clj"
    229]
   [clojure.lang.PersistentVector reduce "PersistentVector.java" 343]
   [clojure.core$reduce invokeStatic "core.clj" 6885]
   [clojure.core$reduce invoke "core.clj" 6868]
   [nextjournal.clerk.eval$eval_analyzed_doc
    invokeStatic
    "eval.clj"
    224]
   [nextjournal.clerk.eval$eval_analyzed_doc invoke "eval.clj" 221]
   [nextjournal.clerk.builder$build_static_app_BANG_$fn__17458$fn__17461$fn__17462
    invoke
    "builder.clj"
    324]
   [nextjournal.clerk.builder$build_static_app_BANG_$fn__17458$fn__17461
    invoke
    "builder.clj"
    323]
   [nextjournal.clerk.builder$build_static_app_BANG_$fn__17458
    invoke
    "builder.clj"
    322]
   [clojure.core$map$fn__5939 invoke "core.clj" 2777]
   [clojure.lang.LazySeq sval "LazySeq.java" 42]
   [clojure.lang.LazySeq seq "LazySeq.java" 51]
   [clojure.lang.Cons next "Cons.java" 39]
   [clojure.lang.RT next "RT.java" 713]
   [clojure.core$next__5451 invokeStatic "core.clj" 64]
   [clojure.core.protocols$fn__8249 invokeStatic "protocols.clj" 169]
   [clojure.core.protocols$fn__8249 invoke "protocols.clj" 124]
   [clojure.core.protocols$fn__8204$G__8199__8213
    invoke
    "protocols.clj"
    19]
   [clojure.core.protocols$seq_reduce invokeStatic "protocols.clj" 31]
   [clojure.core.protocols$fn__8236 invokeStatic "protocols.clj" 75]
   [clojure.core.protocols$fn__8236 invoke "protocols.clj" 75]
   [clojure.core.protocols$fn__8178$G__8173__8191
    invoke
    "protocols.clj"
    13]
   [clojure.core$reduce invokeStatic "core.clj" 6886]
   [clojure.core$into invokeStatic "core.clj" 6958]
   [clojure.core$mapv invokeStatic "core.clj" 6970]
   [clojure.core$mapv invoke "core.clj" 6970]
   [nextjournal.clerk.builder$build_static_app_BANG_
    invokeStatic
    "builder.clj"
    319]
   [nextjournal.clerk.builder$build_static_app_BANG_
    invoke
    "builder.clj"
    292]
   [nextjournal.clerk$build_BANG_ invokeStatic "clerk.clj" 508]
   [nextjournal.clerk$build_BANG_ invoke "clerk.clj" 466]
   [mentat.clerk_utils.build$build_BANG_$fn__34159
    invoke
    "build.clj"
    121]
   [clojure.lang.Delay deref "Delay.java" 42]
   [clojure.core$deref invokeStatic "core.clj" 2337]
   [clojure.core$deref invoke "core.clj" 2323]
   [mentat.clerk_utils.build$build_BANG_ invokeStatic "build.clj" 126]
   [mentat.clerk_utils.build$build_BANG_ invoke "build.clj" 97]
   [user$build_BANG_ invokeStatic "user.clj" 76]
   [user$build_BANG_ invoke "user.clj" 75]
   [clojure.lang.AFn applyToHelper "AFn.java" 154]
   [clojure.lang.AFn applyTo "AFn.java" 144]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.core$apply invoke "core.clj" 662]
   [clojure.run.exec$exec invokeStatic "exec.clj" 48]
   [clojure.run.exec$exec doInvoke "exec.clj" 39]
   [clojure.lang.RestFn invoke "RestFn.java" 423]
   [clojure.run.exec$_main$fn__57294 invoke "exec.clj" 180]
   [clojure.run.exec$_main invokeStatic "exec.clj" 176]
   [clojure.run.exec$_main doInvoke "exec.clj" 139]
   [clojure.lang.RestFn invoke "RestFn.java" 397]
   [clojure.lang.AFn applyToHelper "AFn.java" 152]
   [clojure.lang.RestFn applyTo "RestFn.java" 132]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause
  "Execution error (IllegalArgumentException) at emmy.expression.analyze/eval76525$fn$G (analyze.cljc:135).\nNo implementation of method: :known-operation? of protocol: #'emmy.expression.analyze/ICanonicalize found for class: emmy.rational_function$reify__45179\n",
  :data
  {:clojure.error/cause
   "No implementation of method: :known-operation? of protocol: #'emmy.expression.analyze/ICanonicalize found for class: emmy.rational_function$reify__45179",
   :clojure.error/phase :execution,
   :clojure.error/symbol emmy.expression.analyze/eval76525$fn$G,
   :clojure.error/line 135,
   :clojure.error/class java.lang.IllegalArgumentException,
   :clojure.error/source "analyze.cljc",
   :line 151,
   :col 1,
   :clojure.core/eval-file "dev/emmy/notebook.clj",
   :form
   (let
    [expr (+ (square (sin 'x)) (square (cos 'x)))]
    (render [expr (simplify expr)]))},
  :phase :execution}}

Each namespace triggers different errors, but they all seem to come from Clerk redefining a deftype during analysis and breaking the type-based dispatch inside the library.

Here is a Slack thread: https://nextjournal.slack.com/archives/C022KRVLAC9/p1681840549227219

phronmophobic commented 8 months ago

I'm also running into this issue, but don't currently have a reproduction that's easy to share. I also don't have access to the nextjournal slack. Is there a workaround available?

phronmophobic commented 8 months ago

Here is a repro: https://github.com/phronmophobic/llama.clj/actions/runs/8253925607/job/22576887992

error.txt