-
-
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
Interpolation syntax in Threads.@spawn breaks $-aware macros #34138
Comments
Now add a |
I think not recursing into other macro calls is sensible. For complex cases there is always the escape hatch of explicit let blocks. |
cc @NHDaly |
No, you're right. Not only is this a breaking change, it's also just broken. :( Julia 1.2: julia> fetch(@async @eval 2+$2)
4 Julia 1.4: julia> fetch(@async @eval 2+$2)
ERROR: TaskFailedException:
UndefVarError: ##501 not defined Alas. I guess my test coverage wasn't good enough. Sorry. So i think this is just a bug in my parsing in the macro. My intention was that this would still parse exactly the same as before, and that the I think if this is fixed, this should still be an okay change. My intention was that anywhere this is supported would previously have been a
So I already added a mechanism to make sure not to interfere with any julia> x = 2; fetch(Threads.@spawn "$x")
"2" But it's not enough to just not recurse into strings/quotes, since I wanted to support However, i'm not sure if I want to do the same thing for macrocalls, because not all macros actually do make use of (But yes, doing the same thing for macros does fix the broken Would it perhaps be a reasonable solution to manually |
Hmm, so I tried doing that, calling macroexpand internally and then recursing into the resultant expression to replace one level of remaining julia> # Issue #34138
@testset "spawn interpolation: inner macrocalls" begin
x = 2
@test fetch(@async @eval 2+$x) == 4
@test fetch(@async @eval 2+$$x) == 4
x = [reshape(1:4, 2, 2);]
@test fetch(Threads.@spawn @. $exp(x)) == @. $exp(x)
end
Test Summary: | Pass Total
spawn interpolation: inner macrocalls | 3 3
Test.DefaultTestSet("spawn interpolation: inner macrocalls", Any[], 3, false) HOWEVER it still doesn't work if there's a macro on the OUTSIDE: julia> @eval fetch(@async 2+$$x)
ERROR: syntax: "$" expression outside quote
Stacktrace:
[1] top-level scope at REPL[55]:1
julia> @eval fetch(@async @eval 2+$$x)
ERROR: syntax: "$" expression outside quote
Stacktrace:
[1] top-level scope at REPL[56]:1 I guess this is because this "inside-out" evaluation strategy is not very common...? |
I've just pushed up what i was trying here: #34148 Sorry i need to run to bed now. Hope some other good insight happens while I'm asleep! :) |
Right; I believe that for multiple
There clearly only |
Mmm yeah, too bad. But you're right that we can always use an explicit As an aside, would it make sense to try to move everyone towards having macros all support multiple |
@NHDaly Thanks for the quick patch PR and the thorough analysis!
I think imposing uniform meaning for |
It seems interpolation syntax for
@spawn
#33119 is a breaking change:In Julia 1.3
But maybe it's OK to have breaking changes as
@spawn
is explicitly marked as experimental?Stopping recursing into
macrocall
in the AST manipulation of@spawn
can "fix" this problem. However, it's a bit limiting approach if you consider something like@spawn h(@spawn g($(f(x))))
.One approach may be to repeat
$
to "escape"$
; e.g.,@spawn @. $$exp(x)
if you want to do@. $exp(x)
in another task. (This is of course breaking.)The text was updated successfully, but these errors were encountered: