|
3556 | 3556 | (util/changed? src cache)))))))
|
3557 | 3557 |
|
3558 | 3558 | #?(:clj
|
3559 |
| - (defn- get-speced-vars |
| 3559 | + (defn- get-spec-vars |
3560 | 3560 | []
|
3561 | 3561 | (when-let [spec-ns (find-ns 'cljs.spec.alpha)]
|
3562 |
| - (ns-resolve spec-ns '_speced_vars))) |
| 3562 | + {:registry-ref (ns-resolve spec-ns 'registry-ref) |
| 3563 | + :speced-vars (ns-resolve spec-ns '_speced_vars)})) |
3563 | 3564 | :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 [] |
| 3565 | + (let [registry-ref (delay (get (ns-interns* 'cljs.spec.alpha$macros) 'registry-ref)) |
| 3566 | + ;; Here, we look up the symbol '-speced-vars because ns-interns* |
| 3567 | + ;; is implemented by invoking demunge on the result of js-keys. |
| 3568 | + speced-vars (delay (get (ns-interns* 'cljs.spec.alpha$macros) '-speced-vars))] |
| 3569 | + (defn- get-spec-vars [] |
3568 | 3570 | (when (some? (find-ns-obj 'cljs.spec.alpha$macros))
|
3569 |
| - @cached-var)))) |
| 3571 | + {:registry-ref @registry-ref |
| 3572 | + :speced-vars @speced-vars})))) |
3570 | 3573 |
|
3571 | 3574 | (defn dump-specs
|
3572 | 3575 | "Dumps registered speced vars for a given namespace into the compiler
|
3573 | 3576 | environment."
|
3574 | 3577 | [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)))) |
| 3578 | + (let [spec-vars (get-spec-vars) |
| 3579 | + ns-str (str ns)] |
| 3580 | + (swap! env/*compiler* update-in [::namespaces ns] |
| 3581 | + merge |
| 3582 | + (when-let [registry-ref (:registry-ref spec-vars)] |
| 3583 | + {:cljs.spec/registry-ref (into [] (filter (fn [[k _]] (= ns-str (namespace k)))) @@registry-ref)}) |
| 3584 | + (when-let [speced-vars (:speced-vars spec-vars)] |
| 3585 | + {:cljs.spec/speced-vars (into [] (filter #(= ns-str (namespace %))) @@speced-vars)})))) |
3579 | 3586 |
|
3580 | 3587 | (defn register-specs
|
3581 | 3588 | "Registers speced vars found in a namespace analysis cache."
|
3582 | 3589 | [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)))) |
| 3590 | + #?(:clj (try |
| 3591 | + (require 'cljs.spec.alpha) |
| 3592 | + (catch Throwable t))) |
| 3593 | + (let [{:keys [registry-ref speced-vars]} (get-spec-vars)] |
| 3594 | + (when-let [registry (seq (:cljs.spec/registry-ref cached-ns))] |
| 3595 | + (when registry-ref |
| 3596 | + (swap! @registry-ref merge registry))) |
| 3597 | + (when-let [vars (seq (:cljs.spec/speced-vars cached-ns))] |
| 3598 | + (when speced-vars |
| 3599 | + (swap! @speced-vars into vars))))) |
3589 | 3600 |
|
3590 | 3601 | #?(:clj
|
3591 | 3602 | (defn write-analysis-cache
|
|
0 commit comments