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

RFC: make Ref(x) always construct a RefValue(x) object #21527

Merged
merged 1 commit into from
Dec 21, 2017
Merged

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Apr 24, 2017

After having Ref(x) on master for awhile, it seems awkward to need to write Ref{typeof(x)}(x) to be sure to get a reference to x itself, especially since x may often be a Ptr. This reserves Ref(x) to mean precisely "make a Ref containing x". Further, it extends two common usages (Ref{<:Number}() and Ref{<:Ptr}()) to always be zero-initialized so that Ref{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)

(::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)
Copy link
Member

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.

@pabloferz
Copy link
Contributor

Somewhat related #18990

@ararslan ararslan added needs docs Documentation for this change is required needs tests Unit tests are required for this change labels Apr 24, 2017
@tkelman
Copy link
Contributor

tkelman commented Apr 24, 2017

Way too late to be adding new deprecations to 0.6.

@StefanKarpinski
Copy link
Member

Yes, this absolutely cannot be merged until we branch.

@@ -1328,6 +1328,10 @@ for fname in (:ones, :zeros)
end
end

@deprecate Ref(x::AbstractArray) Ref(x, 1)
Copy link
Contributor

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

@timholy timholy added this to the 1.0 milestone Dec 2, 2017
@timholy
Copy link
Member

timholy commented Dec 2, 2017

LGTM. I added a 1.0 tag. Just needs a rebase & merge.

@vtjnash vtjnash removed needs docs Documentation for this change is required needs tests Unit tests are required for this change labels Dec 19, 2017
the old behavior is now directly a feature of `convert`
@vtjnash vtjnash merged commit b57a592 into master Dec 21, 2017
@vtjnash vtjnash deleted the jn/Ref-always branch December 21, 2017 03:31
@vtjnash
Copy link
Member Author

vtjnash commented Dec 21, 2017

@nanosoldier runbenchmarks(ALL, vs="@555264e1f005eb390ad22c29c26cf14c662b0677")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@vtjnash
Copy link
Member Author

vtjnash commented Dec 22, 2017

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.

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

Successfully merging this pull request may close these issues.

7 participants