Skip to content

Commit b967499

Browse files
thomasmulvaneymfikes
authored andcommitted
CLJS-1888 - Seqs of PHMs and PAMs do not handle metadata correctly
1 parent 2e5790b commit b967499

File tree

5 files changed

+235
-24
lines changed

5 files changed

+235
-24
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ reduces them without incurring seq initialization"
17421742
(cons o coll))
17431743

17441744
IEmptyableCollection
1745-
(-empty [coll] (-with-meta (.-EMPTY List) meta))
1745+
(-empty [coll] (.-EMPTY List))
17461746

17471747
IHash
17481748
(-hash [coll] (hash-ordered-coll coll))
@@ -4874,7 +4874,7 @@ reduces them without incurring seq initialization"
48744874
(-conj [coll o] (cons o coll))
48754875

48764876
IEmptyableCollection
4877-
(-empty [coll] (-with-meta (.-EMPTY List) meta))
4877+
(-empty [coll] (.-EMPTY List))
48784878

48794879
ISequential
48804880
ISeqable
@@ -4963,7 +4963,7 @@ reduces them without incurring seq initialization"
49634963
(-conj [coll o] (cons o coll))
49644964

49654965
IEmptyableCollection
4966-
(-empty [coll] (-with-meta (.-EMPTY List) meta))
4966+
(-empty [coll] (.-EMPTY List))
49674967

49684968
IHash
49694969
(-hash [coll] (caching-hash coll hash-ordered-coll __hash))
@@ -5060,7 +5060,7 @@ reduces them without incurring seq initialization"
50605060
(-conj [coll o] (cons o coll))
50615061

50625062
IEmptyableCollection
5063-
(-empty [coll] (-with-meta (.-EMPTY List) meta))
5063+
(-empty [coll] (.-EMPTY List))
50645064

50655065
ISequential
50665066
ISeqable
@@ -6774,7 +6774,7 @@ reduces them without incurring seq initialization"
67746774
(cons o coll))
67756775

67766776
IEmptyableCollection
6777-
(-empty [coll] (-with-meta (.-EMPTY List) _meta))
6777+
(-empty [coll] (.-EMPTY List))
67786778

67796779
IHash
67806780
(-hash [coll] (hash-ordered-coll coll))
@@ -6785,13 +6785,13 @@ reduces them without incurring seq initialization"
67856785

67866786
(-rest [coll]
67876787
(if (< i (- (alength arr) 2))
6788-
(PersistentArrayMapSeq. arr (+ i 2) _meta)
6788+
(PersistentArrayMapSeq. arr (+ i 2) nil)
67896789
()))
67906790

67916791
INext
67926792
(-next [coll]
67936793
(when (< i (- (alength arr) 2))
6794-
(PersistentArrayMapSeq. arr (+ i 2) _meta)))
6794+
(PersistentArrayMapSeq. arr (+ i 2) nil)))
67956795

67966796
IReduce
67976797
(-reduce [coll f] (seq-reduce f coll))
@@ -7722,7 +7722,7 @@ reduces them without incurring seq initialization"
77227722
(-conj [coll o] (cons o coll))
77237723

77247724
IEmptyableCollection
7725-
(-empty [coll] (-with-meta (.-EMPTY List) meta))
7725+
(-empty [coll] (.-EMPTY List))
77267726

77277727
ISequential
77287728
ISeq
@@ -7803,18 +7803,18 @@ reduces them without incurring seq initialization"
78037803
(-conj [coll o] (cons o coll))
78047804

78057805
IEmptyableCollection
7806-
(-empty [coll] (-with-meta (.-EMPTY List) meta))
7806+
(-empty [coll] (.-EMPTY List))
78077807

78087808
ISequential
78097809
ISeq
78107810
(-first [coll] (first s))
78117811
(-rest [coll]
7812-
(let [ret (create-array-node-seq nil nodes i (next s))]
7812+
(let [ret (create-array-node-seq nodes i (next s))]
78137813
(if-not (nil? ret) ret ())))
78147814

78157815
INext
78167816
(-next [coll]
7817-
(create-array-node-seq nil nodes i (next s)))
7817+
(create-array-node-seq nodes i (next s)))
78187818

78197819
ISeqable
78207820
(-seq [this] this)
@@ -7832,18 +7832,18 @@ reduces them without incurring seq initialization"
78327832
(es6-iterable ArrayNodeSeq)
78337833

78347834
(defn- create-array-node-seq
7835-
([nodes] (create-array-node-seq nil nodes 0 nil))
7836-
([meta nodes i s]
7835+
([nodes] (create-array-node-seq nodes 0 nil))
7836+
([nodes i s]
78377837
(if (nil? s)
78387838
(let [len (alength nodes)]
78397839
(loop [j i]
78407840
(if (< j len)
78417841
(if-let [nj (aget nodes j)]
78427842
(if-let [ns (.inode-seq nj)]
7843-
(ArrayNodeSeq. meta nodes (inc j) ns nil)
7843+
(ArrayNodeSeq. nil nodes (inc j) ns nil)
78447844
(recur (inc j)))
78457845
(recur (inc j))))))
7846-
(ArrayNodeSeq. meta nodes i s nil))))
7846+
(ArrayNodeSeq. nil nodes i s nil))))
78477847

78487848
(deftype HashMapIter [nil-val root-iter ^:mutable seen]
78497849
Object
@@ -8972,7 +8972,7 @@ reduces them without incurring seq initialization"
89728972
(cons o coll))
89738973

89748974
IEmptyableCollection
8975-
(-empty [coll] (-with-meta (.-EMPTY List) _meta))
8975+
(-empty [coll] (.-EMPTY List))
89768976

89778977
IHash
89788978
(-hash [coll] (hash-ordered-coll coll))
@@ -8987,7 +8987,7 @@ reduces them without incurring seq initialization"
89878987
(-next mseq)
89888988
(next mseq))]
89898989
(if-not (nil? nseq)
8990-
(KeySeq. nseq _meta)
8990+
(KeySeq. nseq nil)
89918991
())))
89928992

89938993
INext
@@ -8996,7 +8996,7 @@ reduces them without incurring seq initialization"
89968996
(-next mseq)
89978997
(next mseq))]
89988998
(when-not (nil? nseq)
8999-
(KeySeq. nseq _meta))))
8999+
(KeySeq. nseq nil))))
90009000

90019001
IReduce
90029002
(-reduce [coll f] (seq-reduce f coll))
@@ -9724,9 +9724,9 @@ reduces them without incurring seq initialization"
97249724
(-next [rng]
97259725
(if (pos? step)
97269726
(when (< (+ start step) end)
9727-
(Range. meta (+ start step) end step nil nil nil))
9727+
(Range. nil (+ start step) end step nil nil nil))
97289728
(when (> (+ start step) end)
9729-
(Range. meta (+ start step) end step nil nil nil))))
9729+
(Range. nil (+ start step) end step nil nil nil))))
97309730

97319731
IChunkedSeq
97329732
(-chunked-first [rng]
@@ -9746,7 +9746,7 @@ reduces them without incurring seq initialization"
97469746
(-conj [rng o] (cons o rng))
97479747

97489748
IEmptyableCollection
9749-
(-empty [rng] (-with-meta (.-EMPTY List) meta))
9749+
(-empty [rng] (-with-meta (.-EMPTY List) nil))
97509750

97519751
ISequential
97529752
IEquiv

src/test/cljs/cljs/collections_test.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
(is (= -1 (.lastIndexOf (cycle []) 19 2)))
203203

204204
(is (= {:a 1} (meta (with-meta (cycle [1 2 3]) {:a 1}))))
205-
(is (= {:a 1} (meta (empty (with-meta (cycle [1 2 3]) {:a 1})))))
205+
(is (nil? (meta (empty (with-meta (cycle [1 2 3]) {:a 1})))))
206206
(is (= (take 7 (with-meta (cycle [1 2 3]) {:a 1})) (take 7 (cycle [1 2 3]))))
207207

208208
(is (realized? (cycle [1 2 3])))
@@ -291,7 +291,7 @@
291291
(is (= 3 (.lastIndexOf (repeat 7 5) 5 3)))
292292

293293
(is (= {:a 1} (meta (with-meta (repeat 5 7) {:a 1}))))
294-
(is (= {:a 1} (meta (empty (with-meta (repeat 5 7) {:a 1})))))
294+
(is (nil? (meta (empty (with-meta (repeat 5 7) {:a 1})))))
295295
(is (= (with-meta (repeat 5 7) {:a 1}) (repeat 5 7)))
296296

297297
(is (not (realized? (repeat 5 7))))
@@ -338,7 +338,7 @@
338338
(is (not (realized? (rest (iterate inc 0)))))
339339

340340
(is (= {:a 1} (meta (with-meta (iterate inc 0) {:a 1}))))
341-
(is (= {:a 1} (meta (empty (with-meta (iterate inc 0) {:a 1})))))
341+
(is (nil? (meta (empty (with-meta (iterate inc 0) {:a 1})))))
342342
(is (= (take 20 (with-meta (iterate inc 0) {:a 1})) (take 20 (iterate inc 0))))
343343

344344
(is (= [:first 0 1] (take 3 (conj (iterate inc 0) :first))))

src/test/cljs/cljs/hash_map_test.cljs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,64 @@
9797
(let [m (array-map nil nil 1 1 2 2)]
9898
(is (every? map-entry? m))
9999
(is (every? map-entry? (iter->set (-iterator m))))))))
100+
101+
(deftest test-cljs-1888
102+
(let [arr-map-seq (seq (array-map :a 1 :b 2))
103+
;; small hash map will produce a NodeSeq
104+
node-seq (seq (hash-map :a 1 :b 2 :c 3))
105+
;; Large hash map will produce an ArrayNodeSeq
106+
array-node-seq (seq (into {}
107+
(map (fn [e] [e nil]))
108+
(range 1000)))]
109+
(testing "PersistentArrayMapSeq"
110+
(is (= {:has :meta} (-> arr-map-seq
111+
(with-meta {:has :meta})
112+
(meta))))
113+
(is (= nil (-> arr-map-seq
114+
(with-meta {:has :meta})
115+
(rest)
116+
(meta))))
117+
(is (= nil (-> arr-map-seq
118+
(with-meta {:has :meta})
119+
(next)
120+
(meta))))
121+
(is (= nil (-> arr-map-seq
122+
(with-meta {:has :meta})
123+
(empty)
124+
(meta)))))
125+
126+
(testing "NodeSeq"
127+
(is (instance? NodeSeq node-seq))
128+
(is (= {:has :meta} (-> node-seq
129+
(with-meta {:has :meta})
130+
(meta))))
131+
(is (= nil (-> node-seq
132+
(with-meta {:has :meta})
133+
(rest)
134+
(meta))))
135+
(is (= nil (-> node-seq
136+
(with-meta {:has :meta})
137+
(next)
138+
(meta))))
139+
(is (= nil (-> node-seq
140+
(with-meta {:has :meta})
141+
(empty)
142+
(meta)))))
143+
144+
(testing "ArrayNodeSeq"
145+
(is (instance? ArrayNodeSeq array-node-seq))
146+
(is (= {:has :meta} (-> array-node-seq
147+
(with-meta {:has :meta})
148+
(meta))))
149+
(is (= nil (-> array-node-seq
150+
(with-meta {:has :meta})
151+
(rest)
152+
(meta))))
153+
(is (= nil (-> array-node-seq
154+
(with-meta {:has :meta})
155+
(next)
156+
(meta))))
157+
(is (= nil (-> array-node-seq
158+
(with-meta {:has :meta})
159+
(empty)
160+
(meta)))))))

0 commit comments

Comments
 (0)