Does dmd not always compile all of the source code?
Steven Schveighoffer
schveiguy at yahoo.com
Wed Dec 6 20:39:19 UTC 2017
On 12/6/17 2:19 PM, A Guy With a Question wrote:
> On Wednesday, 6 December 2017 at 18:09:45 UTC, Steven Schveighoffer wrote:
>> On 12/6/17 12:17 PM, Steven Schveighoffer wrote:
>>
>>> So why wouldn't the compiler fail? Because it has no idea yet what
>>> you mean by Nullable. It doesn't even know if Nullable will be
>>> available or not. You could even import Nullable, but Nullable!T may
>>> be an error.
>>
>> To give an example of why the compiler waits until instantiation:
>>
>> class C(T) : T
>> {
>> void foo() { doesthisexist(); }
>> }
>>
>> class D { void doesthisexist(); }
>>
>> auto x = new C!D; // OK
>> auto y = new C!Object: // fail
>>
>> -Steve
>
> It also doesn't parse or do semantic checks on unit tests unless you add
> the flag...apparently.
>
> This compiles...
>
> unittest
> {
> WHY DOESNT THE COMPILER FIND A PROBLEM HERE!?
> }
>
> It seems D's fast compile times are achieved by skipping semantic
> checking and even parsing when it doesn't feel it's needed.
This is a red herring. The compile times are fast even with unittests
enabled. They are just faster (and use less memory) when unittests
aren't compiled in.
If a unit test is instantiating tons of templates that I'm not using in
my main code, I don't want that being compiled and then thrown away when
I don't care about it!
> I strongly
> disagree with this decision. This could leave complex dormant time bombs
> that break builds unexpectedly and even accidentally.
This decision was made by reality. How do you compile incomplete code?
that is essentially what a template is.
In terms of unit tests that don't compile, I can't ever imagine someone
writing a unittest and then not compiling with -unittest, and being
upset their code "passed".
Note, this was done pretty recently, and simply to make the compiler
consume less memory (and run a bit faster).
> It's
> understandable in certain situations where there is enough information,
> but the first step to testing code, is first making sure it compiles...I
> don't want the compiler making decisions on what is worthy to compile.
The first step to testing code is writing tests. And the idea that the
compiler is making these decisions arbitrarily is incorrect. You are
telling the compiler how to compile.
> If I pass a d source file into it, I want to know if it's valid. This is
> unfortunate. This might be a deal breaker for me.
There is literally only one exception to the rule, unittests. Everything
else must be valid syntax-wise.
Even version statements must have valid syntax inside them.
Hardly a deal-breaker, since you aren't going to write unittests and
then not run them.
-Steve
More information about the Digitalmars-d-learn
mailing list