|
3561 | 3561 | (write-analysis-cache ns cache-file nil))
|
3562 | 3562 | ([ns ^File cache-file src]
|
3563 | 3563 | (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)))) |
3564 | 3569 | (let [ext (util/ext cache-file)
|
3565 | 3570 | analysis (dissoc (get-in @env/*compiler* [::namespaces ns]) :macros)]
|
3566 | 3571 | (case ext
|
|
3576 | 3581 | (when src
|
3577 | 3582 | (.setLastModified ^File cache-file (util/last-modified src))))))
|
3578 | 3583 |
|
| 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 | + |
3579 | 3619 | (defn analyze-form-seq
|
3580 | 3620 | ([forms]
|
3581 | 3621 | (analyze-form-seq forms
|
|
3659 | 3699 | (when (and cache (true? (:cache-analysis opts)))
|
3660 | 3700 | (write-analysis-cache ns cache res))))
|
3661 | 3701 | (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) |
3684 | 3703 | (catch Throwable e
|
3685 | 3704 | (analyze-file f true opts))))))))))))
|
0 commit comments