-
-
Notifications
You must be signed in to change notification settings - Fork 741
Minimized and explicit imports in std.algorithm #1339
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
Conversation
I have a bad gut feeling about shipping this as long as http://d.puremagic.com/issues/show_bug.cgi?id=314 is still not |
@klickverbot good point. Could one of the compiler experts take a look at http://d.puremagic.com/issues/show_bug.cgi?id=314? @WalterBright? @9rnsr? @donc @AndrejMitrovic? |
Looking at the imports, I'd think a lot of these are probably only needed in specific functions. Using scoped imports would allow for safer (avoids bug 314), and more efficient (import only if used) imports. In particular, I'm thinking about:
As for |
For a vanilla non-unittest import of std.algorithm, dependencies now are down from 55 to 31. To compute these numbers I ran:
|
I can't further reduce dependencies because some symbols are used in restricted template guards, which cannot be scoped. |
We should avoid imports in |
In this case 'AFAIK), the only place where it is used is followed by a |
@@ -1188,21 +1195,22 @@ Allows to directly use range operations on lines of a file. | |||
} | |||
} | |||
|
|||
import std.traits; |
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.
That's a rather odd place to place a fully qualified import. This should go at the top I think. No one will go looking for an import in the middle of the file.
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.
oops yes... shrapnel of various experiments.
314 isn't fixed yet, is it? I like this, but I'm afraid that if we merge this right now, we'll leak symbols, leading to users writing code with incorrect imports... For now, maybe we should leave the selective imports as global imports? |
std.traits, std.typecons, std.typetuple, std.uni, std.utf; | ||
import std.functional : unaryFun, binaryFun; | ||
import std.range; | ||
import std.traits; |
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's a couple extra localized import std.traits
you added in the code, which are useless with this import right here.
Presumably fixed Windows errors. |
passes tests, ping pliz pliz |
Minimized and explicit imports in std.algorithm
Unfortunately, this change silently breaks Phobos modules. Please see #1813 and merge it. |
I'm investigating semi-automated ways to minimize dependencies, and worked on std.algorithm by hand. I was unable to figure what's needed from std.range. For the others, I either pushed them down into unittests or made the symbols explicit.
One simple advice for Effective D would be:
"Avoid using
version(unittest) import xxx;
. Instead, useimport xxx;
inside every unittest that needs it."