Skip to content

Commit fce34e0

Browse files
committed
CLJ version checks before require
1 parent 521e077 commit fce34e0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/main/clojure/clojure/core/async.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ IOC and vthread code.
8383
[java.util.concurrent ThreadLocalRandom]
8484
[java.util Arrays ArrayList]))
8585

86+
(when (not dispatch/lazy-loading-supported?)
87+
(require 'clojure.core.async.impl.go))
88+
8689
(alias 'core 'clojure.core)
8790

8891
(set! *warn-on-reflection* false)
@@ -512,8 +515,9 @@ IOC and vthread code.
512515
(when ret @ret)))
513516

514517
(defn- dynamic-require [nsym]
515-
(dispatch/ensure-clojure-version! 1 12 3)
516-
(require nsym))
518+
(when (and dispatch/lazy-loading-supported?
519+
(not (contains? @@#'clojure.core/*loaded-libs* nsym)))
520+
(#'clojure.core/serialized-require nsym)))
517521

518522
(defn- go* [body env]
519523
(cond (and (not dispatch/virtual-threads-available?)

src/main/clojure/clojure/core/async/impl/dispatch.clj

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@
7373
[workload]
7474
(Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workload) "-%d") true)))
7575

76-
(def ensure-clojure-version!
77-
(memoize
78-
(fn [maj min incr]
79-
(let [{:keys [major minor incremental]} *clojure-version*]
80-
(when (neg? (compare [major minor incremental] [maj min incr]))
81-
(throw (ex-info (str "core.async go block expander requires Clojure version ≥"
82-
maj "." min "." incr
83-
" to load")
84-
{:clojure-version *clojure-version*})))))))
76+
(defn at-least-clojure-version?
77+
[[maj min incr]]
78+
(let [{:keys [major minor incremental]} *clojure-version*]
79+
(not (neg? (compare [major minor incremental] [maj min incr])))))
80+
81+
(def lazy-loading-supported? (at-least-clojure-version? [1 12 3]))
8582

8683
(def virtual-threads-available?
8784
(try

0 commit comments

Comments
 (0)