Asking for the opinion of DMD developers

Stefanos Baziotis sdi1600105 at di.uoa.gr
Sun Oct 13 18:21:29 UTC 2019


On Sunday, 13 October 2019 at 15:06:11 UTC, Elie Morisse wrote:
>
> This is because DMD's current implementation of template 
> argument deduction isn't advanced enough to cover this case, 
> but it could be improved to cover it.
>

Yes, the problem though is that DMD developers could not cover it,
so the DIP was introduced to help.

> Regarding C++, C++ template argument deduction is more 
> "sophisticated" but also has its limits, maybe to keep the 
> complexity of the implementation at an acceptable level.
> An example of C++ template function that doesn't work with the 
> rules of C++ template argument deduction is 
> std::forward<T>(std::remove_reference_t<T>& t) (see 
> https://en.cppreference.com/w/cpp/utility/forward), C++ 
> compilers cannot deduce T by matching the argument type to 
> std::remove_reference<T>. Thus std::forward can only be used 
> with an explicit template argument.

I didn't know that, interesting.

>
> The C++ equivalent of your example does work, but alias 
> templates are different in C++ and D. In C++ they only alias 
> types, while in D there is no concept of alias template, your 
> AliasTemplate may have one or more overloads that instantiate a 
> variable or some other kind of symbol completely unrelated to 
> aliases.
> So C++ has it easier and the paragraph you quoted from the spec 
> makes argument deduction possible by first substituting the 
> function parameter by a "dummy instantiation of 
> AliasTemplate<T>". A similar solution wouldn't be easy to 
> implement in DMD for the aforementioned reasons, but it may be 
> do-able.

I have some little experience with DMD, but not enough to
answer this fully. From a draft implementation I did, it seems
that for the simple case, it should be doable.
However, what you mentioned with the overloads etc. is 
interesting,
I'll refer to it again below.

>
> IMHO if not done yet you should submit a bugzilla issue with 
> your example and perhaps dive into DMD's code and try figuring 
> out a solution.

You can check the DIP I referenced above [1]. There are links to 
a draft
implementation and a lot of bugzilla reports.

> And unlike in C++ SomeAlias might have overloads that 
> instantiate something completely different :
> 
> template SomeAlias(T : char) { enum SomeAlias = 987; }
> template SomeAlias(T : int) { void SomeAlias() {} }

This is interesting in that a specification for alias templates 
as C++'s
may not be enough and an addition may actually help. TBH, I don't 
think though.
Because DMD currently can't handle even the simplest case.
I left the implementation and started the DIP when I stumbled 
upon problems
that didn't have to do with aliases but with template 
instantiation.
This is something that definitely should be able to be solved 
with the
current specification, yet it doesn't.

> A possible solution like C++'s, but taking into account the 
> multiplicity of TemplateDeclaration overloads would be:

Some of the things you mentioned are done but I don't remember 
wholly.
However, I get the idea.
Currently, I don't have time to work on the implementation though.
Consider that this was supposed to have ended by the end of May.
Unfortunately, it's unclear how much time will I have to do only 
the DIP work.
So basically, I can focus only on the specification side of 
things and
leave the implementation reasoning (i.e. whether the DIP will 
help with that,
how it can be done etc.) to the DMD developers.

Thanks for your input!
- Stefanos

[1] https://github.com/dlang/DIPs/pull/176




More information about the Digitalmars-d mailing list