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

Restrict making of containers to non-infinite ranges #4860

Merged
merged 1 commit into from
Oct 13, 2016

Conversation

nordlow
Copy link
Contributor

@nordlow nordlow commented Oct 13, 2016

Model-checking that forbids construction of containers from infinite generators.

Copy link
Member

@MetaLang MetaLang left a comment

Choose a reason for hiding this comment

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

Looks good. I think there are many more places in Phobos where we should be checking for isInfinite, such as std.array.array... I've been burned more than a couple times because I forgot that the range being passed to various consuming functions is actually an infinite range. I have one suggestion, which is to add another unit test testing the positive case where the range is not infinite. You can never have too many unit tests after all.

Edit: sorry, I'm still getting used to the new review system.

import std.container.array : Array;
import std.range : repeat;
import std.range.primitives : isInfinite;
static assert(!__traits(compiles, { auto arr = make!Array(repeat(5)); }));
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to have the positive case tested as well. Something like:

static assert(__traits(compiles, { auto arr = make!Array(only(5)); }));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@MetaLang
Copy link
Member

Urgh, this is going to take some getting used to.

@MetaLang
Copy link
Member

I'm referring to the new Github review system. This is my first time using it and it's going to take some getting used to ;-)

@nordlow
Copy link
Contributor Author

nordlow commented Oct 13, 2016

Aha.

@nordlow
Copy link
Contributor Author

nordlow commented Oct 13, 2016

Two has approved...so why no merge?

@jmdavis
Copy link
Member

jmdavis commented Oct 13, 2016

Auto-merge toggled on

@nordlow
Copy link
Contributor Author

nordlow commented Oct 13, 2016

Thanks.

@nordlow
Copy link
Contributor Author

nordlow commented Oct 13, 2016

@MetaLang array() seems protected against infinite ranges. Any more functions that need to be qualified?

@MetaLang
Copy link
Member

Not sure, I'm guessing we'll just have to cross those bridges as we come to them. The only other functions I can think of at the moment are writeln et al. They'll happily take an infinite range and print out its elements forever.

@wilzbach
Copy link
Member

All checks have passed
5 successful checks

Seems like auto-tester has still now some troubles with automatically merging (it worked on a other PR), let's have an eye on this. I just deprecated one build which will hopefully trigger the merge soon.

@jmdavis jmdavis merged commit dd609e6 into dlang:master Oct 13, 2016
@schveiguy
Copy link
Member

It's possible another PR merged. Github doesn't have great sync with auto tester, it sometimes keeps old status.

@nordlow nordlow deleted the no-infinite-make branch October 13, 2016 23:20
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.

6 participants