-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Enable runnable examples - remove the last modules from the blacklist #5607
Conversation
std/experimental/allocator/common.d
Outdated
| @@ -92,13 +92,14 @@ size_t goodAllocSize(A)(auto ref A a, size_t n) | |||
| Returns s rounded up to a multiple of base. | |||
| */ | |||
| @safe @nogc nothrow pure | |||
| package size_t roundUpToMultipleOf(size_t s, uint base) | |||
| size_t roundUpToMultipleOf(size_t s, uint base) | |||
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.
This exposes roundUpToMultipleOf to the docs, it's used in many of the building blocks and the documented examples in quantizer needs it. An alternative would be to use a more simplistic Quantizer than:
alias MyAlloc = Quantizer!(
FreeTree!GCAllocator,
n => n.roundUpToMultipleOf(n <= 16_384 ? 64 : 4096));
``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.
I made it package-visible because it's in the wrong place. Once we expose it we'll need to do it forever. It should be shuttled to the right place. I'd say put it in std.numeric. Other possible candidates: std.conv, std.math.
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.
Also, it's much less generic than it could and should be because there wasn't a need. Once we expose it as a public primitive, the requirements change. It probably needs to accept any two unsigned types.
| @@ -930,7 +930,7 @@ $(D rawRead) always reads in binary mode on Windows. | |||
| { | |||
| static import std.file; | |||
|
|
|||
| auto testFile = testFilename(); | |||
| auto testFile = std.file.deleteme(); | |||
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.
Not a huge fan of this, but deleteme is the "defacto" standard within Phobos and used in many other public examples.
| @@ -7721,13 +7732,13 @@ template getSymbolsByUDA(alias symbol, alias attribute) | |||
| static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[0], Attr)); | |||
| } | |||
|
|
|||
| /// | |||
| // | |||
| @safe unittest | |||
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.
Access to private members is not possible with getSymbolsByUDA - the test only works it's in the same module.
Bug report
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.
I suggest moving out the bad parts of the unit test rather than hiding the entire test.
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.
I read the issue 17643 I agree with @CyberShadow that we should leave this in a private unittest, until we reach a consensus about whether access to private members should be allowed. (I think one should be able to get the attributes of private members at least in the same module, though that's not what this unittest tested..)
That is excessive. I hoped this feature would be a little smarter and disable itself when it would otherwise ping more than 3-5 people. |
|
The std.stdio changes are fine by me. I guess we never decided if we want to make |
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.
We need to make sure published functions get due treatment. How about for now you just inline the rounding code in examples therefore making roundUpToMultipleTo unnecessary?
std/experimental/allocator/common.d
Outdated
| @@ -92,13 +92,14 @@ size_t goodAllocSize(A)(auto ref A a, size_t n) | |||
| Returns s rounded up to a multiple of base. | |||
| */ | |||
| @safe @nogc nothrow pure | |||
| package size_t roundUpToMultipleOf(size_t s, uint base) | |||
| size_t roundUpToMultipleOf(size_t s, uint base) | |||
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.
I made it package-visible because it's in the wrong place. Once we expose it we'll need to do it forever. It should be shuttled to the right place. I'd say put it in std.numeric. Other possible candidates: std.conv, std.math.
std/experimental/allocator/common.d
Outdated
| @@ -92,13 +92,14 @@ size_t goodAllocSize(A)(auto ref A a, size_t n) | |||
| Returns s rounded up to a multiple of base. | |||
| */ | |||
| @safe @nogc nothrow pure | |||
| package size_t roundUpToMultipleOf(size_t s, uint base) | |||
| size_t roundUpToMultipleOf(size_t s, uint base) | |||
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.
Also, it's much less generic than it could and should be because there wasn't a need. Once we expose it as a public primitive, the requirements change. It probably needs to accept any two unsigned types.
I thought the same ... according to their docs:
|
bb4921f to
92e319f
Compare
| @@ -2751,8 +2751,7 @@ if (isFloatingPoint!T) | |||
| int exp; | |||
| real mantissa = frexp(123.456L, exp); | |||
|
|
|||
| // check if values are equal to 19 decimal digits of precision | |||
| assert(equalsDigit(mantissa * pow(2.0L, cast(real) exp), 123.456L, 19)); | |||
| assert(approxEqual(mantissa * pow(2.0L, cast(real) exp), 123.456L)); | |||
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.
I'd have to check this on a target that demanded it.
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.
You don't need to, I moved the test to an internal unittest. This change is just needed because approxEqual isn't a public symbol and would error when run online (or wherever the user tries to run the example).
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.
Yes, but does it pass on ARM? Or any other real==double target for that matter?
If equalsDigit and approxEqual are sufficiently the same, then there's no problem. :)
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.
If equalsDigit and approxEqual are sufficiently the same, then there's no problem. :)
approxEqual (used for the public examples) is much weaker, than equalsDigit. approxEqual checks by a difference of 1e-5 by default, whereas the equalsDigit tests here are by a precision of 1e-19.
| @@ -3601,6 +3609,11 @@ real log2(real x) @safe pure nothrow @nogc | |||
| /// | |||
| @system unittest | |||
| { | |||
| assert(approxEqual(log2(1024.0L), 10)); | |||
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.
Actually, why are you testing with both approxEqual() and equalsDigit(19)?
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.
equalsDigit is private, that's why I copied the test to a separate unittest and inserted approxEqual instead
Well it's better than not having public tests or having public ones that aren't working for the tests. So is anything blocking this then? @CyberShadow we really have an issue with our CIs. Sometimes even everything is red, despite having "good" changes: |
Yep. Turns out continuous integration is hard. Who would have guessed? :) |
92e319f to
6f48f83
Compare
6f48f83 to
56e9e6d
Compare
|
As the GH issues have been resolved, this should be finally good to go. |
| @@ -2684,7 +2686,7 @@ private template hasRawAliasing(T...) | |||
| enum hasRawAliasing = Impl!(RepresentationTypeTuple!T); | |||
| } | |||
|
|
|||
| /// | |||
| // | |||
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.
Why are we undocumenting useful example blocks?
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.
Because hasRawAliasing is a private symbol -> https://github.com/dlang/phobos/blob/v2.076.0/std/traits.d#L2661
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.
Oh, OK. So this was an "example" for a private symbol.
| @@ -7721,13 +7732,13 @@ template getSymbolsByUDA(alias symbol, alias attribute) | |||
| static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[0], Attr)); | |||
| } | |||
|
|
|||
| /// | |||
| // | |||
| @safe unittest | |||
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.
I suggest moving out the bad parts of the unit test rather than hiding the entire test.
56e9e6d to
fce9f42
Compare
Done - the other public unittest that I removed in std.traits was from a private symbol. Anything else or can be get this in before 2.077? Would be great because then we can finally enable "runnable examples" for all modules on dlang.org |
fce9f42 to
41de215
Compare
|
so? |
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.
Apart from what I've commented on , everything looks good.
| @@ -114,8 +114,7 @@ struct FreeList(ParentAllocator, | |||
| _max = high; | |||
| } | |||
|
|
|||
| /// | |||
| @safe unittest | |||
| @system unittest | |||
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.
I wonder why it worked with @safe before?
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.
Because it was never executed, see the comment about unittest blocks in templates before. By moving the unittest to the module level, this unittest was executed for the first time...
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.
Quite unfortunate. Thanks for the clarification.
| a.setBounds(64, 128); // equivalent | ||
| assert(a.max == 128); | ||
| assert(a.min == 64); | ||
| } |
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.
What's the reason for moving the unit test to module level? Is it because the test extractor cannot handle unit tests for member functions? I don't like this change as now the example won't show immediately after the function, but on rather different place (especially with the ddox layout).
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.
A unittest in a template will be part of every instantiation, they shouldn't have been there in the first place.See DIP82 for a more detailed description of the problem.
Also note that the unittest will still be associated with its struct.
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.
This can be worked around via static if (doUnittest) (see e.g. https://github.com/libmir/mir-algorithm/blob/e590f7f46058588f1ceb08672c92bd6248863e18/source/mir/ndslice/slice.d#L737).
Essentially you need to make sure that doUnittest is true for a single set of template arguments and that you have a template instance with those arguments (e.g. used in a private unittest).
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.
(If you don't want to deal with this now, we can leave it for later.)
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.
This can be worked around via static if (doUnittest)
Considering that the test didn't compile until now (in case you didn't notice, the moved out version is different - it doesn't set the bounds twice as this is prohibited), I was merely trying to get things to work, s.t. we can finally move forward with the runnable examples ;-)
Regarding the static if (doUnittest): I am aware of this pattern (even the old std.experimental.ndslice used this), but AFAIK that has been the only occurrence of this pattern in Phobos.
Anyways, there are still plenty of unittests in templated structs/classes, so I would strongly prefer if such a general cleanup is done in a later PR...
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.
Fair enough
| assert(a.approxMaxLength == 1024); | ||
| a.approxMaxLength = 1; | ||
| assert(a.approxMaxLength == 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.
ditto
| @@ -7721,13 +7732,13 @@ template getSymbolsByUDA(alias symbol, alias attribute) | |||
| static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[0], Attr)); | |||
| } | |||
|
|
|||
| /// | |||
| // | |||
| @safe unittest | |||
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.
I read the issue 17643 I agree with @CyberShadow that we should leave this in a private unittest, until we reach a consensus about whether access to private members should be allowed. (I think one should be able to get the attributes of private members at least in the same module, though that's not what this unittest tested..)




After quite a bit of work, we are heading for an end :)
This PR removes the last five modules from the runnable blacklist, s.t. with 2.076 all unittests are runnable
(FYI: the effort started in #4943)
For some modules, I wasn't sure sure on the best approach and I will mark these bits individually.