Folding similar templates into one
Meta
jared771 at gmail.com
Fri Jun 28 05:55:01 PDT 2013
On Friday, 28 June 2013 at 12:45:22 UTC, Marco Leise wrote:
> Am Thu, 27 Jun 2013 23:24:48 +0200
> schrieb "Meta" <jared771 at gmail.com>:
>
>> I'm not an expert on how DMD works, but could this possibly be
>> done after the native code is generated
>
> I've thought of that as well, but you have to merge templates
> at an earlier stage. In case of a compiler such as GCC, the
> native code is not even generated in the compiler, but an
> external assembler.
> That said, DMD does not create duplicate template instances
> for the same parameters. I'd assume this includes "string
> lambdas".
That's good to know. I wasn't sure if there were some cases when
template were ellided or not, even with the same arguments. By
string lambdas, I mean lambdas of the form sort!"a <= b" that are
heavily used in std.algorithm.
> And I'm not sure what you really want to improve for
> assertNotThrown. It is a unit testing function and the most
> important thing at the moment seems to keep DMD's memory
> consumption low, which more compile-time parameters can only
> increase.
I was only using assertNotThrown as an example of a template
function where parameters that could be compile-time arguments
become run-time arguments to minimize template bloat.
> Another point is that today's best compilers are good at
> detecting compile-time constants already and could inline a
> function with runtime parameters that are statically known.
> I've once let DMD create a switch-case with 81 cases for me
> and used a 100% templated function specialized for all these
> cases. The result was a major slow-down from all the
> compile-time arguments. Run-time arguments are just better!
That is certainly a corner case. Perhaps finding a way to fold
templates in some cases would still provide benefits in more
normal cases.
More information about the Digitalmars-d
mailing list