Fork me on GitHub
#cursive
<
2019-05-05
>
p-himik07:05:34

Is there any way to debug compiled classes created by compile function from a CLJ source? I see some magic - a function calls another function with a not-nil argument, and the callee still receives nil. I see that the call stack includes 2 levels for each function call, so there must be something fishy going on in there.

p-himik09:05:47

Here's a piece of code of interest:

(defn write
  "Writes a value to a transit writer."
  [^Writer writer o]
  (.write ^com.cognitect.transit.Writer (.w writer) o))
When the current line is the very first one, writer is not null. But as soon as I step into , it becomes null for no apparent reason.

p-himik09:05:35

Ahh, the value there is not actually null - the NPE is in the .write function, a step further. But why does the debugger report null here? I'm in the debug mode, so locals should not be cleared. Let alone locals in the current frame.

p-himik14:05:25

I have -Dclojure.compiler.disable-locals-clearing=true in my :jvm-opts, and the corresponding button in the debug REPL is pushed in, so that shouldn't be it.

cfleming22:05:54

@U2FRKM4TW That definitely sounds like locals clearing. Note that locals clearing is a compile flag, it has to be set when you compile your code. If you’re loading from source then having it set in your runtime is sufficient since your code will be compiled when it’s loaded, but if you’re AOT compiling you’ll have to either set the flag before compiling or re-evaluate your code (i.e. re-send the file to the REPL) to have it be recompiled taking the flag into account.

p-himik22:05:45

Hmm, there's a change it was indeed AOT. Thanks!