-
-
Notifications
You must be signed in to change notification settings - Fork 740
std.range package #2661
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
std.range package #2661
Conversation
ping authors (@jmdavis, @dsimcha) and @MartinNowak |
That's a really good idea. import std.range.concepts;
void foo(R)(R r) if (isForwardRange!R)
{
import std.range; // import rest
copy(r.retro, r);
} |
There is only one change (except imports and There are few links in comments, that can be broken. I will check them. But comments checks can be done after merge. So there is main thing to review: |
This is something I tried to do long ago, so it's awesome to see this idea implemented. I would warn about using selective imports at global scope, these still create a bunch of aliases and thus leak symbols out of module. (I might be wrong, just check if any of them are accessible outside of std.range) |
Very nice! Let's get this into shape for merging, and then we should start looking into splitting up For that latter case, since it's so huge, maybe we can do it piecemeal instead of all in one go. (I've tried to do it in one go before, but the effort involved is too much for a single PR and besides risks conflicts with other std.algorithm PRs that may get merged in the meantime.) The easiest pieces to handle are those functions that are frequently used throughout Phobos, like |
I think name |
|
Probably What about separating stuff like |
|
@@ -1750,28 +1750,28 @@ if (isNativeOutputRange!(R, E)) | |||
{ | |||
if (c <= 0x7F) | |||
{ | |||
doPut(range, cast(char) c); |
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.
There was a reason for doPut
here over put
. Why did you feel this needed change?
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.
doPut was package
function, but it was not accessible from std.encoding
. It was accessible only from std.range.*
since it in std.range.constraints
.
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.
Edit: Hum... actually, you kept the isNativeOutputRange
, so that works. Never mind, cary on.
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.
doPut was package function, but it was not accessible from...
That alone doesn't justify the change though, they don't have the same semantics! But in this case, it still works.
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, I checked it )
I'm still not a huge fan of having "put" or "moveFront" be part of "constraints". I'd have loved to have a those in "concept", which might have actually publicly included "constraints". More often that not, you don't need these functions for constraint checking. If you start writting @Dicebot suggested calling |
|
||
@safe unittest | ||
version(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.
Oh, shit. Don't do this. If somebody misses a dependency in code, all unittests will pass, we will ship it, and clients' code won't compile. It's happened before it is an awful kind of bug.
Use a mixin if you must, but please avoid "version(unittest)" in global space at all cost.
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.
Fixed, see my last comment #2675
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'm not sure how it's fixed? We still have global imports that are only included in unittests. We are currently unable to catch an error where code that depends on these failed to do a proper import.
IMO, this is worst than an unconditional import.
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 imports have been fixed in #2675.
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'm not talking about the imports. They may or may not be correct. Heck, it's not about the imports, it's about the functions that depend on them.
The issue is that we currently aren't covering whether or not our standard non-unittest functions have the correct imports. As it stands, especially with your imports cleaning, we have absolutely no way to know if any of these functions in range had an actual dependency on algorithm, which you forgot to locally include. Or somebody else in the future might write a function that requires std.algorithm.
We will fail to compile for literally every client, and not even see it.
It should be kept as simple global import, or scoped import. version(unittest)
is evil and dangerous.
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.
Move dummy ranges into std/internal/unittest/dummyrange.d
: see #2691
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.
version(unittest)
is a huge headache ...
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.
Proof? You can just make the imports unittest-local, can't you?
Not always. If you have some additional symbols / function shared by unittest blocks there is no place to put imports for those other than in same version(unittest)
block. However second proposal for requiring forced namespace hygiene may be enough to address 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.
If these "additional symbols / function shared by unittest blocks" only make sense for unittests, then version(unittest)
is not that much of a problem, since actual code can't "accidently" depend on those.
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.
stuff from version(unittest)
scope accessible from all functions.
Very good work. Sorry for being late for the review. I think there might still be some issues to discuss, but the overall change is nice. And I think at this point, merge than argue is a better approach. We still have until the next release to tweak. |
I agree that it is sub-optimal to keep those with constraints but concepts are completely irrelevant here. Those primitives simply provide default range implementations for existing types (though you are right that that does not imply UFCS). |
I think that should still be done for a cleaner package structure. |
But when you use |
Sure, but you can |
Ping any other collaborator to confirm suggestion "rename |
I think on the forum we agreed on |
Or maybe we can have both, with template constraints in |
Please split two questions:
@quickfur Can you give a link to forum discussion? |
Sorry, I use the mailing list interface so I didn't think to post the forum link. Here it is: http://forum.dlang.org/thread/mailman.1974.1415943181.9932.digitalmars-d@puremagic.com |
OK. There is three variants:
Collaborator, please select one! @MartinNowak (update) @monarchdodra and @Dicebot want to split.
Please do not split module for beautiful names. |
Oh, I'm not arguing for I also think |
@klickverbot I got it from forum.Voting list is updated. |
No, we split modules so that people reading the docs or contributing code know where to find stuff and having |
@9il It's not true that when you use The way I see it, the split should more-or-less be along the same (or similar) lines as the current
|
Oh, and BTW, there's something else that needs to be cleaned up before the next release: https://issues.dlang.org/show_bug.cgi?id=13766 |
@quickfur |
Yes I just saw that, that's why I edited my comment. :-) |
So I will rename current |
Sounds good. |
@quickfur: Imho not including the array -> range adapters in the same module as the range traits is quite dangerous, because you need to import the former too so that generic code using Incidentally, this is also the reason why I think it's a mistake to keep the additional helpers like |
I agree that the further layout can be discussed in a separate PR, though. |
@klickverbot I agree with your points. So we should put array primitives and range traits together in |
Sounds like a plan. |
Renamed, see #2765 |
Needs #2684.Issue 13253 - use more scoped imports in phobos
Please, freeze all other std.range commits!
Known PR that should be blocked:
fix Issue 12409 - Add "each" function as found in Ruby and jQuery #2024(only one comment line, can be merged)std.range
Contains D ranges (zip, iota etc.).
Global imports
std.range.constraints
Contains range
has*
,is*Range
primitives and convenience functions formanipulating ranges (like
put
).Global imports
I think the next PR will move
empty, save, popFront, popBack, front, back
intostd.range.constraints
.The reason is to don't import
std.array
globally to all Phobos modules.std.range
\std.range.constraints
is imported instd.array
anyway.All scoped imports
std.range.interfaces
Contains interfaces and classes.
Global imports
All scoped imports
See also: #2765