cljs-dev

dnolen 2026-03-06T21:23:14.851359Z

@borkdude ok async much easier for me to digest, is the reason you need the bootstrap macros because if you use the Clojure macros you can't do the meta processing for async?

borkdude 2026-03-06T21:36:23.825929Z

The changes to the fn macro are because of (^:async fn ...) support

borkdude 2026-03-06T21:37:14.093509Z

correct yes

borkdude 2026-03-06T21:38:29.298889Z

one thing that's been on my mind: we could make async itself not a macro but a special form based on context like catch in try is. So when you use async outside of an async context, you would just get `"Unresolved symbol: async", perhaps with a better location.

borkdude 2026-03-06T21:38:46.351979Z

Not sure which is best

dnolen 2026-03-06T22:01:21.725059Z

you mean the testing macro? It wasn't really intended for general usage

borkdude 2026-03-06T22:08:53.607309Z

no I don't mean the testing macro, I mean the (defmacro async ...)

dnolen 2026-03-06T22:11:18.759029Z

maybe I'm missing something but isn't this in cljs.test or is that a part of the patch? (sorry in the middle of a close review, so maybe not there yet)

borkdude 2026-03-06T22:11:56.952899Z

no it's in cljs.core

borkdude 2026-03-06T22:12:22.097339Z

sorry, I mean defmacro await

borkdude 2026-03-06T22:12:42.268449Z

so either await as a macro or contextual special form like catch in try/catch

dnolen 2026-03-06T22:16:31.909629Z

could do, but first thought is that await can see &env - is that only locals or can you get the expr context there? I thought it had the full compiler env unlike in Clojure

borkdude 2026-03-06T22:17:54.242909Z

it's just a regular CLJS macro so env is whatever all macros get in CLJS. The expr context is in there right now. But it doesn't have to be this way really, we could do without a macro as well

borkdude 2026-03-06T22:18:44.847489Z

I'm mostly thinking about good error messages when you try to use await outside of an async context

dnolen 2026-03-06T22:21:19.254979Z

I just mean is there any advantage w/ the special form? I think in CLJS it doesn't make much difference for something this simple - but maybe you have something else in mind I don't see yet?

borkdude 2026-03-06T22:22:44.891079Z

I guess it's fine how it is now, wrt error messages.

$ clj -M:cljs-repl -m cljs.main -re node
ClojureScript 0.0.1487400309
cljs.user=> (defn foo [] (await 1))
Unexpected error (AssertionError) macroexpanding cljs.core/await at (<cljs repl>:1:14).
Assert failed: await can only be used in async contexts
(:async &env)
cljs.user=> (defn foo [] (catch 1))
WARNING: Use of undeclared Var cljs.user/catch at line 1 <cljs repl>
#'cljs.user/foo

borkdude 2026-03-06T22:23:22.395769Z

just wanted to share my doubts if await really has to be a macro or not, but it's probably fine

dnolen 2026-03-06T22:31:40.170689Z

I mean sometimes a macro is simpler, adding a special form is a bit more invasive.

👍 1
dnolen 2026-03-06T22:32:19.394599Z

That said it's harder for tooling to understand if you don't have a new AST type.

borkdude 2026-03-06T22:32:24.114819Z

another benefit of a macro is that the symbol isn't coming out of nowhere

dnolen 2026-03-06T22:32:50.603939Z

so it does help tooling if we move to special form.

dnolen 2026-03-06T22:33:18.043639Z

still maybe some more feedback appropriate here before we decide ...

borkdude 2026-03-06T22:33:39.876429Z

right, we could change it based on feedback, too early to tell I think

dnolen 2026-03-06T22:37:09.726599Z

I see you allow async assignment to def in the patch? is there a test for that? Does top level async work?

borkdude 2026-03-06T22:38:12.638079Z

top level async/await doesn't work. in the REPL you can make it work by using a self-calling async fn though. can you point me to what you are referring to?

borkdude 2026-03-06T22:39:03.049969Z

file and line number

dnolen 2026-03-06T22:41:59.259289Z

async when def emits var, (note this is a REPL thing only)

borkdude 2026-03-06T22:42:42.397229Z

I just captured all the IIFE creation with two functions, iife-open and iife-close to be consistent

dnolen 2026-03-06T22:43:19.819619Z

ok, I will check if this leads to bad code gen in the REPL

borkdude 2026-03-06T22:43:42.936179Z

let me know, I'm curious what you come up with :)

dnolen 2026-03-06T22:45:16.009389Z

will do, thanks for doing this - this is fun to review and excited to play w/ it when I have all the notes down

borkdude 2026-03-06T22:46:19.982579Z

sounds good. at least with iife-open / close we can now track where the implicit iife-s are happening in the code.

dnolen 2026-03-06T21:23:48.980209Z

I'm going to try to really assess the patch this weekend, sorry for the delay