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

Rename srand to Random.seed! #28295

Merged
merged 17 commits into from
Jul 29, 2018
Merged

Rename srand to Random.seed! #28295

merged 17 commits into from
Jul 29, 2018

Conversation

MoonCoral
Copy link
Contributor

@MoonCoral MoonCoral commented Jul 26, 2018

Closes #27726

  • Note that there are a bunch of deprecation warnings concerning Base.Random when running tests.
  • Also this causes Random.seed(seed) to be a common occurrence which could lead to confusion.
  • I didn't touch the occurrences in Base as they seem to be actually calling the c srand.

(This is my first PR)

@@ -37,3 +37,6 @@ end

# PR #25668
@deprecate RandomDevice(unlimited::Bool) RandomDevice(; unlimited=unlimited)

# PR #Current
@deprecate srand Random.seed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should have a false at the end to avoid exporting it, i.e.

@deprecate srand Random.seed false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think this form is supported, I think you need to write a custom message with depwarn(...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this works okay:

julia> module A
       f() = 1
       Base.@deprecate g A.f false
       end
Main.A

julia> using .A

julia> A.g()
┌ Warning: `g` is deprecated, use `A.f` instead.
│   caller = top-level scope at none:0
└ @ Core none:0
1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it is the other way around that does not work

Copy link
Contributor Author

@MoonCoral MoonCoral Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it when I wake up tomorrow. In the meantime, does anyone know where the:

WARNING: importing deprecated binding Base.Random into Test. Base.Random is deprecated, run `using Random` instead ERROR: LoadError: error compiling top-level scope: deprecated binding: Base.Random WARNING: importing deprecated binding Base.Random into Test. Base.Random is deprecated, run `using Random` instead ERROR: LoadError: error compiling top-level scope: deprecated binding: Base.Random

and similar come from? As they seem to be the main culprit to the tests failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Test.jl you need using Random instead of just using Random: ..., which only imports specific items from Random (and not Random itself).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need using Random instead of just using Random: ...,

In this case, import Random would be slightly better I think (imports only the binding Random itself), as there is already a line using Random: ... with explicit functions. But not worth changing again.
BTW, wouldn't it make sense that using Random: ... also imports the Random binding itself?

@ararslan ararslan added randomness Random number generation and the Random stdlib deprecation This change introduces or involves a deprecation needs news A NEWS entry is required for this change labels Jul 26, 2018
@Sacha0
Copy link
Member

Sacha0 commented Jul 26, 2018

Welcome @MoonCoral! Wonderful first contribution! 🎉

@MoonCoral
Copy link
Contributor Author

MoonCoral commented Jul 27, 2018

This should be it. Tell me if I should squash the commits.

@mbauman mbauman removed the needs news A NEWS entry is required for this change label Jul 27, 2018
NEWS.md Outdated
@@ -1321,6 +1321,8 @@ Deprecated or removed

* `ndigits(n, b, [pad])` is deprecated in favor of `ndigits(n, base=b, pad=pad)` ([#27908]).

* `srand` is deprecated in favor of the unexported `Random.seed` ([#27726]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the PR number should be mentioned here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue number is sufficient.

@@ -37,3 +37,6 @@ end

# PR #25668
@deprecate RandomDevice(unlimited::Bool) RandomDevice(; unlimited=unlimited)

# PR #28295
@deprecate srand Random.seed false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a deprecation for guardsrand -> guardseed as well? It was introduced in the 0.7 cycle but I know some packages use it so could be good to add.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guardsrand was unexported in #27942, without deprecation...

Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about squashing the commits, we can do that on merge. I have one outstanding comment, and other than that this looks great to me. Thanks for taking it on!

@@ -37,3 +37,6 @@ end

# PR #25668
@deprecate RandomDevice(unlimited::Bool) RandomDevice(; unlimited=unlimited)

# PR #28295
@deprecate srand Random.seed false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually wrong about false; that avoids exporting srand, not Random.seed. What you had originally was correct. Sorry about that!

@rfourquet
Copy link
Member

I would like to use this renaming opportunity to suggest Random.seed! instead. This was not mentioned in the linked issue, but was very briefly discussed at #9105 (comment).
It's true that we don't use the exclamation mark in rand even though the RNG state is modified. But I woud argue that this is the expected way of modifying the state, and the focus is on the produced random values (and we prefer reserving ! for our current rand!). In srand, the focus is on the RNG itself, with the goal to mutate it, so I think it deserves a !. For example, in the "Random.jl" __init__ function, we now have this call: seed(), on a line by itself; we usually don't see in Julia such a function without ! called only for its side effect; it really looks like this call does nothing.
Morever, in seed!(rng, seed), the ! helps a bit understand seed! as a verb versus seed as a noun.

@JeffBezanson
Copy link
Member

That's a good point; particularly if this is generalized to operate on an RNG, seed!(rng, val) makes more sense.

@ararslan ararslan dismissed their stale review July 27, 2018 20:17

Deprecation has been fixed

@MoonCoral
Copy link
Contributor Author

That went badly :(

@MoonCoral
Copy link
Contributor Author

My apologies for my clumsy way to fix the merge conflict. I think all changes on my side should be fine now, so I'll refrain from touching git further and making things worse.

@MoonCoral MoonCoral changed the title Rename srand to Random.seed Rename srand to Random.seed! Jul 27, 2018
@rfourquet
Copy link
Member

I think all changes on my side should be fine now, so I'll refrain from touching git further and making things worse.

In the diff here, many unrelated changes still appear, so I'm afraid you may have to touch git a bit more!

@MoonCoral
Copy link
Contributor Author

I believe I managed to clean this up.

Copy link
Member

@rfourquet rfourquet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

state of the global RNG as it was before."
function guardsrand(f::Function, r::AbstractRNG=GLOBAL_RNG)
function guardseed(f::Function, r::AbstractRNG=GLOBAL_RNG)

This comment was marked as outdated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see that was already discussed. Never mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation This change introduces or involves a deprecation randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants