-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Atomic destructors #12631
Comments
…nomorphization code size nim-lang/Nim#12630
Actually there is another solution. Just like we can replace |
Sounds feasible. |
I'm not sure this is true btw, atomics have "publish" semantics, the compiler cannot reorder |
The
move
andwasMoved
procs need an escape hatch for Atomics.Today we can use the
{.nodestroy.}
pragma, originally designed to avoid deep recursion.However, it would be very easy to use an atomic and forget about no destroy.
Example
For example here is a single-producer single-consumer channel that can only buffer a pointer
In the
tryRecv
function, usingmove
instead would be equivalent toThis is not the same as the compiler could reorder the nil statement and violates the moRelease requirements (not here due to data dependencies).
Also while there would not be any different instructions emitted on X86 due to the strong memory model, this may not be the case on architecture like ARM and PowerPC.
Potential solutions
Atomics would become magic and cannot be implemented as a library
wasMoved
, this way atomic move can be implemented as a libraryThis would meant that the type is never destroyed implicitly
This requires proposition 2 as well
This requires proposition 2 as well
The text was updated successfully, but these errors were encountered: