-
-
Notifications
You must be signed in to change notification settings - Fork 411
Replaced version (unittest) with version (DRuntimeUnittest) to avoid unnecessary overhead when compiling with -unittest #2902
Conversation
|
Thanks for your pull request and interest in making D better, @alexandrumc! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + druntime#2902" |
|
I appreciate the focus on this, however maybe we should pause and consider how widespread this problem is likely to be. Any library is likely to suffer from this. I'm thinking Vibe.d, for example. Should the compiler blindly run Can we start to acknowledge this and move to a solution on the language level, rather than pushing the problem down to all libraries ? |
The compiler doesn't run module foo;
import std.smth;
unittest
{
import std.stdio : writeln;
writeln("Target unittest: ", a);
}
version (unittest)
{
int a = 10;
}
void main() {}module std.smth;
unittest
{
import std.stdio : writeln;
writeln("Dependency unittest: ", b);
}
version (unittest)
{
int b = 5;
}
|
|
@alexandrumc : Right, it doesn't do it for non-root modules. |
Sure, that's true. But by changing the |
Correct. This is why none of my own libraries have unittest blocks anywhere that client code could see.
No.
Yes. It's the standard library, it's the dependency.
The issue is semantic analysis, not actually running tests.
Yes. But for now this is easier. I need to discuss this with @WalterBright |
src/core/time.d
Outdated
|
|
||
| //To verify that an lvalue isn't required. | ||
| version (unittest) private T copy(T)(T t) | ||
| version (DRuntimeUnittest) private T copy(T)(T 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.
I believe you need to keep this because it is called from a templated unittest.
At least that's what the CI suggests:
/var/lib/buildkite-agent/builds/ci-agent-89c4044a-12c8-4cab-b953-c7a634bd4891-5/dlang/druntime/build/distribution/bin/../imports/core/time.d(2202,21): Error: undefined identifier `copy`, did you mean import `core`?
--
| /var/lib/buildkite-agent/builds/ci-agent-89c4044a-12c8-4cab-b953-c7a634bd4891-5/dlang/druntime/build/distribution/bin/../imports/core/time.d(2210,16): Error: undefined identifier `copy`, did you mean import `core`?
| /var/lib/buildkite-agent/builds/ci-agent-89c4044a-12c8-4cab-b953-c7a634bd4891-5/dlang/druntime/build/distribution/bin/../imports/core/time.d(2211,16): Error: undefined identifier `copy`, did you mean import `core`?
| /var/lib/buildkite-agent/builds/ci-agent-89c4044a-12c8-4cab-b953-c7a634bd4891-5/dlang/druntime/build/distribution/bin/../imports/core/time.d(2212,25): Error: undefined identifier `copy`, did you mean import `core`?
| /var/lib/buildkite-agent/builds/ci-agent-89c4044a-12c8-4cab-b953-c7a634bd4891-5/dlang/druntime/build/distribution/bin/../imports/core/time.d(2272,20): Error: undefined identifier `copy`, did you mean import `core`?
| /var/lib/buildkite-agent/builds/ci-agent-89c4044a-12c8-4cab-b953-c7a634bd4891-5/dlang/druntime/build/distribution/bin/../imports/core/time.d(2283,13): Error: undefined identifier `assertApprox`
| /var/lib/buildkite-agent/builds/ci-agent-89c4044a-12c8-4cab-b953-c7a634bd4891-5/dlang/druntime/build/distribution/bin/../imports/core/time.d(2004,18): Error: template instance `core.time.MonoTimeImpl!cast(ClockType)0` error instantiating
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 don't think that's actually a problem. I think that the -version=DRuntimeUnittest is somehow not passed to the compiler when unittests are compiled.
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.
Are the Makefiles used for testing exactly the ones that are located in phobos/? Are they different?
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.
For the record, I both of you are correct.
The root cause was that even though the function was used only from druntime's unit tests, they were nested inside the MonoTime template, which was instantiated from phobos, without passing -version=CoreUnittest. I solved this by guarding all nested (and undocumented) unit tests with version (CoreUnittest).
@atilaneves : Great, thanks. And happy to know you guys are working on improving compilation speed! |
wilzbach
left a comment
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.
CoreUnittest already exists! Besides only Core and Std are reserved version keyword prefixes.
8fc3345 to
8a0e873
Compare
|
I addressed the issues with @alexandrumc let's wait and see if the CI will be green, hopefully no further work on this PR will be necessary from you. |
It prevented removing all instances of `version (unittest)` from druntime as various nested unittest blocks were using `copy`, which under `version (CoreUnittest)` would not be visible from MonoTime instantiators, such as phobos. (See the next commit for additional details.)
To avoid unnecessary overhead when compiling with -unittest
8a0e873 to
df390c1
Compare
|
@alexandrumc @atilaneves @Geod24 @thewilsonator @wilzbach Please take another look. |
|
BTW, I just rembered about the discussion in this PR: dlang/phobos#6159. @atilaneves what's your take on it? Edit: after re-reading that discussion, I still think that using |
…ion (CoreUnittest)`
PetarKirov
left a comment
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.
@alexandrumc's changes look good to me.
Related to #2888 and #2896