Skip to content

Conversation

WebDrake
Copy link
Contributor

This is an instance of Issue 2803, a clash between a template parameter and a default argument. With no general solution on the horizon for that bug, I've used the workaround proposed in that issue thread:
http://d.puremagic.com/issues/show_bug.cgi?id=2803#c1

Tests have been included to ensure that these functions work with all possible RNG types. If this style of testing is considered useful I propose extending it to all functions that make use of RNGs.

don't work with Xorshift.

This is an instance of Issue 2803, a clash between a template
parameter and a default argument.  I've used the workaround
proposed in that issue thread:
http://d.puremagic.com/issues/show_bug.cgi?id=2803#c1

Tests have been included to ensure that these functions work
with all possible RNG types.
@@ -112,6 +112,12 @@ version(unittest) import std.typetuple;
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/

version(unittest)
{
alias TypeTuple!(MinstdRand0, MinstdRand, Mt19937, Xorshift32, Xorshift64, Xorshift96,
Copy link

Choose a reason for hiding this comment

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

You should move this inside the unittest block where it's used, or it might conflict with user symbols when they compile with -unittest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that this TypeTuple be available to all unittest blocks so that they (and any dependent modules) can all do similar foreach() runs over all the available set of RNGs. I have a further patch in the pipeline which will extend that kind of testing to all std.random unittests, but I've withheld it for now as it's probably a good idea to wait until after pull request #1357 lands.

I could move the TypeTuple inside the randomShuffle unittest block for now and move it out again when the later patch is submitted -- your call. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, would it be better to make it a global symbol that's not dependent on compiling with -unittest?

Copy link

Choose a reason for hiding this comment

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

In that case make it global but also add a ddoc comment (and I recommend using the syntax alias PseudoRngTypes = TypeTuple!(...)).

Copy link
Collaborator

Choose a reason for hiding this comment

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

In any case, even Inside a version(unittest) block, please make it package or private, or you could polute user unittest code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One possible reason to leave it inside a version(unittest) block -- it avoids having to import std.typetuple for non-unittest builds.

Copy link

Choose a reason for hiding this comment

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

unittest-based imports are error-prone. There was a problem in Phobos recently where an import was inside of a version(unittest) block, but because Phobos is never tested without the -unittest switch nobody caught a bug where compiling a user project which imported the module and where the user didn't have the -unittest switch caused the compilation to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll make std.typetuple a regular import and remove the version(unittest) block around PseudoRngTypes. Would be interested to have a link to the bug you mention.

Copy link

Choose a reason for hiding this comment

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

Ah, I've mis-remembered what exactly it was about. Here's the bug:

http://d.puremagic.com/issues/show_bug.cgi?id=9269

Essentially someone added a version(unittest) import into a module which had a pragma(lib) call for the linker, leading to cases where the user could compile the code if they didn't use -unittest, but it would fail compilation if the user used -unittest but didn't have curl installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, in that case I will keep the version(unittest) blocks, using the package alias ... formulation to make sure that it never clashes with anything outside std.random and documenting it with a comment rather than a ddoc section. Unless you specifically want me to do something else, in which case ... I'll do whatever you ask for. :-)

@WebDrake
Copy link
Contributor Author

Will this do? Or would you still prefer the version(unittest) brackets to be removed?

@WebDrake
Copy link
Contributor Author

WebDrake commented Jul 2, 2013

.... ping? :-)

@WebDrake
Copy link
Contributor Author

WebDrake commented Jul 5, 2013

My testing demon is striking again. Anyway, re-ping? :-)

@ghost
Copy link

ghost commented Jul 5, 2013

Yeah it's good, let's just wait for the tester to pass.

@WebDrake
Copy link
Contributor Author

... ping? Seems an opportune time after #1403 got pulled :-)

@WebDrake
Copy link
Contributor Author

Ping again? It's now 3 weeks since the final version was uploaded, and it's now simply stuck on low priority in the autotester.

@WebDrake
Copy link
Contributor Author

I'm considering splashing out on the machine that goes 'ping' :-)

ghost pushed a commit that referenced this pull request Jul 15, 2013
Fix Issue 9607 - std.random.randomShuffle() and partialShuffle() don't work with Xorshift.
@ghost ghost merged commit 443b54e into dlang:master Jul 15, 2013
@ghost
Copy link

ghost commented Jul 15, 2013

Yeah. Btw, if you want to force a re-test usually what you do is just amend your last commit so it ends up having a new hash, then force push and the autotester will run from scratch.

@WebDrake
Copy link
Contributor Author

Thanks Andrej :-) I considered doing that, but TBH it seems ill-mannered to jump the queue. Anyway -- thank you again for the merge!

@WebDrake WebDrake deleted the randomshuffle branch July 15, 2013 22:18
@ghost
Copy link

ghost commented Jul 15, 2013

Well unfortunately there are no 'pull went green' notifications, otherwise I'd pull this sooner.

This pull request was closed.
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.

2 participants