www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Recursive expansion

reply "Henning Pohl" <henning still-hidden.de> writes:
I've ended up with a TypeTuple storing 1230 auto-generated types. 
Now the compiler claims there is a recursive template expansion. 
How to stir him from his resolve?
Aug 17 2012
parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Friday, August 17, 2012 23:45:49 Henning Pohl wrote:
 I've ended up with a TypeTuple storing 1230 auto-generated types.
 Now the compiler claims there is a recursive template expansion.
 How to stir him from his resolve?
I believe that if a particular template is ever instantiated more than 50 times recursively, the compiler will error out on the assumption that it's hit infinite recursion (it has to bottom out eventually, or would just end up running until it ran out of memory if it actually does hit infinite recursion; I don't know how arbitrary the choice of 50 was). So, the TypeTuple itself shouldn't be a problem (e.g. you should be able to use foreach on it just fine), but template instantiations will be a problem if you try and go through the whole TypeTuple recursively. - Jonathan M Davis
Aug 17 2012
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Jonathan M Davis:

 I believe that if a particular template is ever instantiated 
 more than 50
 times recursively, the compiler will error out on the 
 assumption that it's hit
 infinite recursion (it has to bottom out eventually, or would 
 just end up
 running until it ran out of memory if it actually does hit 
 infinite recursion;
 I don't know how arbitrary the choice of 50 was).
I think currently the limit is 500 (time ago it was smaller, but probably higher than 50): template Foo(int n) { enum Foo = Foo!(n + 1); } pragma(msg, Foo!0); void main() {} It gives: test2.d(2): Error: template instance test2.Foo!(500) recursive expansion The 500 limit is quite arbitrary. I like GCC, that defined a limit, but with -ftemplate-depth-n you are allowed to increase it to n. Bye, bearophile
Aug 17 2012
prev sibling parent reply "Henning Pohl" <henning still-hidden.de> writes:
On Friday, 17 August 2012 at 22:01:42 UTC, Jonathan M Davis wrote:
 On Friday, August 17, 2012 23:45:49 Henning Pohl wrote:
 I've ended up with a TypeTuple storing 1230 auto-generated 
 types.
 Now the compiler claims there is a recursive template 
 expansion.
 How to stir him from his resolve?
I believe that if a particular template is ever instantiated more than 50 times recursively, the compiler will error out on the assumption that it's hit infinite recursion (it has to bottom out eventually, or would just end up running until it ran out of memory if it actually does hit infinite recursion; I don't know how arbitrary the choice of 50 was). So, the TypeTuple itself shouldn't be a problem (e.g. you should be able to use foreach on it just fine), but template instantiations will be a problem if you try and go through the whole TypeTuple recursively. - Jonathan M Davis
Damn, I just ran out of memory using ~ 550 types. DMD was flooding my 8GB RAM like in 5 seconds. Fortunately I could kill DMD just in time. So there have to be another solution. I want to store lots (~615) dynamically loaded function pointers in a class and call them using opDispatch. To provide a type-safe function call, the types of the functions have to be stored somewhere, in a TypeTuple. Maybe you can help me how this could be done.
Aug 17 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Henning Pohl:

 I want to store lots (~615) dynamically loaded function 
 pointers in a class and call them using opDispatch. To provide 
 a type-safe function call, the types of the functions have to 
 be stored somewhere, in a TypeTuple.
Function pointers in a TypeTuple? Do you mean a Tuple? Can't you use an array? Bye, bearophile
Aug 17 2012
parent reply "Henning Pohl" <henning still-hidden.de> writes:
On Friday, 17 August 2012 at 22:28:12 UTC, bearophile wrote:
 Henning Pohl:

 I want to store lots (~615) dynamically loaded function 
 pointers in a class and call them using opDispatch. To provide 
 a type-safe function call, the types of the functions have to 
 be stored somewhere, in a TypeTuple.
Function pointers in a TypeTuple? Do you mean a Tuple? Can't you use an array? Bye, bearophile
Sorry, I meant function types like void function(int i, string s)
Aug 17 2012
parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
On Sat, Aug 18, 2012 at 12:30 AM, Henning Pohl <henning still-hidden.de> wrote:
 Sorry, I meant function types like

 void function(int i, string s)
I'm not sure how you can have dynamically-given functions and statically-determined types? Did you try to either fuse the repeated types (that is, getting a set and not a tuple) and pointing to the correct type anyway? Or, you can try to divide your tuple into smaller stores of, say, 256 types.
Aug 20 2012