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

@atomic setfield! parsing #56979

Closed
MilesCranmer opened this issue Jan 7, 2025 · 1 comment
Closed

@atomic setfield! parsing #56979

MilesCranmer opened this issue Jan 7, 2025 · 1 comment

Comments

@MilesCranmer
Copy link
Member

I think it would be nice if

@atomic setfield!(var, field, val)
@atomic setproperty!(var, field, val)

expanded correctly or gave a more descriptive error message. I have a custom setproperties! where I wanted to use :atomic on special handling of the setfield! operation and get confused about this because the error shows:

julia> mutable struct A
           @atomic a::Int
       end

julia> a = A(1)
A(1)

julia> @atomic setfield!(a, :a, 2)
ERROR: LoadError: could not parse @atomic expression setfield!(a, :a, 2)

I figured it out after reading https://gist.github.com/vtjnash/11b0031f2e2a66c9c24d33e810b34ec0 that I can provide :sequentially_consistent manually.

@vtjnash
Copy link
Member

vtjnash commented Jan 7, 2025

I don't know how you could, since that call syntax is already defined to mean an atomic update of the first argument expression (e.g. of a). Either as a field update (currently implemented now):

julia> @macroexpand @atomic +(x.x, 1)
:(Base.modifyproperty!(x, :x, +, 1, :sequentially_consistent))

Or a variable update (not yet implemented):

julia> @macroexpand @atomic +(a, 1)
:(Base.modifyglobal!(Main, :a, +, 1, :sequentially_consistent))

# other equivalent expressions would include:
julia> @macroexpand @atomic a + 1
julia> @macroexpand @atomic a += 1

@vtjnash vtjnash closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants