-
-
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
atomics: switch to using Pair for return pairs #41659
Conversation
6defd26
to
cff1610
Compare
I'm not totally sold on this; the case of |
That particular usage of pair is a common API pattern in C++ to return |
That's a good example. In C++ pair is basically the same as a 2-tuple, though. I guess they have tuples now, but pair predates them by a lot? It looks to me like they'd use 2-tuples now if they were doing it over. |
Or, if we want something invariant, another possibility is to use namedtuples, and be more self-documenting at the same time. |
cff1610
to
20d6dae
Compare
This makes many more functions type-stable, by directly preserving the element type when making the copy, and prints as `old => new`, like the argument to atomic replace. For replace, we use Pair{FT, FT} (like the argument). For modify, we use NamedTuple{(:old, :success), Tuple{FT, Bool}}.
20d6dae
to
0f86508
Compare
# if we didn't inline this, it's probably because the callsite was actually dynamic | ||
# to avoid potentially compiling many copies of this, we mark the arguments with `@nospecialize` | ||
# but also mark the whole function with `@inline` to ensure we will inline it whenever possible | ||
# (even if `convert(::Type{A}, a::A)` for some reason was expensive) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comment have been moved to Base.jl? Or which method does it belong to?
This makes many more functions type-stable, by directly preserving the element type when making the copy, and prints as `old => new`, like the argument to atomic replace. For replace, we use Pair{FT, FT} (like the argument). For modify, we use NamedTuple{(:old, :success), Tuple{FT, Bool}}. (cherry picked from commit cc3fc0b)
This makes many more functions type-stable, by directly preserving the
element type when making the copy, and prints as
old => new
, like theargument to atomic replace.