493 – Partial IFTI does not work

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 493 - Partial IFTI does not work
Summary: Partial IFTI does not work
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 enhancement
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks: 1856
Show dependency tree / graph
Reported: 2006年11月09日 22:21 UTC by Bill Baxter
Modified: 2014年02月15日 13:21 UTC (History)
0 users

See Also:


Attachments
Patch to backport partial IFTI to dmd. Against llvmdc's dmd frontend. Should be similar to dmd 1.033. (2.45 KB, patch)
2008年08月09日 04:00 UTC, Christian Kamm
Details | Diff
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Bill Baxter 2006年11月09日 22:21:38 UTC
IFTI should try to deduce the parameter types for any template paramters not specified (if they don't have defaults).
--------
import std.stdio:writefln;
template foo(T,S)
{
 void foo(T t, S s) {
 writefln("typeof(T)=",typeid(typeof(T))," typeof(S)=",typeid(typeof(S)));
 }
}
template bar(T,S)
{
 void bar(S s) {
 writefln("typeof(T)=",typeid(typeof(T))," typeof(S)=",typeid(typeof(S)));
 }
}
void main()
{
 // OK -- IFTI works happily
 foo(1.0,33);
 // OK -- Full template parameters specified
 bar!(double,int)(33);
 // error: I gave it T and it should be able to use IFTI to guess S, but it doesn't
 //bar!(float)(33); 
}
---------------
Not sure if this should be a bug or an enhancement, but anyway, especially with the new variadic templates I think it will become more common to want to have a few specified paramters and let IFTI guess the rest.
 templatefunc(T, Var...)(Var v) {
 [...]
 }
 templatefunc!(SomeType)(a,b,c,d,e);
 This basically isn't usable if I have to specify all the types for a,b,c, and d.
Comment 1 Walter Bright 2008年02月20日 16:20:38 UTC
DMD 2.011 was enhanced to do this.
Comment 2 Bill Baxter 2008年02月20日 21:40:48 UTC
(In reply to comment #1)
> DMD 2.011 was enhanced to do this.
> 
And this isn't a bug in D1 because...?
As far as I can tell, the spec says only this about IFTI:
"""
Function templates can be explicitly instantiated ...
or implicitly, where the TemplateArgumentList is deduced from the types of the function arguments
"""
It doesn't say anything about only working when it's convenient or when the stars are aligned properly. The conclusion I draw is that any failure to deduce a type when the information required to deduce it is there is a bug.
Comment 3 Bill Baxter 2008年02月20日 21:46:32 UTC
By the way, that's great that it's fixed in D2.
I can confirmed that it does indeed work with 2.011 (but not with 1.075).
Comment 4 Bill Baxter 2008年03月06日 19:07:45 UTC
The new std.algorithm in DMD 2.011 uses this capability heavily.
That means porting std.algorithm to D1 is basically not practical as of D2.011. 
I'm really going to be bummed if you hold to the line that fixes like this are really "enhancements" that will not be ported to D1.
Comment 5 Sean Kelly 2008年05月18日 08:50:02 UTC
This is a bug in DMD 1.0 so I'm sure it will be fixed eventually. And since basically all real development is with D 1.0, I sincerely hope we don't have to wait forever. This ticket was originally filed in 2006. It would be nice if #1650 were fixed at some point as well, since a rather fundamental example in the D book requires it to work correctly.
Comment 6 Christian Kamm 2008年08月09日 04:00:50 UTC
Created attachment 267 [details] 
Patch to backport partial IFTI to dmd. Against llvmdc's dmd frontend. Should be similar to dmd 1.033.
I only did basic testing, but this patch seems to backport the D2 partial IFTI changes to D1.
Should this go into llvmdc proper though? If we start diverging from Walter's definition of D1 too much we'll essentially create a D 1.5... People using this feature on llvmdc couldn't switch back to dmd easily.
Comment 7 Leandro Lucarella 2008年11月13日 13:36:51 UTC
I don't think is a good idea either to make ldc as buggy as DMD just to be compatible =)
Comment 8 anonymous4 2008年12月01日 08:26:57 UTC
It's the very purpose of compatibility to replicate bugs.
Comment 9 Frits van Bommel 2008年12月01日 09:02:11 UTC
(In reply to comment #8)
> It's the very purpose of compatibility to replicate bugs.
No, the very purpose of compatibility is to replicate *features*!
Comment 10 Walter Bright 2008年12月25日 04:40:31 UTC
Added to dmd 1.038


AltStyle によって変換されたページ (->オリジナル) /