<!-- 
RSS generated by JIRA (4.4#649-r158309) at Sun May 19 06:35:14 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/CLJ-944/CLJ-944.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[CLJ-944] (.containsKey {:one 1} :one) throws Exception</title>
                <link>http://dev.clojure.org/jira/browse/CLJ-944</link>
                <project id="10010" key="CLJ">Clojure</project>
                        <description>&lt;p&gt;Patch clj944-plus-tests does three things:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;includes the previous &quot;0002&quot; patch which has the compiler emit map types consistent with the reader&lt;/li&gt;
	&lt;li&gt;adds tests&lt;/li&gt;
	&lt;li&gt;removes tests that were broken all along and now symptomatic&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Hi guys, I am getting the following exception:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;(.containsKey {:one 1} :one)
;=&amp;gt; ClassCastException clojure.lang.PersistentArrayMap cannot be &lt;span class=&quot;code-keyword&quot;&gt;cast&lt;/span&gt; to clojure.lang.PersistentHashMap&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;The map is a clojure.lang.PersistentArrayMap, which obviously has a containsKey method (&lt;a href=&quot;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L95&quot;&gt;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L95&lt;/a&gt;). &lt;/p&gt;

&lt;p&gt;Casting it works fine though:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;(.containsKey ^clojure.lang.PersistentArrayMap {:one 1} :one)
;=&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;The mailing list suggest that the compiler injects an incorrect cast to clojure.lang.PersistentHashMap. In this case it should probably be cast to a clojure.lang.Associative, the highest common interface having the .containsKey method.&lt;/p&gt;

&lt;p&gt;The problem is not present in Clojure 1.2.1.&lt;/p&gt;</description>
                <environment>Clojure 1.3 om Mac OS 10.7, Clojure 1.5.0 alpha1 on Linux x86_64 (OpenJDK 1.7.0 b147)</environment>
            <key id="15259">CLJ-944</key>
            <summary>(.containsKey {:one 1} :one) throws Exception</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="3" iconUrl="http://dev.clojure.org/jira/images/icons/priority_major.gif">Major</priority>
                    <status id="1" iconUrl="http://dev.clojure.org/jira/images/icons/status_open.gif">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="-1">Unassigned</assignee>
                                <reporter username="stoyle">Alf Kristian St&#248;yle</reporter>
                        <labels>
                    </labels>
                <created>Sun, 4 Mar 2012 02:45:09 -0600</created>
                <updated>Sat, 13 Apr 2013 12:06:35 -0500</updated>
                                    <version>Release 1.3</version>
                <version>Release 1.4</version>
                <version>Release 1.5</version>
                                <fixVersion>Release 1.5</fixVersion>
                <fixVersion>Release 1.6</fixVersion>
                                        <due></due>
                    <votes>2</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="29873" author="bronsa" created="Tue, 30 Oct 2012 17:02:10 -0500"  >&lt;p&gt;The attached patch fixes the issue, by emitting IPersistentMap instead of Persistent{Hash|Array}Map as class type for maps literals&lt;/p&gt;</comment>
                    <comment id="29885" author="bronsa" created="Thu, 1 Nov 2012 15:48:45 -0500"  >&lt;p&gt;I uploaded another patch fixing the same problem in a different way.&lt;br/&gt;
While 0001-Fix-for-&lt;a href=&quot;http://dev.clojure.org/jira/browse/CLJ-944&quot; title=&quot;(.containsKey {:one 1} :one) throws Exception&quot;&gt;CLJ-944&lt;/a&gt;.patch makes clojure.lang.Complier.ConstantExpr#getJavaClass return clojure.lang.IPersistentMap for both clojure.lang.PersistentHashMap and clojure.lang.PersistentArrayMap, 0002-Fix-for-&lt;a href=&quot;http://dev.clojure.org/jira/browse/CLJ-944&quot; title=&quot;(.containsKey {:one 1} :one) throws Exception&quot;&gt;CLJ-944&lt;/a&gt;.patch makes clojure.lang.Compiler.MapExpr#parse return a PersistentArrayMap if the length is &amp;lt;= HASHTABLE_THRESHOLD, instead of always returning a PersistentHashMap.&lt;/p&gt;

&lt;p&gt;This approach is more consistent, making the type of the compiler&apos;s internal representation of a map literal equal to the one of the reader.&lt;/p&gt;

&lt;p&gt;Note that this second approach while being more consistent, breaks some tests that assume some operations on maps (specifically `seq` and `print`) to be order dependent, and written with the hash-map return order implementation in mind.&lt;/p&gt;

&lt;p&gt;That should not be the case and if the second patch is preferred over the first one, I&apos;ll gladly fix those tests.&lt;/p&gt;</comment>
                    <comment id="30678" author="stu" created="Fri, 1 Mar 2013 12:09:44 -0600"  >&lt;p&gt;Approach #2, relying on consistent choice of concrete map class by size throughout, feels quite fragile.&lt;/p&gt;

&lt;p&gt;Approach #1 seems to abuse the method name getJavaClass(), now having it return &quot;get the base type I would need for cast&quot;.&lt;/p&gt;

&lt;p&gt;Maybe there needs to be a different thing entirely?&lt;/p&gt;</comment>
                    <comment id="30684" author="bronsa" created="Fri, 1 Mar 2013 14:17:09 -0600"  >&lt;p&gt;Patch #2 should get merged (IMHO) regardless of the fragility of its approach to fixing this ticket&apos;s bug, since it fixes another bug:&lt;/p&gt;

&lt;p&gt;prior to the patch:&lt;/p&gt;

&lt;p&gt;user=&amp;gt; (class {:a 1})&lt;br/&gt;
clojure.lang.PersistentArrayMap&lt;br/&gt;
user=&amp;gt; (def a {:a 1})&lt;br/&gt;
#&apos;user/a&lt;br/&gt;
user=&amp;gt; (class a)&lt;br/&gt;
clojure.lang.PersistentHashMap&lt;/p&gt;

&lt;p&gt;after the patch:&lt;/p&gt;

&lt;p&gt;user=&amp;gt; (class {:a 1})&lt;br/&gt;
clojure.lang.PersistentArrayMap&lt;br/&gt;
user=&amp;gt; (def a {:a 1})&lt;br/&gt;
#&apos;user/a&lt;br/&gt;
user=&amp;gt; (class a)&lt;br/&gt;
clojure.lang.PersistentArrayMap&lt;/p&gt;

&lt;p&gt;This should also lead to some &lt;b&gt;minor&lt;/b&gt; performance enhancement since prior to this moment, every map def&apos;ed would be a HashMap instead of an ArrayMap&lt;/p&gt;

&lt;p&gt;So, I think patch #2 should be applied if not for this ticket&apos;s bug, at least for the reason stated above.&lt;br/&gt;
If somebody has any proposal for making this patch more solid regarding this ticket&apos;s bug, any help is welcome&lt;/p&gt;</comment>
                    <comment id="30949" author="richhickey" created="Sat, 13 Apr 2013 09:41:58 -0500"  >&lt;p&gt;This should not have passed screening. There are two issues, should be separate. I have no idea what has been screened nor what will be applied should it be approved. There&apos;s contention in the discussion but no resolution.&lt;/p&gt;</comment>
                    <comment id="30950" author="bronsa" created="Sat, 13 Apr 2013 12:06:35 -0500"  >&lt;p&gt;I don&apos;t think that there are two issues here.&lt;br/&gt;
The issue is only one: the compiler doesn&apos;t emit maps in a way consistent with what the reader returns and with how the compiler itself uses maps.&lt;br/&gt;
The symptoms are two: some interop calls fail, and def&apos;ed vars with a literal map as value never use a PersistentArrayMap.&lt;/p&gt;

&lt;p&gt;The underlying cause of those two symtoms is fixed by the patch 002 that i submitted (incorporated in Stu&apos;s clj944-plus-tests patch.&lt;/p&gt;

&lt;p&gt;Stuart said that this approach feels fragile but the bug is caused by the fact that everywhere else clojure returns a PersistentArrayMap when the element count is &amp;lt;= than the PersistentHashMap threshold, and when emitting maps, it doesn&apos;t.&lt;/p&gt;

&lt;p&gt;Making clojure emit maps consistently with how clojure does internally everywhere else looks to me like the only solution, and I don&apos;t really see how making clojure consistent is a fragile approach.&lt;/p&gt;

&lt;p&gt;But again, if somebody can suggest a better solution to this problem, I&apos;ll gladly submit another patch.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11644" name="0001-Fix-for-CLJ-944.patch" size="879" author="bronsa" created="Tue, 30 Oct 2012 17:02:10 -0500" />
                    <attachment id="11655" name="0002-Fix-for-CLJ-944.patch" size="1094" author="bronsa" created="Thu, 1 Nov 2012 15:48:45 -0500" />
                    <attachment id="11955" name="clj944-plus-tests.patch" size="4827" author="stu" created="Fri, 12 Apr 2013 15:57:36 -0500" />
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                <customfield id="customfield_10002" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                <customfieldname>Approval</customfieldname>
                <customfieldvalues>
                        <customfieldvalue key="10003">Vetted</customfieldvalue>

                </customfieldvalues>
            </customfield>
                                                                                    <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                            <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                <customfieldname>Patch</customfieldname>
                <customfieldvalues>
                        <customfieldvalue key="10001">Code</customfieldvalue>

                </customfieldvalues>
            </customfield>
                                                                                        </customfields>
    </item>
</channel>
</rss>