B Revzin - if const expr isn't broken (was Re: My Meeting C++ Keynote video is now available)

Stefan Koch uplink.coder at googlemail.com
Thu Jan 17 23:50:11 UTC 2019

On Thursday, 17 January 2019 at 22:44:08 UTC, H. S. Teoh wrote:
> On Thu, Jan 17, 2019 at 10:20:24PM +0000, Stefan Koch via 
> Digitalmars-d-announce wrote:
>> P.S. There is one caveat: because of how type-functions work 
>> they cannot, you cannot create a non-anonymous symbol inside a 
>> type-function, because there is no way to infer a mangle.
>> You can however create an anonymous symbol and alias it inside 
>> a template body, which gives it a mangle and it can behave 
>> like a regular symbol.
> Interesting.  Is it possible to assign a "fake" mangle to type 
> functions that never actually gets emitted into the object 
> code, but just enough to make various internal compiler stuff 
> that needs to know the mangle work properly?

No this is not possible, a symbol which is only used at 
compile-time is actually really rare. Actually If the symbol is 
constrained to a compile-time only context (e.g. inside is() or 
taking the .sizeof) this problem does not arise, and it could be 

Imagine you want to return a struct type  which has all the 
fields of a given base struct but adds a member.
>> module ct_helper;
> alias f(alias baseT, alias newMemberType, string newMember_name)
> {
>    struct Extended
>    {
>        baseT base;
>        mixin("newMemberType " ~ newMemberName);
>    }
>    return typeof(Extended.init);
>> module user
struct S1 { int x; }
alias S2 = f!(S1, float, "y") // looks like a 
template-instantiation but it's not!, I am just reusing it, to 
not confuse the parser to much.

which mangle should this get?
S2 ?  - doesn't work there is no mangle for an alias.
  ct_helper.f.Extended? doesn't work if we call the type-function 
again with diffrent arguments
make it an anonymous type ? - If we do that than this means that 
the type-function is no longer pure as two anonymous types can 
never Equal each other

include the arguments to the type-function and it's parameters in 
the mangle? - that's possible but type-functions are not meant to 
leave any sign of their existence in order to not introduce ABI 

In short for now I'd rather side-step the problem by not allowing 
freshly minted types to escape into a runtime context without 
going through a template wrapper (which also handles caching and 
has proper behavior in is-expressions).

More information about the Digitalmars-d-announce mailing list