digitalmars.D.learn - Recursive expansion
- Henning Pohl (3/3) Aug 17 2012 I've ended up with a TypeTuple storing 1230 auto-generated types.
- Jonathan M Davis (10/13) Aug 17 2012 I believe that if a particular template is ever instantiated more than 5...
- bearophile (16/25) Aug 17 2012 I think currently the limit is 500 (time ago it was smaller, but
- Henning Pohl (10/32) Aug 17 2012 Damn, I just ran out of memory using ~ 550 types. DMD was
- bearophile (5/9) Aug 17 2012 Function pointers in a TypeTuple? Do you mean a Tuple? Can't you
- Henning Pohl (3/12) Aug 17 2012 Sorry, I meant function types like
- Philippe Sigaud (6/8) Aug 20 2012 I'm not sure how you can have dynamically-given functions and
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
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
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
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: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.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
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
On Friday, 17 August 2012 at 22:28:12 UTC, bearophile wrote:Henning Pohl:Sorry, I meant function types like void function(int i, string s)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
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