clojure-dev

John Hinchberger 2023-01-18T01:58:11.286689Z

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.

2023-01-18T02:26:53.556099Z

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&cid=C03S1KBA2

2023-01-18T02:28:25.049349Z

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 Hinchberger 2023-01-18T02:39:59.792419Z

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) 2023-01-18T03:17:51.787949Z

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