<!-- 
RSS generated by JIRA (4.4#649-r158309) at Sat May 18 19:32:01 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-232/CLJ-232.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-232] Locals cleared too aggressively on delay</title>
                <link>http://dev.clojure.org/jira/browse/CLJ-232</link>
                <project id="10010" key="CLJ">Clojure</project>
                        <description>&lt;p&gt;Steve Gilardi and I noticed some strange behaviour with local clearing in conjunction with delay:&lt;/p&gt;

&lt;p&gt;    (defn do-something &lt;span class=&quot;error&quot;&gt;&amp;#91;x&amp;#93;&lt;/span&gt;&lt;br/&gt;
      (throw (Exception.)))&lt;/p&gt;

&lt;p&gt;    (defn clear-locals &lt;span class=&quot;error&quot;&gt;&amp;#91;x&amp;#93;&lt;/span&gt;&lt;br/&gt;
      (delay (try (do-something x)&lt;br/&gt;
                  (catch Exception e&lt;br/&gt;
                    (println &quot;argument value:&quot; x)))))&lt;/p&gt;

&lt;p&gt;    (force (clear-locals :argument))&lt;br/&gt;
    ;; =&amp;gt; argument value: nil&lt;/p&gt;

&lt;p&gt;It seems the locals are getting cleared a little too aggressively here. I did some digging to discover that delay is a thin wrapper around an fn, but using an fn in this context (rather than a delay) does not trigger the problem. Also I found that throwing an exception directly inside the try block (rather than in a function called from the try block) did not trigger it.&lt;/p&gt;

&lt;p&gt;I was able to reproduce in the new branch, the master branch, and 1.0.0, so it&apos;s not related to the more recent locals-clearing changes.&lt;/p&gt;</description>
                <environment></environment>
            <key id="13629">CLJ-232</key>
            <summary>Locals cleared too aggressively on delay</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                        <status id="6" iconUrl="http://dev.clojure.org/jira/images/icons/status_closed.gif">Closed</status>
                    <resolution id="1">Completed</resolution>
                                <assignee username="richhickey">Rich Hickey</assignee>
                                <reporter username="-1">None</reporter>
                        <labels>
                    </labels>
                <created>Wed, 30 Dec 2009 17:27:00 -0600</created>
                <updated>Tue, 24 Aug 2010 05:43:00 -0500</updated>
                    <resolved>Tue, 24 Aug 2010 05:43:00 -0500</resolved>
                                            <fixVersion>Release 1.2</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="23358" author="importer" created="Tue, 24 Aug 2010 05:43:00 -0500"  >&lt;p&gt;Converted from &lt;a href=&quot;http://www.assembla.com/spaces/clojure/tickets/232&quot;&gt;http://www.assembla.com/spaces/clojure/tickets/232&lt;/a&gt;&lt;br/&gt;
Attachments:&lt;br/&gt;
locals.clj - &lt;a href=&quot;https://www.assembla.com/spaces/clojure/documents/d6rA1a9ASr3RHaeJe5afGb/download/d6rA1a9ASr3RHaeJe5afGb&quot;&gt;https://www.assembla.com/spaces/clojure/documents/d6rA1a9ASr3RHaeJe5afGb/download/d6rA1a9ASr3RHaeJe5afGb&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="23359" author="importer" created="Tue, 24 Aug 2010 05:43:00 -0500"  >&lt;p&gt;technomancy said: [&lt;a href=&quot;file:d6rA1a9ASr3RHaeJe5afGb&quot;&gt;file:d6rA1a9ASr3RHaeJe5afGb&lt;/a&gt;]: repro case&lt;/p&gt;</comment>
                    <comment id="23360" author="importer" created="Tue, 24 Aug 2010 05:43:00 -0500"  >&lt;p&gt;chouser@n01se.net said: &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;((let [x :foo]
     (#^{:once &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;} fn* []
       (&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; (#(&lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; (Exception.)))
         (&lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; Exception e
           (println &lt;span class=&quot;code-quote&quot;&gt;&quot;x:&quot;&lt;/span&gt; x))))))
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;
The same problem is visible when a &lt;span class=&quot;code-keyword&quot;&gt;finally&lt;/span&gt; clause uses a closed-over:
&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;  ((let [x :foo]
     (#^{:once &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;} fn* []
       (&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; (#(&lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; (Exception.)))
         (&lt;span class=&quot;code-keyword&quot;&gt;finally&lt;/span&gt;
           (println &lt;span class=&quot;code-quote&quot;&gt;&quot;x:&quot;&lt;/span&gt; x))))))&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br/&gt;
Both of these print x: nil when they should print x: :foo&lt;/p&gt;

&lt;p&gt;I think the problem is that, because the last expr in a try block produces the value that will be returned, it is compiled in a &quot;return&quot; context (a.k.a. tail position), therefore the locals are cleared before calling the final function.&lt;/p&gt;

&lt;p&gt;But if that final call throws an exception, you end up in the catch clause with your locals cleared.&lt;/p&gt;

&lt;p&gt;emitClearLocals protects against this problem by using localsUsedInCatchFinally, but emitClearCloses (used only when :once is true) does not.&lt;/p&gt;

&lt;p&gt;The solution is so very far beyond me.  I guess the simplest might be to skip clearing of closed-overs that are used in catch/finally clauses, but I don&apos;t think those are currently tracked.  It looks like closeOver could be made to track these as well, but I&apos;m lost as to the relationships between the various instances in that code.&lt;/p&gt;</comment>
                    <comment id="23361" author="importer" created="Tue, 24 Aug 2010 05:43:00 -0500"  >&lt;p&gt;danlarkin said: Kevin Downey and I just stumbled on this problem again. Here&apos;s our smallest repro case:&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;(defn throwsomething [] (&lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; (Exception.)))

(defn foo [bar]
  @(delay (&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt;
           (throwsomething)
           (&lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; Exception e
             (nil? bar)))))
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;

We came up with two workarounds, one is to wrap everything inside the delay in a let capturing the &lt;span class=&quot;code-quote&quot;&gt;&quot;bar&quot;&lt;/span&gt; scope, like &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;:

&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;
(defn foo [bar]
  @(delay (let [bar bar]
            (&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt;
             (throwsomething)
             (&lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; Exception e
               (nil? bar))))))
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;

and the other is to not have the exception-throwing call in the tail position, like &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;:

&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;
(defn foo [bar]
  @(delay (&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt;
           (let [t (throwsomething)]
             t)
           (&lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; Exception e
             (nil? bar)))))&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="23362" author="importer" created="Tue, 24 Aug 2010 05:43:00 -0500"  >&lt;p&gt;richhickey said: (In [&lt;span class=&quot;error&quot;&gt;&amp;#91;r:93fecbd825c26e2570f8449cd64d0df0cc520c1d&amp;#93;&lt;/span&gt;]) fold closes clearing into the path system, fixes #232&lt;/p&gt;

&lt;p&gt;Branch: master&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                                                                                            </customfields>
    </item>
</channel>
</rss>