Skip to content

Commit f119f65

Browse files
author
dnolen
committed
CLJS-1989: s/fdef expansion side effect fails when load cached source
lift analysis cache reading into a helper. Handle writing out spec vars in write-analysis-cache and read-analysis-cache.
1 parent 18f580c commit f119f65

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,11 @@
35613561
(write-analysis-cache ns cache-file nil))
35623562
([ns ^File cache-file src]
35633563
(util/mkdirs cache-file)
3564+
(when-let [spec-ns (find-ns 'cljs.spec.alpha)]
3565+
(when-let [speced-vars (ns-resolve spec-ns '_speced_vars)]
3566+
(let [ns-str (str ns)]
3567+
(swap! env/*compiler* update-in [::namespaces ns :cljs.spec/speced-vars]
3568+
(fnil into #{}) (filter #(= ns-str (namespace %))) @@speced-vars))))
35643569
(let [ext (util/ext cache-file)
35653570
analysis (dissoc (get-in @env/*compiler* [::namespaces ns]) :macros)]
35663571
(case ext
@@ -3576,6 +3581,41 @@
35763581
(when src
35773582
(.setLastModified ^File cache-file (util/last-modified src))))))
35783583

3584+
#?(:clj
3585+
(defn read-analysis-cache
3586+
([cache-file src]
3587+
(read-analysis-cache cache-file src nil))
3588+
([^File cache-file src opts]
3589+
;; we want want to keep dependency analysis information
3590+
;; don't revert the environment - David
3591+
(let [{:keys [ns]} (parse-ns src
3592+
(merge opts
3593+
{:restore false
3594+
:analyze-deps true
3595+
:load-macros true}))
3596+
ext (util/ext cache-file)
3597+
cached-ns (case ext
3598+
"edn" (edn/read-string (slurp cache-file))
3599+
"json" (let [{:keys [reader read]} @transit]
3600+
(with-open [is (io/input-stream cache-file)]
3601+
(read (reader is :json transit-read-opts)))))]
3602+
(when (or *verbose* (:verbose opts))
3603+
(util/debug-prn "Reading analysis cache for" (str src)))
3604+
(swap! env/*compiler*
3605+
(fn [cenv]
3606+
(do
3607+
(when-let [vars (seq (:cljs.spec/speced-vars cached-ns))]
3608+
(try
3609+
(require 'cljs.spec.alpha)
3610+
(catch Throwable t))
3611+
(when-let [spec-ns (find-ns 'cljs.spec.alpha)]
3612+
(when-let [speced-vars (ns-resolve spec-ns '_speced_vars)]
3613+
(swap! @speced-vars into vars))))
3614+
(doseq [x (get-in cached-ns [::constants :order])]
3615+
(register-constant! x))
3616+
(-> cenv
3617+
(assoc-in [::namespaces ns] cached-ns)))))))))
3618+
35793619
(defn analyze-form-seq
35803620
([forms]
35813621
(analyze-form-seq forms
@@ -3659,27 +3699,6 @@
36593699
(when (and cache (true? (:cache-analysis opts)))
36603700
(write-analysis-cache ns cache res))))
36613701
(try
3662-
;; we want want to keep dependency analysis information
3663-
;; don't revert the environment - David
3664-
(let [{:keys [ns]} (parse-ns res
3665-
(merge opts
3666-
{:restore false
3667-
:analyze-deps true
3668-
:load-macros true}))
3669-
ext (util/ext cache)
3670-
cached-ns (case ext
3671-
"edn" (edn/read-string (slurp cache))
3672-
"json" (let [{:keys [reader read]} @transit]
3673-
(with-open [is (io/input-stream cache)]
3674-
(read (reader is :json transit-read-opts)))))]
3675-
(when (or *verbose* (:verbose opts))
3676-
(util/debug-prn "Reading analysis cache for" (str res)))
3677-
(swap! env/*compiler*
3678-
(fn [cenv]
3679-
(let []
3680-
(doseq [x (get-in cached-ns [::constants :order])]
3681-
(register-constant! x))
3682-
(-> cenv
3683-
(assoc-in [::namespaces ns] cached-ns))))))
3702+
(read-analysis-cache cache res opts)
36843703
(catch Throwable e
36853704
(analyze-file f true opts))))))))))))

0 commit comments

Comments
 (0)