defcache needs to impl. iterator() to avoid Clojure 1.7 breakage

Description

After upgrading to Clojure 1.7 beta2 some of our code started failing, specifically attempts to use iterator() on (keys our-cache).

This is because post http://dev.clojure.org/jira/browse/CLJ-1499, calls to iterator on Seqables optimize by delegating to underlying collection iterator. defcache implements IPersistentMap but not iterator therefore:

Proposal: Make defcache implement Iterable (which is implied by implementing IPersistentMap). I implemented by invoking .iterator on the underlying base-field, however this brings up the issue of reflection (warnings then popped up). To fix, I applied meta to base-field to type-hint it to clojure.lang.IPersistentMap.

This seems implied by various checks for map? elsewhere but I am not certain this is the correct type hint. It could be as narrow as java.lang.Iterable to be sufficient, but it seemed better to make a broader statement here if that is correct.

Patch: ccache-41.patch

Environment

None

Activity

Show:
Alex Miller
March 28, 2016, 3:10 PM

Patch applied for next release.

Fogus
March 28, 2016, 2:46 PM

Looks like a winner to me.

import
February 23, 2016, 11:54 AM

Is there any fix planned?
or should core.cache be considered permanently broken for clojure 1.7 ?

Alex Miller
May 27, 2015, 4:43 AM

The relevant ticket is not CLJ-1499 but CLJ-1602.

Alex Miller
May 27, 2015, 4:42 AM

defcache creates a deftype that implements IPersistentMap, but does not implement Iterable/iterator, even though IPersistentMap extends Iterable, so I consider this broken.

Completed

Assignee

Fogus

Reporter

Colin Taylor

Labels

None

Approval

Screened

Patch

Code and Test

Priority

Critical