Skip to content

Commit 592d28a

Browse files
committed
CLJS-978: Analysis caching doesn't account for constants table
`cljs.analyzer/register-constant!` now takes an optional analysis `env`. If supplied will use the current ns to add this to the `:cljs.analyzer/constants` set for the namespace. when reading analysis cache off disk in `cljs.analyzer/analyze-file` add all constants in `:cljs.analyzer/constants` back to the compilation environment via `cljs.analyzer/register-constant!`
1 parent 53f55da commit 592d28a

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,20 @@
204204
(Exception. (str "constant type " (type value) " not supported"))))]
205205
(symbol (str prefix (swap! constant-counter inc)))))
206206

207-
(defn- register-constant! [val]
208-
(swap! env/*compiler* update-in [::constant-table]
209-
(fn [table]
210-
(if (get table val)
211-
table
212-
(assoc table val (gen-constant-id val))))))
207+
(defn- register-constant!
208+
([val] (register-constant! nil val))
209+
([env val]
210+
(swap! env/*compiler*
211+
(fn [cenv]
212+
(cond->
213+
(-> cenv
214+
(update-in [::constant-table]
215+
(fn [table]
216+
(if (get table val)
217+
table
218+
(assoc table val (gen-constant-id val))))))
219+
env (update-in [::namespaces (-> env :ns :name) ::constants]
220+
(fnil conj #{}) val))))))
213221

214222
(def default-namespaces '{cljs.core {:name cljs.core}
215223
cljs.user {:name cljs.user}})
@@ -469,7 +477,7 @@
469477
;; TODO: move this logic out - David
470478
(defn analyze-keyword
471479
[env sym]
472-
(register-constant! sym)
480+
(register-constant! env sym)
473481
{:op :constant :env env :form sym :tag 'cljs.core/Keyword})
474482

475483
(defn get-tag [e]
@@ -1994,7 +2002,11 @@ argument, which the reader will use in any emitted errors."
19942002
:load-macros true}))]
19952003
(when (or *verbose* (:verbose opts))
19962004
(util/debug-prn "Reading analysis cache for " res))
1997-
(swap! env/*compiler* assoc-in [::analyzed-cljs path] true)
1998-
(swap! env/*compiler* assoc-in [::namespaces ns]
1999-
(edn/read-string (slurp cache))))))))))))
2000-
2005+
(swap! env/*compiler*
2006+
(fn [cenv]
2007+
(let [cached-ns (edn/read-string (slurp cache))]
2008+
(doseq [x (::constants cached-ns)]
2009+
(register-constant! x))
2010+
(-> cenv
2011+
(assoc-in [::analyzed-cljs path] true)
2012+
(assoc-in [::namespaces ns] cached-ns))))))))))))))

0 commit comments

Comments
 (0)