Skip to content

Commit a93ac96

Browse files
committed
CLJS-2541: binding not made in parallel
1 parent 04e6bd9 commit a93ac96

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
lines changed

src/main/cljs/cljs/js.cljs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@
184184
(.fromCharCode js/String (str "0x" match))))
185185
(base64/encodeString))))))
186186

187-
(defn- current-alias-map
188-
[]
189-
(->> (merge (get-in @env/*compiler* [::ana/namespaces ana/*cljs-ns* :requires])
190-
(get-in @env/*compiler* [::ana/namespaces ana/*cljs-ns* :require-macros]))
187+
(defn- alias-map
188+
[compiler cljs-ns]
189+
(->> (merge (get-in compiler [::ana/namespaces cljs-ns :requires])
190+
(get-in compiler [::ana/namespaces cljs-ns :require-macros]))
191191
(remove (fn [[k v]] (symbol-identical? k v)))
192192
(into {})))
193193

@@ -685,7 +685,7 @@
685685
ana/*fn-invoke-direct* (and (:static-fns opts) (:fn-invoke-direct opts))
686686
*ns* (create-ns ns)
687687
ana/*passes* (:*passes* bound-vars)
688-
r/*alias-map* (current-alias-map)
688+
r/*alias-map* (alias-map @(:*compiler* bound-vars) ns)
689689
r/*data-readers* (:*data-readers* bound-vars)
690690
r/resolve-symbol resolve-symbol
691691
comp/*source-map-data* (:*sm-data* bound-vars)
@@ -801,7 +801,7 @@
801801
ana/*cljs-static-fns* (:static-fns opts)
802802
ana/*fn-invoke-direct* (and (:static-fns opts) (:fn-invoke-direct opts))
803803
*ns* (create-ns (:*cljs-ns* bound-vars))
804-
r/*alias-map* (current-alias-map)
804+
r/*alias-map* (alias-map @(:*compiler* bound-vars) (:*cljs-ns* bound-vars))
805805
r/*data-readers* (:*data-readers* bound-vars)
806806
r/resolve-symbol resolve-symbol
807807
comp/*source-map-data* (:*sm-data* bound-vars)]
@@ -916,7 +916,7 @@
916916
ana/*cljs-static-fns* (:static-fns opts)
917917
ana/*fn-invoke-direct* (and (:static-fns opts) (:fn-invoke-direct opts))
918918
*ns* (create-ns ns)
919-
r/*alias-map* (current-alias-map)
919+
r/*alias-map* (alias-map @(:*compiler* bound-vars) ns)
920920
r/*data-readers* (:*data-readers* bound-vars)
921921
r/resolve-symbol resolve-symbol
922922
comp/*source-map-data* (:*sm-data* bound-vars)]
@@ -1051,7 +1051,7 @@
10511051
ana/*cljs-static-fns* (:static-fns opts)
10521052
ana/*fn-invoke-direct* (and (:static-fns opts) (:fn-invoke-direct opts))
10531053
*ns* (create-ns ns)
1054-
r/*alias-map* (current-alias-map)
1054+
r/*alias-map* (alias-map @(:*compiler* bound-vars) ns)
10551055
r/*data-readers* (:*data-readers* bound-vars)
10561056
r/resolve-symbol resolve-symbol
10571057
comp/*source-map-data* (:*sm-data* bound-vars)

src/main/cljs/cljs/pprint.cljs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,22 +3304,21 @@ type-map {"core$future_call" "Future",
33043304
in ks. If ks are not specified, use the keys of the first item in rows."
33053305
{:added "1.3"}
33063306
([ks rows]
3307-
(binding [*print-newline*]
3308-
(when (seq rows)
3309-
(let [widths (map
3310-
(fn [k]
3311-
(apply max (count (str k)) (map #(count (str (get % k))) rows)))
3312-
ks)
3313-
spacers (map #(apply str (repeat % "-")) widths)
3314-
fmt-row (fn [leader divider trailer row]
3315-
(str leader
3316-
(apply str (interpose divider
3317-
(for [[col width] (map vector (map #(get row %) ks) widths)]
3318-
(add-padding width (str col)))))
3319-
trailer))]
3320-
(cljs.core/println)
3321-
(cljs.core/println (fmt-row "| " " | " " |" (zipmap ks ks)))
3322-
(cljs.core/println (fmt-row "|-" "-+-" "-|" (zipmap ks spacers)))
3323-
(doseq [row rows]
3324-
(cljs.core/println (fmt-row "| " " | " " |" row)))))))
3307+
(when (seq rows)
3308+
(let [widths (map
3309+
(fn [k]
3310+
(apply max (count (str k)) (map #(count (str (get % k))) rows)))
3311+
ks)
3312+
spacers (map #(apply str (repeat % "-")) widths)
3313+
fmt-row (fn [leader divider trailer row]
3314+
(str leader
3315+
(apply str (interpose divider
3316+
(for [[col width] (map vector (map #(get row %) ks) widths)]
3317+
(add-padding width (str col)))))
3318+
trailer))]
3319+
(cljs.core/println)
3320+
(cljs.core/println (fmt-row "| " " | " " |" (zipmap ks ks)))
3321+
(cljs.core/println (fmt-row "|-" "-+-" "-|" (zipmap ks spacers)))
3322+
(doseq [row rows]
3323+
(cljs.core/println (fmt-row "| " " | " " |" row))))))
33253324
([rows] (print-table (keys (first rows)) rows)))

src/main/clojure/cljs/core.cljc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,11 +2160,13 @@
21602160
[bindings & body]
21612161
(core/let [names (take-nth 2 bindings)
21622162
vals (take-nth 2 (drop 1 bindings))
2163-
tempnames (map (comp gensym name) names)
2164-
binds (map core/vector names vals)
2165-
resets (reverse (map core/vector names tempnames))
2163+
orig-val-syms (map (comp gensym #(core/str % "-orig-val__") name) names)
2164+
temp-val-syms (map (comp gensym #(core/str % "-temp-val__") name) names)
2165+
binds (map core/vector names temp-val-syms)
2166+
resets (reverse (map core/vector names orig-val-syms))
21662167
bind-value (core/fn [[k v]] (core/list 'set! k v))]
2167-
`(let [~@(interleave tempnames names)]
2168+
`(let [~@(interleave orig-val-syms names)
2169+
~@(interleave temp-val-syms vals)]
21682170
~@(map bind-value binds)
21692171
(try
21702172
~@body

src/test/cljs/cljs/binding_test.cljs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,19 @@
1919
(is (with-redefs [o/bar 2]
2020
(= o/bar 2)))
2121
(is (= o/bar 10)))
22+
23+
(def ^:dynamic *a* 1)
24+
(def ^:dynamic *b* nil)
25+
26+
(deftest test-binding-parallel
27+
(is (= 2 (binding [*a* 10
28+
*b* (inc *a*)]
29+
*b*))))
30+
31+
(def a 1)
32+
(def b nil)
33+
34+
(deftest test-redefs-parallel
35+
(is (= 2 (with-redefs [a 10
36+
b (inc a)]
37+
b))))

0 commit comments

Comments
 (0)