This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-18
Channels
- # aws (1)
- # babashka (35)
- # beginners (52)
- # biff (4)
- # calva (55)
- # cider (19)
- # clojure (54)
- # clojure-dev (3)
- # clojure-europe (23)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-uk (2)
- # clojurescript (9)
- # code-reviews (3)
- # datahike (1)
- # fulcro (1)
- # funcool (4)
- # graalvm (21)
- # gratitude (2)
- # java (5)
- # jobs (2)
- # joyride (1)
- # kaocha (13)
- # malli (2)
- # off-topic (22)
- # other-languages (11)
- # pathom (4)
- # re-frame (35)
- # reagent (3)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (42)
- # sql (18)
- # tools-deps (72)
- # web-security (6)
- # xtdb (15)
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?
@dekelpilli Hmm, that's funny, I upgraded timbre to 6.0.1 in babashka. and I didn't get any errors about it
https://github.com/babashka/babashka/commit/d222b32d7009e43cd0f6aa639bd7e1d39157cb58
@dekelpilli which graalvm version are you using?
@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.
@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 checkhttps://github.com/babashka/babashka/blob/326b1def6b1ba476b445d58c954f0c8c78751dbc/feature-logging/babashka/impl/logging.clj#L16 So I'm avoiding this bug for now
Made an issue here https://github.com/ptaoussanis/timbre/issues/360
Ah ok, thank you for looking into that, I was quite confused about how you got it working in BB without issue
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)))
Yeah, although I am curious about the use of random in this instance, but that’s no longer a graalvm discussion. Thanks again!
Perhaps @dergutemoritz can enlighten us why this was necessary
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.
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
See https://github.com/ptaoussanis/timbre/pull/354 for rationale
@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).
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)
Sorry for breaking graal compat, it's something that isn't on my radar so far 🙂
or rather: I haven't absorbed it into my habits, yet