Fork me on GitHub
#graalvm
<
2022-11-18
>
dekel08:11:42

I’m trying to use timbre 6.0.1 in a GraalVM project, but I’m struggling due to a top-level random that was added (in https://github.com/ptaoussanis/timbre/pull/354) since the last working version (5.2.1). Does anyone know how to make this work, or is my best bet here to make a PR against timbre to make it avoid instantiating Random at build time?

borkdude08:11:12

@dekelpilli Hmm, that's funny, I upgraded timbre to 6.0.1 in babashka. and I didn't get any errors about it

borkdude08:11:03

@dekelpilli which graalvm version are you using?

dekel09:11:00

@borkdude Yeah, I did see that babashka was using 6.0.1, which is what made me doubt my instinct to try and remove the random from timbre. I’m using graalVM 22.3.0 with Java 17. The specific project I’m trying to do this with is using https://github.com/clj-easy/graal-build-time, but I also tried to simply increase the version in https://github.com/clj-easy/graalvm-clojure/tree/master/timbre and that also broke due to the Random.

borkdude09:11:49

I'll try locally with only the Random

borkdude09:11:07

@dekelpilli I can reproduce this with:

(def x (java.util.Random. 1337))

(defn -main [& args]
  (prn args (.nextInt x)))
My guess is that I might not be using that specific function in bb. Let me check

borkdude09:11:47

Ah I think bb has its own version of the log! macro

dekel09:11:15

Ah ok, thank you for looking into that, I was quite confused about how you got it working in BB without issue

borkdude09:11:24

I can also do a PR, but I have a meeting now. You can fix it with:

(let [rand (delay (java.util.Random. 1337))] 
  (defn determistic-rand [] (.nextDouble ^java.util.Random @rand)))

dekel09:11:49

Yeah, although I am curious about the use of random in this instance, but that’s no longer a graalvm discussion. Thanks again!

borkdude09:11:29

Perhaps @dergutemoritz can enlighten us why this was necessary

dekel10:11:35

Oh, I had dinner and forgot why the usual delay strategy likely wouldn’t work here - this is called in a macro, so any usages of that macro would happen at build time, meaning the Random would get instantiated at build time anyway.

dekel10:11:35

Or maybe not… Maybe I need to brush up on my order of operations here, it looks like it’s fixed now in 6.0.2-SNAPSHOT

dergutemoritz10:11:09

@dekelpilli Instantiating the Random at macro-expansion time is no problem, it will not end up in the generated bytecode. What the fix guards against is that it also is instantiated at "load" time (where it's not even needed).

👍 1
dergutemoritz10:11:53

Problem being that you can't have a def which is only usable at macro-expansion time (unless you pull in https://github.com/cgrand/macrovich)

dergutemoritz10:11:52

Sorry for breaking graal compat, it's something that isn't on my radar so far 🙂

dergutemoritz10:11:14

or rather: I haven't absorbed it into my habits, yet