D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3762 - Restrictive functionality for template instance recursive expansion
Summary: Restrictive functionality for template instance recursive expansion
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-31 14:30 UTC by Igor Lesik
Modified: 2015-06-09 01:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Igor Lesik 2010-01-31 14:30:04 UTC
How to reproduce:
template static_factorial(int n)
{
    static if (n == 1)
        const static_factorial = 1;
    else
        const static_factorial = n * static_factorial!(n-1);
}

void main()
{
    writefln("502!=%d", static_factorial!(502));

Error: template instance factorial.static_factorial!(2) recursive expansion

Max recursion depth 500 is hardcoded in template.c function TemplateInstance::semantic() line 3738 if (++nest > 500). While 500 is reasonable practical limit, it would be nice to be able to control it somehow, with #pragma for example.
Comment 1 Don 2010-02-04 05:53:45 UTC
> While 500 is reasonable practical limit, it would be nice to be able to 
control it somehow, with #pragma for example.

Do you have ANY use cases for this? The limit is (a) to prevent the compiler 
from crashing with a stack fault; and (b) to warn the user when they have 
inadvertently created an infinite loop.

By the way, on DMD, the limit couldn't be set much higher. It blows the stack 
at about 700. If there were a pragma, its only effect would be to create an 
error message stating that the limit cannot be increased above 500.
I just don't believe that it is 'restrictive' in any meaningful sense.
Comment 2 Igor Lesik 2010-02-04 10:57:03 UTC
No, I do not have any real use case for this. I have to admit that after all it is not that restrictive.