Skip to content

when try+ expands it captures too much #36

Closed
pjstadig opened this Issue Aug 13, 2013 · 3 comments

2 participants

@pjstadig

When try+ expands it captures the entire lexical environment regardless of whether all of the symbols in the environment are free in the body of the try+.

This means in a case like this:

(let [x 1] (fn [] (try+ 1)))

The closure that is returned will include a reference to x. The risk is that x could be a lazy sequence, and even though it is not referenced in the closure its head will be held as long as the closure is around.

The simplest solution seems to be providing a way to disable environment capture.

Another solution would be to trim the environment based on the body of the try+, though that might break existing code.

@pjstadig
pjstadig commented Mar 9, 2014

I don't think environment trimming could actually work. First of all it is the throw+ that is capturing the environment. An empty try+ will exhibit the problem because the catch clause (even for an empty try+) contains a throw+ form.

Second, all of this is non-lexical, so in general it doesn't seem possible to determine what names in the environment are being referenced, for example:

(defn do-something []
  (let [x :this-is-x]
    (throw+ 1)))

(try+
  (do-something)
  (catch Object o
    (println (get (:environment &throw-context) 'x))))

It seems the only valid options here are to either provide an option to disable the environment capture (which would be less likely to break code), or just remove this feature (since it isn't really a safe feature in terms of lazy sequences, locals clearing, etc.).

@scgilardi
Owner

I'm inclined to remove the feature.

@scgilardi
Owner

addressed by merge of "stop capturing locals", issue #44.

@scgilardi scgilardi closed this Oct 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.