-
-
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
RFC: make Ref(x) always construct a RefValue(x) object #21527
Conversation
base/refpointer.jl
Outdated
(::Type{Ref{T}})() where {T} = RefValue{T}() # Ref{T}() | ||
(::Type{Ref{T}})(x) where {T} = RefValue{T}(x) # Ref{T}(x) | ||
convert(::Type{Ref{T}}, x) where {T} = RefValue{T}(x) | ||
|
||
Ref(x::Ref, i::Integer) = (i != 1 && error("Ref only has one element"); x) |
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.
throw(ArgumentError())
would probably be better than error()
here.
Somewhat related #18990 |
Way too late to be adding new deprecations to 0.6. |
Yes, this absolutely cannot be merged until we branch. |
base/deprecated.jl
Outdated
@@ -1328,6 +1328,10 @@ for fname in (:ones, :zeros) | |||
end | |||
end | |||
|
|||
@deprecate Ref(x::AbstractArray) Ref(x, 1) |
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 be moved to 0.7 section
LGTM. I added a 1.0 tag. Just needs a rebase & merge. |
the old behavior is now directly a feature of `convert`
03388bf
to
c6b56d3
Compare
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
Sorry, wrong reference commit makes this a bit confusing to read the report. But shows that the performance issue observed in the nightly occurred before this PR was merged. |
After having
Ref(x)
on master for awhile, it seems awkward to need to writeRef{typeof(x)}(x)
to be sure to get a reference tox
itself, especially sincex
may often be a Ptr. This reservesRef(x)
to mean precisely "make a Ref containingx
". Further, it extends two common usages (Ref{<:Number}()
andRef{<:Ptr}()
) to always be zero-initialized so thatRef{Ptr{T}}()
works.(the old behavior of only making a Ref if the argument was not already a subtype of Ref is now directly a feature of
convert
)