Skip to content

Commit f4c5488

Browse files
authored
Analyzer improvements (#751)
Remove unused cljs branches and improve performance. Also fixes #497.
1 parent 749cfa5 commit f4c5488

File tree

3 files changed

+83
-237
lines changed

3 files changed

+83
-237
lines changed

src/nextjournal/clerk/analyzer.clj

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,6 @@
4949

5050
#_(sha1-base58 "hello")
5151

52-
(defn ^:private ensure-symbol [class-or-sym]
53-
(cond
54-
(symbol? class-or-sym) class-or-sym
55-
(class? class-or-sym) (symbol (pr-str class-or-sym))
56-
:else (throw (ex-info "not a symbol or a class" {:class-or-sym class-or-sym} (IllegalArgumentException.)))))
57-
58-
(defn class-deps [analyzed]
59-
(set/union (into #{}
60-
(comp (keep :class)
61-
(filter class?)
62-
(map ensure-symbol))
63-
(ana/nodes analyzed))
64-
(into #{}
65-
(comp (filter (comp #{:const} :op))
66-
(filter (comp #{:class} :type))
67-
(keep :form)
68-
(map ensure-symbol))
69-
(ana/nodes analyzed))))
70-
7152
#_(map type (:deps (analyze '(+ 1 2))))
7253

7354
(defn rewrite-defcached [form]
@@ -101,9 +82,7 @@
10182
(defn analyze-form [form]
10283
(with-bindings {clojure.lang.Compiler/LOADER (clojure.lang.RT/makeClassLoader)}
10384
(binding [ana/*deps* (or ana/*deps* (atom #{}))]
104-
(-> (analyze-form* (rewrite-defcached form))
105-
(ana/resolve-syms-pass)
106-
(ana/macroexpand-pass)))))
85+
(analyze-form* (rewrite-defcached form)))))
10786

10887
(defn ^:private var->protocol [v]
10988
(or (:protocol (meta v))
@@ -165,13 +144,12 @@
165144
(keep #(-> % :args first))
166145
(filter :var)
167146
(keep (fn [{:keys [op var]}]
168-
(when-not (= op :the-var)
147+
(when-not (= :the-var op)
169148
(list `deref (symbol var))))))
170149
nodes)
171150
;; TODO: check case '(def a (inc a)) deps are empty for this which is wrong
172151
deps (set/union (set/difference (into #{} (map (comp symbol var->protocol)) @!deps) vars)
173152
deref-deps
174-
(class-deps analyzed)
175153
(when (var? form) #{(symbol form)}))
176154
hash-fn (-> form meta :nextjournal.clerk/hash-fn)]
177155
(cond-> {#_#_:analyzed analyzed

0 commit comments

Comments
 (0)