View mode: basic / threaded / horizontal-split · Log in · Help
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #10 from timon.gehr@gmx.ch 2012-02-17 07:20:59 PST ---
If you think it is invalid you misunderstand the issue. This is about extending
IFTI so that it can match templated aliases.

template Alias(T){ alias Foo!T Alias;}

void foo(T)(Alias!T x){ pragma(msg, T); }

foo(Foo!int); // prints 'int'

What effectively would need to be done at the compiler side:

- If a template parameter type is a template, check whether it is an eponymous
alias template (like template Alias(T){ alias Foo!T Alias; }
- If so, expand the template without knowing the type it is instantiated with

void foo(T)(Alias!T x){ ... } => void foo(T)(Foo!T x){ ... }

This is always a valid transformation for eponymous alias templates.

This does not introduce any dependencies across parameters.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #11 from dawg@dawgfoto.de 2012-02-17 07:25:35 PST ---
Is that what you mean by alias template.
template Wrap(T) { alias T Wrap; } // no members, no static if

This has a bidirectional mapping, but you can't change the type any longer.
'void foo(T)(Wrap!T val)' would always be equal to 'void foo(T)(T val)'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #12 from timon.gehr@gmx.ch 2012-02-17 07:35:44 PST ---
An alias template is like a function template, just for aliases.

Those are all alias templates:

template A(T){alias T A;}
template B(T){alias Foo!T B;}
template C(T){alias foo.bar.Qux!T C;}
template D(T){alias Foo!(Bar!(Qux!T)) D;}

Those are functions that use them:
void fooa(T)(A!T a){ ... }
void foob(T)(B!T b){ ... }
void fooc(T)(C!T c){ ... }
void food(T)(D!T d){ ... }

Those are the versions that do exactly the same thing but work with IFTI:
void fooa(T)(T a){ ... }
void foob(T)(Foo!T b){ ... }
void fooc(T)(foo.bar.Qux!T c){ ... }
void food(T)(Foo!(Bar!(Qux!T)) d){ ... }

What I am asking for is for IFTI to work the same for the former and latter
versions of the functions. This is easy to implement and matches what most
programmers would expect the language to be capable of.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #13 from dawg@dawgfoto.de 2012-02-17 07:47:33 PST ---
MidAir collision but thanks for the clarification.

Most of those cases can be handled by aliasing
the template declaration rather than the instance.

alias Foo Alias;
void foo(T)(Alias!T x){ pragma(msg, T); }
foo(Foo!int.init);

Which wouldn't work for recursion.
template D(T){alias Foo!(Bar!(Qux!T)) D;}

It seems to me that what you want is an AST macro not a template expansion.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #14 from Kenji Hara <k.hara.pg@gmail.com> 2012-02-17 07:59:59 PST ---
(In reply to comment #12)
> An alias template is like a function template, just for aliases.
> 
> Those are all alias templates:
> 
> template A(T){alias T A;}
> template B(T){alias Foo!T B;}
> template C(T){alias foo.bar.Qux!T C;}
> template D(T){alias Foo!(Bar!(Qux!T)) D;}
> 
> Those are functions that use them:
> void fooa(T)(A!T a){ ... }
> void foob(T)(B!T b){ ... }
> void fooc(T)(C!T c){ ... }
> void food(T)(D!T d){ ... }
> 
> Those are the versions that do exactly the same thing but work with IFTI:
> void fooa(T)(T a){ ... }
> void foob(T)(Foo!T b){ ... }
> void fooc(T)(foo.bar.Qux!T c){ ... }
> void food(T)(Foo!(Bar!(Qux!T)) d){ ... }
> 
> What I am asking for is for IFTI to work the same for the former and latter
> versions of the functions. This is easy to implement and matches what most
> programmers would expect the language to be capable of.

OK, I almost understand what you expects.

When the two declarations exist,
> template B(T){alias Foo!T B;}
> void foob(T)(B!T b){ ... }

and calling foob with IFTI like follows:
Foo!int x;
foob(x);  // foob(T)(B!T) is converted to foob(T)(Foo!T) 
         // *with expanding template B*, then foob deduces T as int.

OK?

-----
There is some problems about this enhancement.

1) This enhancement requires adding a phase to expanding eponymous templates
used as function parameter type. This makes IFTI process more complicate.

2) Some eponymous templates are not one liner.

template X(T) {
  template Y(U) { ... }  // massive type calculation
  alias Y!T X;   // also eponymous template
}
void foo(T)(X!T) { ... }

Should compiler calculate T from X!T? It is almost impossible!

If it only works with one-linear eponymous template, it is less benefit than
the semantic complexity.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #15 from timon.gehr@gmx.ch 2012-02-17 08:05:50 PST ---
(In reply to comment #14)
> 
> OK?
> 

Yes.

> -----
> There is some problems about this enhancement.
> 
> 1) This enhancement requires adding a phase to expanding eponymous templates
> used as function parameter type. This makes IFTI process more complicate.
> 

It can presumably be done while semantically analyzing the parameter types.

> 2) Some eponymous templates are not one liner.
> 
> template X(T) {
>    template Y(U) { ... }  // massive type calculation
>    alias Y!T X;   // also eponymous template
> }
> void foo(T)(X!T) { ... }
> 
> Should compiler calculate T from X!T? It is almost impossible!
> 

It shouldn't, because it *is* impossible.

> If it only works with one-linear eponymous template, it is less benefit than
> the semantic complexity.

I disagree. There is almost no semantic complexity.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #16 from timon.gehr@gmx.ch 2012-02-17 08:06:44 PST ---
(In reply to comment #13)
> MidAir collision but thanks for the clarification.
> 
> Most of those cases can be handled by aliasing
> the template declaration rather than the instance.
> 
> alias Foo Alias;
> void foo(T)(Alias!T x){ pragma(msg, T); }
> foo(Foo!int.init);
> 
> Which wouldn't work for recursion.
> template D(T){alias Foo!(Bar!(Qux!T)) D;}
> 
> It seems to me that what you want is an AST macro not a template expansion.

IFTI matching already works that way.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #17 from dawg@dawgfoto.de 2012-02-17 08:44:58 PST ---
>IFTI matching already works that way.
No it does not.

With IFTI and structs you recursively match template arguments.
Foo!(Bar!(Baz!T)))
Foo!(Bar!(Baz!int)))

With the alias you need to instantiate the template, probably using a bottom
type and then do the above.
Foo!(Bar!(Baz!(T))) => Result!T
Result!int

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529


Steven Schveighoffer <schveiguy@yahoo.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |schveiguy@yahoo.com


--- Comment #18 from Steven Schveighoffer <schveiguy@yahoo.com> 2012-02-17 12:52:32 PST ---
Is this not a duplicate of bug 1807?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
http://d.puremagic.com/issues/show_bug.cgi?id=7529


timon.gehr@gmx.ch changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|NEW                         |RESOLVED
        Resolution|                            |DUPLICATE


--- Comment #19 from timon.gehr@gmx.ch 2012-02-17 14:20:37 PST ---
Good catch.

*** This issue has been marked as a duplicate of issue 1807 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home