-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Document Base.RefValue and clarify that this is public API #58101
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
base: master
Are you sure you want to change the base?
Conversation
xref #40369 I don't see why this is necessary, especially now that a package is being registered. And considering all the issues with |
Even with the new package registered I think it is still good to clarify and make |
I feel that too much discussion of the ZeroDimensionalArrays.jl package might be a fruitless digression. The relevant questions should be:
My answers would have been: Yes, it's already de-facto public; yes, that's a good thing; and no, we shouldn't need to spell that out, but it is probably better to spell it out explicitly, at least for things like linters that warn about use of "private unstable APIs". You @nsajko have provided the existence proof for (3): Stability of this API is undeniably not self-evident. The reason why Base.RefValue is already de-facto public is: This is the return type of the widely advertised and used So I would not see this a new feature, but rather a docfix for an oversight when the |
That doesn't mean it's public or "de-facto public", xref #55280.
That doesn't mean it's public: see the FAQ. In fact, preventing these kinds of arguments was one of the motivations for introducing
Lots of abstract types don't have the |
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.
LGTM. There are almost always better choices (Some or FillArray or mutable), but it is valid to use this also in some occasional cases
This note seems welcome, but perhaps still gets lost at the end of Could it start out by saying that It would also help if the examples given would create a variety of types, as I think all of them now make julia> x = [0, pi, 2pi];
julia> r = Ref(x, 2)
Base.RefArray{Float64, Vector{Float64}, Nothing}([0.0, 3.141592653589793, 6.283185307179586], 2, nothing)
julia> r isa Ref{Float64}
true
julia> r[]
3.141592653589793
julia> p = pointer(x, 2)
Ptr{Float64} @0x000000010c7fe7e8
julia> p isa Ref
true Maybe the broadcasting heading can have its own block of examples, too. Maybe with and without julia> isa.(Ref(x), [Array Dict Real Complex]) # Ref(x) is scalar under broadcasting
1×4 BitMatrix:
1 0 0 0
julia> isa.(x, [Array Dict Real Complex])
3×4 BitMatrix:
0 0 1 0
0 0 1 0
0 0 1 0
julia> println.("hello", ' ', ("world", "julia")) # Strings are scalar under broadcasting...
hello world
hello julia
(nothing, nothing)
julia> Broadcast.broadcastable("string") # ... because this calls Ref
Base.RefValue{String}("string") |
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.
While I agree with @mcabbott's suggestions, they are not strictly about this PR so @bbrehm, you are welcome to address them here or choose to proceed without an overhaul of the Ref
docstring.
Currently, the documentation fails to build because the cross ref to RefValue
is broken because RefValue
is not included in the docs. It should go just after or just before Base.Ref
in doc/src/manual/base/c.md
.
Aside from that build issue this PR LGTM (Looks good to me). Thanks for making it!
Document Base.RefValue and clarify that this is public API.
This PR was triggered by https://discourse.julialang.org/t/ann-zerodimensionalarrays-jl-zero-dimensional-arrays-references-boxes/ and related discussions. Some people are questioning whether using
Base.RefValue
counts as "mucking with unstable runtime internals", so we better answer that conclusively.(I wouldn't mind also exporting
Base.RefValue
, but that's a higher bar in terms of cluttering the namespace, and let's not have the good be the enemy of the adequate)