Skip to content

Commit faa3a25

Browse files
var-store-take: fix race condition and fuse adding new names
Co-authored-by: Oleksandr Yakushev <alex@bytopia.org>
1 parent a1b2780 commit faa3a25

File tree

1 file changed

+27
-15
lines changed
  • typed/clj.checker/src/typed/cljc/checker

1 file changed

+27
-15
lines changed

typed/clj.checker/src/typed/cljc/checker/cs_gen.clj

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,23 +1332,35 @@
13321332
;; The range is this map is a list of symbols generated on demand, as we need
13331333
;; more dots.
13341334

1335-
;; Take (generate as needed) n symbols that correspond to variable var used in
1335+
;; Take (generate as needed) n symbols that correspond to variable dotted-var used in
13361336
;; the context of type t.
13371337
;FIXME no-check, trans-dots needs to be generalised
1338-
(t/ann ^:no-check var-store-take [t/Sym r/Type t/Int t/Any -> (t/Seqable t/Sym)])
1339-
(defn- var-store-take [var t n {::keys [dotted-var-store] :as opts}]
1340-
(assert dotted-var-store (keys opts))
1341-
;(t/ann-form dotted-var-store (t/Atom (t/Map '[r/Type t/Sym] (t/Seq t/Sym))))
1342-
(let [key [t n]
1343-
res (@dotted-var-store key)]
1344-
(if (>= (count res) n)
1345-
;; there are enough symbols already, take n
1346-
(take n res)
1347-
;; we need to generate more
1348-
(let [new (repeatedly (- n (count res)) #(gensym var))
1349-
all (concat res new)]
1350-
(swap! dotted-var-store assoc key all)
1351-
all))))
1338+
(t/ann ^:no-check var-store-take [t/Sym r/Type t/Int t/Any -> (t/Vec t/Sym)])
1339+
(defn- var-store-take [dotted-var t n opts]
1340+
{:pre [(simple-symbol? dotted-var)
1341+
(r/Type? t)
1342+
(nat-int? n)]
1343+
:post [(vector? %)]}
1344+
(if (zero? n)
1345+
[]
1346+
(let [dotted-var-store (::dotted-var-store opts)
1347+
;_ (t/ann-form dotted-var-store (t/Atom (t/Map '[r/Type t/Sym] (t/Vec t/Sym))))
1348+
k [t n]
1349+
res (@dotted-var-store k)]
1350+
(if (>= (count res) n)
1351+
;; there are enough symbols already, take n
1352+
(subvec res 0 n)
1353+
;; we need to generate more
1354+
(-> (swap! dotted-var-store
1355+
(fn [m]
1356+
(let [res (m k)
1357+
cnt (count res)]
1358+
(cond-> m
1359+
(< cnt n)
1360+
(assoc k (into (or res []) (map (fn [_] (gensym dotted-var)))
1361+
(range (- n cnt))))))))
1362+
(get k)
1363+
(subvec 0 n))))))
13521364

13531365
(defn cs-gen-Function-just-rests [V X Y S T opts]
13541366
{:pre [(every? #(#{:fixed :rest} (:kind %)) [S T])]}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy