|
3555 | 3555 | true
|
3556 | 3556 | (util/changed? src cache)))))))
|
3557 | 3557 |
|
| 3558 | +#?(:clj |
| 3559 | + (defn- get-speced-vars |
| 3560 | + [] |
| 3561 | + (when-let [spec-ns (find-ns 'cljs.spec.alpha)] |
| 3562 | + (ns-resolve spec-ns '_speced_vars))) |
| 3563 | + :cljs |
| 3564 | + ;; Here, we look up the symbol '-speced-vars because ns-interns* |
| 3565 | + ;; is implemented by invoking demunge on the result of js-keys. |
| 3566 | + (let [cached-var (delay (get (ns-interns* 'cljs.spec.alpha$macros) '-speced-vars))] |
| 3567 | + (defn- get-speced-vars [] |
| 3568 | + (when (some? (find-ns-obj 'cljs.spec.alpha$macros)) |
| 3569 | + @cached-var)))) |
| 3570 | + |
| 3571 | +(defn dump-speced-vars-to-env |
| 3572 | + "Dumps registered speced vars for a given namespace into the compiler |
| 3573 | + environment." |
| 3574 | + [ns] |
| 3575 | + (when-let [speced-vars (get-speced-vars)] |
| 3576 | + (let [ns-str (str ns)] |
| 3577 | + (swap! env/*compiler* update-in [::namespaces ns :cljs.spec/speced-vars] |
| 3578 | + (fnil into #{}) (filter #(= ns-str (namespace %))) @@speced-vars)))) |
| 3579 | + |
| 3580 | +(defn register-cached-speced-vars |
| 3581 | + "Registers speced vars found in a namespace analysis cache." |
| 3582 | + [cached-ns] |
| 3583 | + (when-let [vars (seq (:cljs.spec/speced-vars cached-ns))] |
| 3584 | + #?(:clj (try |
| 3585 | + (require 'cljs.spec.alpha) |
| 3586 | + (catch Throwable t))) |
| 3587 | + (when-let [speced-vars (get-speced-vars)] |
| 3588 | + (swap! @speced-vars into vars)))) |
| 3589 | + |
3558 | 3590 | #?(:clj
|
3559 | 3591 | (defn write-analysis-cache
|
3560 | 3592 | ([ns cache-file]
|
3561 | 3593 | (write-analysis-cache ns cache-file nil))
|
3562 | 3594 | ([ns ^File cache-file src]
|
3563 | 3595 | (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)))) |
| 3596 | + (dump-speced-vars-to-env ns) |
3569 | 3597 | (let [ext (util/ext cache-file)
|
3570 | 3598 | analysis (dissoc (get-in @env/*compiler* [::namespaces ns]) :macros)]
|
3571 | 3599 | (case ext
|
|
3604 | 3632 | (swap! env/*compiler*
|
3605 | 3633 | (fn [cenv]
|
3606 | 3634 | (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)))) |
| 3635 | + (register-cached-speced-vars cached-ns) |
3614 | 3636 | (doseq [x (get-in cached-ns [::constants :order])]
|
3615 | 3637 | (register-constant! x))
|
3616 | 3638 | (-> cenv
|
|
0 commit comments