Fork me on GitHub
#clojure-dev
<
2023-01-18
>
John Hinchberger01:01:11

I'm not able to comment on CLJ-2743 directly so I figured I would add some input here about why I think that behavior is being seen. In the JVM the catch block of a thrown exception is always stack clearing (JVMS §6.5 athrow), but at the language level Clojure presents 'try' as a simple expression which doesn't have that non-local behavior. The problem is with expressions like [1 2 (try (something) (catch Exception e 3))]. The stack frame entering into the catch is only going to be (exception) not (1, 2, exception). Essentially, the compiler needs to save the existing stack frame when it encounters a 'try' otherwise it loses those stack elements if the catch is executed. The mechanism to save these existing stack elements seemed to be to copy the entire try block into a separate function and run that. This has the benefit that the frame cleared is not the current stack frame. The downside is the synthetic closure created shadows existing symbols.

hiredman02:01:53

Yes, if you search for clj-2743 there is some discussion of this that didn't get copied to the ticket https://clojurians.slack.com/archives/C03S1KBA2/p1671647482679789?thread_ts=1671643575.912139&amp;cid=C03S1KBA2

hiredman02:01:25

And there are other issues like https://clojure.atlassian.net/browse/CLJ-701 which are also a result of the simple hoisting the compiler does

John Hinchberger02:01:59

Ah, I only checked the ask clojure thread and both of the related tickets. I'll check backchat next time too. Thanks!

Alex Miller (Clojure team)03:01:51

just fyi, you can comment on the Ask Clojure issue instead of the jira, that's what it's for. we look at both when working on stuff