digitalmars.D.bugs - [Issue 7529] New: IFTI does not support aliases
- d-bugmail puremagic.com (30/30) Feb 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (15/15) Feb 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (16/16) Feb 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (12/21) Feb 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (7/7) Feb 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (18/18) Feb 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (8/25) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (10/10) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (7/7) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (14/14) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (17/17) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (9/9) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (24/24) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (14/14) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (26/52) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (10/31) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (7/20) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (13/14) Feb 17 2012 No it does not.
- d-bugmail puremagic.com (10/10) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
- d-bugmail puremagic.com (12/12) Feb 17 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7529
http://d.puremagic.com/issues/show_bug.cgi?id=7529 Summary: IFTI does not support aliases Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: kyfolee gmail.com DMD 2.058 template Type(T) { alias T Type; } void f(T)(T, Type!(T)) {} void main() { f(0, 0); // fail f!(int)(0, 0); // success } --- .\ifti_alias.d(6): Error: template ifti_alias.f(T) does not match any function template declaration .\ifti_alias.d(6): Error: template ifti_alias.f(T) cannot deduce template function from argument types !()(int,int) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 timon.gehr gmx.ch changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |timon.gehr gmx.ch Summary|IFTI does not support |IFTI does not support |aliases |template argument dependent | |template alias instances as | |parameter types Severity|normal |enhancement This is an enhancement, a very desirable one. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 dawg dawgfoto.de changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dawg dawgfoto.de The issue is what do you make of related cases. // not deducible void f(T)(Type!T) {} f(0); // ? void f(T)(Type!T, T) {} f(0, 0); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529The issue is what do you make of related cases. // not deducible void f(T)(Type!T) {} f(0); // ? void f(T)(Type!T, T) {} f(0, 0);Both of those should work. The enhancement demands special treatment of templated aliases. For example, this would work too: template LList(T){alias Lazy!(List!T)) LList;} alias f(T)(LList!T){} f(new LList); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 I meant void f(T)(LList!T){} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 The reason why this works with structs but not with templates is that a struct preserves the full type information while an alias template transforms a type. void bar(Ty)(Ty) { pragma(msg, Ty); } struct SList(T) {} template TList(T) { alias T TList; } void main() { bar(SList!int.init); // type SList!int => SList!int is preserved bar(TList!int.init); // type int => TList!int is lost } Now if you take a function void foo(T)(TList!T) {} and gives you 'TList(T) = int'. What your asking for is an inverted template 'TList^-1(int) = T'. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529The reason why this works with structs but not with templates is that a struct preserves the full type information while an alias template transforms a type. void bar(Ty)(Ty) { pragma(msg, Ty); } struct SList(T) {} template TList(T) { alias T TList; } void main() { bar(SList!int.init); // type SList!int => SList!int is preserved bar(TList!int.init); // type int => TList!int is lost } Now if you take a function void foo(T)(TList!T) {} and gives you 'TList(T) = int'. What your asking for is an inverted template 'TList^-1(int) = T'.Well, yes. But only for a simple set of cases where this is workable. Basically the alias would need to be expanded before IFTI matching. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 void foo(T)(Unsigned!T val) { } foo(2u); ??? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 Unsigned is not an alias template. Your example is unrelated to this enhancement. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 I think this is invalid issue. Reduced case: void f(T)(T, T) { pragma(msg, T); } void main() { f(0L, 0); // first argument is long, and second one is int // Error: template test.f(T) does not match any function template declaration } In IFTI, arguments don't have any dependencies each other about the deduction. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 ---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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529OK?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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529MidAir 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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529IFTI 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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 Steven Schveighoffer <schveiguy yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |schveiguy yahoo.com 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: -------
Feb 17 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529 timon.gehr gmx.ch changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |DUPLICATE 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: -------
Feb 17 2012