Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log! doesn't compile inside clojurescript go block #21

Closed
aiba opened this issue Sep 19, 2024 · 6 comments
Closed

log! doesn't compile inside clojurescript go block #21

aiba opened this issue Sep 19, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@aiba
Copy link

aiba commented Sep 19, 2024

Compiling this code in ClojureScript fails with "ExceptionInfo Can't call nil":

(cljs.core.async/go (taoensso.telemere/log! "hello"))

I'm guessing this has something to do with the way the log! macro expands and then the go macro analyzes the expanded code.

On JVM clojure, it works fine. Is there a way to get it to also work in ClojureScript?

@ptaoussanis ptaoussanis added the bug Something isn't working label Sep 19, 2024
@ptaoussanis ptaoussanis self-assigned this Sep 19, 2024
@ptaoussanis
Copy link
Member

@aiba Hi Aaron, thanks for the report! I'll need to investigate what go is doing that might be causing trouble.

What's the urgency on this? Could a fix wait till next week sometime?

@aiba
Copy link
Author

aiba commented Sep 19, 2024

Not urgent. For now, I can just wrap log! in a regular function, since go macros don't analyze across function boundaries.

@ptaoussanis
Copy link
Member

ptaoussanis commented Sep 20, 2024

Okay, thanks!

BTW in case it's not obvious, you may literally be able to do something like ((fn [] (tel/log! "hello"))) within your go block. (Not sure if that's what you already had in mind, or if you were talking about moving your log calls into a fn that you def outside your go block).

I'll keep this open till I've investigated and found a solution 👍

ptaoussanis added a commit that referenced this issue Sep 20, 2024
Problem:
  (clojure.core.async/go (taoensso.telemere/log! "hello")) ; Compiles fine
  (cljs.core.async/go    (taoensso.telemere/log! "hello")) ; Compile fails

I could try to get to the bottom of exactly what's going on - but ultimately
IOC mechanisms like `go` are always going to be a bit fragile, especially for
heavily-optimized/unusual code.

In this case, the problem is thankfully only with Cljs - and Telemere's Cljs
performance isn't too critical - so I think we can afford to just bypass any
potential fiddling by the `go` macro by wrapping Cljs Telemere expansions in
an IIFE ((fn [] ...)).

Downside is the (small) added cost of a function construction and call.
Upside   is avoiding potential issues with core.async and other similar
IOC-style systems (Electric Clojure, etc.)
@ptaoussanis
Copy link
Member

ptaoussanis commented Sep 20, 2024

Update: fix (a reasonable workaround) is up on master, and available now as a 1.0.0-SNAPSHOT.

Basically just auto-wrapping Cljs expansions with ((fn [] ...)) to avoid fiddling by go and other similar IOC-style mechanisms.

Will keep this issue open until beta 23 is released (ETA next week).

@aiba
Copy link
Author

aiba commented Sep 20, 2024

Oh wow that's a nifty trick I hadn't thought of for go blocks, thank you for that! That's going to be useful to have in many situations.

ptaoussanis added a commit that referenced this issue Sep 20, 2024
Problem:
  (clojure.core.async/go (taoensso.telemere/log! "hello")) ; Compiles fine
  (cljs.core.async/go    (taoensso.telemere/log! "hello")) ; Compile fails

I could try to get to the bottom of exactly what's going on - but ultimately
IOC mechanisms like `go` are always going to be a bit fragile, especially for
heavily-optimized/unusual code.

In this case, the problem is thankfully only with Cljs - and Telemere's Cljs
performance isn't too critical - so I think we can afford to just bypass any
potential fiddling by the `go` macro by wrapping Cljs Telemere expansions in
an IIFE ((fn [] ...)).

Downside is the (small) added cost of a function construction and call.
Upside   is avoiding potential issues with core.async and other similar
IOC-style systems (Electric Clojure, etc.)
@ptaoussanis
Copy link
Member

Closing since this is now addressed in the latest betas 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants