-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Can not call @sync from another macro in Julia 0.7 #28979
Comments
The error here seems to be how
This generates the following:
Here is what it looks like called through @parsync
I think that the statement |
I am having the same issue, running the exact code as OP except my macro was called @fortype. My version of Julia is 1.6.0 |
I think I discovered a workaround (Julia 1.7.1) Consider the (rather pointless) macro: julia> macro defer(ex)
:(@sync Threads.@spawn $(ex))
end When you try to call it, you'll see the same error as above: julia> @defer println(Threads.threadid())
ERROR: syntax: invalid let syntax around task.jl:398 To fix this, you have to disable the macro hygiene by wrapping the expression in the macro in julia> macro deferfix(ex)
esc(:(@sync Threads.@spawn $(ex)))
end
julia> @deferfix println(Threads.threadid())
1
Task (done) @0x00007ff62771d5a0 This probably also tells us that somehow the macro sanitization procedure is to blame. Sidenote: Interestingly doing the above in |
@ViralBShah, what PR closed this? I think I may be running into this issue here: CliMA/ClimaComms.jl#64. The suggestion above: macro deferfix(ex)
esc(:(@sync Threads.@spawn $(ex)))
end is not hygienic, so it's not really a safe recommendation. |
The hygienic version of that is simply: macro deferfix(ex)
esc(:($Base.@sync $Threads.@spawn $(ex)))
end Where each macro is explicitly qualified with a module name and the outer macro is wrapped in |
The alternative "proper" version of this is: macro deferfix(ex)
:(@sync @spawn $(esc(ex))))
end but many macros (include macroexpand itself) handle this form of expression incorrectly, resulting in the |
The macro deferfix(ex)
esc(:($Base.@sync $Threads.@spawn $(ex)))
end pattern worked, thanks! |
It appears to be impossible to use the
@sync
macro within another macro or conversely call@sync
on a user defined macro.Case in point:
Use of this macro gives:
If I remove the
@sync
from myparsync
macro, namely:If I use
@sync
outside of my macro it works with the raw@distributed
macroIf
@parsync
only calls@distributed
without the@sync
, then using@sync
with@parsync
appears to have no effect on@parsync
namely,Number n=3 is never printed.
I'm trying to create some universal macros I can use that depend on the version number of Julia, but this issue is blocking me for my modules containing parallel tasks.
The text was updated successfully, but these errors were encountered: