Fix issue 15853 - std.random save methods must be const#4136
Fix issue 15853 - std.random save methods must be const#4136PetarKirov wants to merge 3 commits intodlang:masterfrom
Conversation
|
|
Please add a unittest that verifies that the |
|
|
std/random.d
Outdated
| } | ||
|
|
||
| /// | ||
| @property typeof(this) save() @safe pure nothrow |
There was a problem hiding this comment.
Why are you removing @safe, pure, and nothrow? In none of the cases that you've changed here does whether the function can be @safe, pure, or nothrow depend on template arguments. So, there's no reason to remove them and every reason to have them.
There was a problem hiding this comment.
At first I started also adding @nogc, in addition to the other attributes, but then I thought that I should leave it to attribute inference, because the UintType could be a BigInteger with non-@nogc non-nothrow, etc. postblit)
There was a problem hiding this comment.
It cannot be BigInt. isUnsigned is only true for built-in types which are unsigned integer types, and that's what's used on UintType in the template constraints. So, please put back the attributes that you removed. And feel free to add @nogc if it works. None of those attributes are going to depend on whether the template argument is a ulong, uint, etc. If BigInt and other user-defined types were allowed, then yes, attribute inference would be needed, but they're not, so it's not.
There was a problem hiding this comment.
Ok, I'll add them back. I think I will make a pass over the whole module to add all possible attributes.
|
Yes. Please add a test verifying that a the result of |
|
I had to add some attributes, because otherwise I was getting the following errors: and: and |
std/random.d
Outdated
| { | ||
| import std.exception : enforce; | ||
| enforce(x0, "Invalid (zero) seed for " | ||
| x0 || assert(0, "Invalid (zero) seed for " |
There was a problem hiding this comment.
I changed this to assert, because it is a logic bug.
There was a problem hiding this comment.
Okay, but why are you ||ing instead of using assert(x0, ...)? That's not how assertions are normally used.
And since you changed it to an assertion, you can make the function nothrow.
There was a problem hiding this comment.
Remember that assert(0, …) (and assert(false, …) etc) are a special case of assert.
There was a problem hiding this comment.
Yes. They're a special case. They're used when they need to fail even in release mode, which is not the normal thing to do with assertions. It's for stuff like the default case of switch statement when it should never be hit or the catch statement that catches an exception that should never be thrown, but you have to catch it to make the function nothrow. It's not for validating function arguments.
There was a problem hiding this comment.
I'm okay with changing enforce with assert here although pedantically it's a breaking change. But no assert(0).
|
@quickfur, @jmdavis, the implicit conversion you're asking for is enshrined in the signature of LGTM. @ZombineDev, is that a failure of attribute inference? :O |
I would argue that
It looks like so. I will try to find a reduce test case. |
|
I agree that non-mutable range types are of very limited use, but by the same logic, surely this patch is also "useless". On the other hand, it's trivial and harmless to support |
Which is why that I argued that this PR is not necessarily a good idea. I'm not sure that it's a bad idea, but I seriously question that it makes sense to try and support const piecemeal like this. I tend to think that we should either find a solution for getting const and ranges to interact properly, or we shouldn't be mucking around with const and ranges. As long as const is pretty much useless with ranges, I'd argue that it's better for folks to realize that they shouldn't be used together rather than trying to get it to work in the corner cases where we happen to be able to get it to work at the moment. Add making |
|
Soo are we pulling this? |
andralex
left a comment
There was a problem hiding this comment.
OK, can we move forward with this?
|
Thanks for the ping, I'll find some time later today or tomorrow to address comments. |
|
Updated. I went into adding attributes to |
@ZombineDev your druntime PR has been merged, so we could move forward with this. Would you be so kind to rebase your work? |
|
Sure will do later this week |
Also add attributes to unpredictableSeed and a couple of unittests.
|
@ZombineDev Can you rebase and then ping me? |
|
ping @ZombineDev Rebase? |
|
ping @ZombineDev |
|
Ping @ZombineDev |
|
ping @ZombineDev @wilzbach Are we still moving forward with this PR, or should we close it? |
I removed the other attributes, because they are inferred.