(defn read-analysis-cache
([cache-file src]
(read-analysis-cache cache-file src nil))
([^File cache-file src opts]
;; we want want to keep dependency analysis information
;; don't revert the environment - David
(let [{:keys [ns]} (parse-ns src
(merge opts
{:restore false
:analyze-deps true
:load-macros true}))
ext (util/ext cache-file)
cached-ns (case ext
"edn" (edn/read-string (slurp cache-file))
"json" (let [{:keys [reader read]} @transit]
(with-open [is (io/input-stream cache-file)]
(read (reader is :json transit-read-opts)))))]
(when (or *verbose* (:verbose opts))
(util/debug-prn "Reading analysis cache for" (str src)))
(swap! env/*compiler*
(fn [cenv]
(do
(register-specs cached-ns)
(doseq [x (get-in cached-ns [::constants :order])]
(register-constant! x))
(-> cenv
(assoc-in [::namespaces ns] cached-ns))))))))