Skip to content

Commit 7c140be

Browse files
committed
change ^:const inlining to be less dramatic of a change, only
inline values which are obviously constant
1 parent a399958 commit 7c140be

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
(def ^:dynamic *load-macros* true)
5454
(def ^:dynamic *reload-macros* false)
5555
(def ^:dynamic *macro-infer* true)
56-
56+
(def ^:dynamic *passes* nil)
5757
(def ^:dynamic *file-defs* nil)
5858

5959
(def constants-ns-sym
@@ -1289,6 +1289,15 @@
12891289
(defn valid-proto [x]
12901290
(when (symbol? x) x))
12911291

1292+
(defn elide-env [env ast opts]
1293+
(dissoc ast :env))
1294+
1295+
(defn constant-value?
1296+
[{:keys [op] :as ast}]
1297+
(or (= :constant op)
1298+
(and (#{:map :set :vector :list} op)
1299+
(every? constant-value? (:children ast)))))
1300+
12921301
(defmethod parse 'def
12931302
[op env form _ _]
12941303
(when (> (count form) 4)
@@ -1383,7 +1392,11 @@
13831392
f))))}
13841393
(when doc {:doc doc})
13851394
(when const?
1386-
{:const-init (:init args)})
1395+
(let [const-expr
1396+
(binding [*passes* (conj *passes* elide-env)]
1397+
(analyze env (:init args)))]
1398+
(when (constant-value? const-expr)
1399+
{:const-expr const-expr})))
13871400
(when (true? dynamic) {:dynamic true})
13881401
(source-info var-name env)
13891402
;; the protocol a protocol fn belongs to
@@ -2919,8 +2932,8 @@
29192932
(if-not (true? (:def-var env))
29202933
(merge
29212934
(assoc ret :op :var :info info)
2922-
(when-let [const-init (:const-init info)]
2923-
{:const-expr (analyze env const-init)}))
2935+
(when-let [const-expr (:const-expr info)]
2936+
{:const-expr const-expr}))
29242937
(let [info (resolve-var env sym)]
29252938
(assoc ret :op :var :info info))))))))
29262939

@@ -3202,8 +3215,6 @@
32023215
ast)))
32033216
ast)))
32043217

3205-
(def ^:dynamic *passes* nil)
3206-
32073218
#?(:clj
32083219
(defn analyze-form [env form name opts]
32093220
(load-core)

0 commit comments

Comments
 (0)