Bye bye, fast compilation times

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Feb 7 01:54:58 UTC 2018


On Tuesday, February 06, 2018 17:20:04 H. S. Teoh via Digitalmars-d wrote:
> So I'd like to propose that we do something similar to what we did with
> template instantiations a couple of years ago: make it so that unittests
> are only instantiated if the module they occur in is being compiled,
> otherwise ignore them (even in the face of -unittest).  This way, adding
> unittests to Phobos won't cause unintentional slowdowns / unittest bloat
> across *all* D projects that import the affected Phobos modules. (Seen
> from this angle, it's a pretty hefty cost.)

Well, that sounds like a DIP is in order.

> Of course, this statement has to be qualified a bit: it's probably still
> a good idea to instantiate unittests inside templates -- since
> ostensibly they could be sanity-checking specific instantiations of
> templates. Though I'd argue that 90% of the time, their location inside
> a template is a mistake; they really should be outside templates and
> only instantiated once, because generally they test specific
> instantiations of the template rather than implement generic tests that
> apply across all template instantiations.

I agree that most of the time, unittest blocks inside templates shouldn't be
compiled with the template and that that mistake is made _way_ too often
(even in Phobos), but once in a while, it's actually desirable. I created a
DIP previously for using static to indicate that a unittest block inside a
template should not be treated as part of the template, but I haven't moved
it from the wiki to github, and Andrei pretty much told me that he though
that such a DIP was a waste of time and that I shouldn't continue with it.
He seems to think that the solutions involving using static ifs on all of
the unittest blocks and compiling them in with a specific instantiation only
are perfectly reasonable and that it's not worth adding anything to the
language for it. I don't agree, but I have no idea how to convince him.

Regardless, because some unittest blocks really should be compiled in with
every instantiation of a template (even if it's rare), I think that it's
clear that unittest blocks that are instantiated with a template should be
included in a program so long as any module that is specifically compiled
instantiates the template. It may be that the implementation would require
that they be there regardless, but even if that's true, not including the
non-templated unittest blocks which are not explicitly compiled in would
definitely be an improvement.

- Jonathan M Davis



More information about the Digitalmars-d mailing list