-
Notifications
You must be signed in to change notification settings - Fork 20
Rename AtomicPtr::fetch_ptr_{add,sub}
to AtomicPtr::fetch_{add,sub}
#126
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
Comments
I personally don't think we should value consistency with the non-atomic pointer types above the potential confusion here. I think it's not unusual for code to be upgraded/changed from AtomicUsize to AtomicPtr (especially because of the strict provenance work), and it'd be a shame if |
I'll disagree with @m-ou-se here: I think this change is good since it also makes |
That note about I think |
It's tricky and algorithm-specific but absolutely possible, and |
We discussed this further in a libs meetup. We felt like the same arguments still apply for why this would be potentially error-prone, most notably that conversion from We weren't entirely thrilled with the names We'd be willing to review a change proposal for a better name that's unambiguous and still makes it clear that it operates in type-sized units rather than bytes. |
Proposal
Problem statement
AtomicPtr
has unstable methods that allow mutating it like other atomic types:These methods were added in order to remove some int2ptr casts (as part of the strict provenance initiative) that were forced because
AtomicPtr
did not have these APIs andAtomicUsize
was used instead.fetch_ptr_add
andfetch_ptr_sub
names are confusing and inconsistent:ptr
implies that the second argument is a pointer (like in case ofsub_ptr
for example), but it isn'tpointer::{add,sub}
don't have theptr
partptr
was meant to suggest that these methods work in units ofT
(as opposed tofetch_byte_add
), but it is already the default for pointersMotivation, use-cases
The motivation is to make the naming less confusing, more consistent and easier to understand.
The search for
fetch_(add|sub)\(.+\) as \*
in public repositories doesn't yield many results, so I'm assuming usingAtomicUsize
asAtomicPtr
withfetch_{add,sub}
is not a common practice and we don't have almost any data of the use cases.I do not know if this is because using
AtomicUsize
asAtomicPtr
is not nice or if this is becausefetch_add
for pointers is not that useful.Solution sketches
I propose just dropping
_ptr
part, renaming the methods tofetch_add
andfetch_sub
.An alternative would be to come out with a better naming, however it would still be inconsistent with
pointer
methods (and I couldn't come out with anything which makes sense).Additionally we should provide good documentation that clearly states (with examples) how these methods work.
Links and related work
AtomicPtr
rust#99108fetch_add
is ambiguous/footgunny and eventually lead tofetch_ptr_add
name Allow arithmetic and certain bitwise ops on AtomicPtr rust#96935 (comment)ptr
fromAtomicPtr::fetch_{add,sub}
method names rust#102970What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: