www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: Debugging CTFE

reply Matthias Walter <Matthias.Walter st.ovgu.de> writes:
Koroskin Denis Wrote:

 On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter  
 <Matthias.Walter st.ovgu.de> wrote:
 
 Hello,

 I have written some compile time executable functions with D 1.0 which  
 work in runtime but hang (and allocate memory without end) at  
 compile-time. Is there a way to debug this further? Can one print stuff  
 out? (Don't know if writefln works at compile-time, as I'm using Tango)  
 Can I somehow get a stack trace of the functions called?

 best regards
 Matthias Walter

You can use pragma(msg, "hello there!") to output some text at compile time.

This only helps for templates, as their "running" is instanciation, which lets the pragma print different stuff depending on the template parameters. In CTFE-functions, you can thus only print fixed messages, but nothing like "I'm here, arg1 - " ~ arg1
Jun 19 2008
parent Robert Fraser <fraserofthenight gmail.com> writes:
Matthias Walter Wrote:

 Koroskin Denis Wrote:
 
 On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter  
 <Matthias.Walter st.ovgu.de> wrote:
 
 Hello,

 I have written some compile time executable functions with D 1.0 which  
 work in runtime but hang (and allocate memory without end) at  
 compile-time. Is there a way to debug this further? Can one print stuff  
 out? (Don't know if writefln works at compile-time, as I'm using Tango)  
 Can I somehow get a stack trace of the functions called?

 best regards
 Matthias Walter

You can use pragma(msg, "hello there!") to output some text at compile time.

This only helps for templates, as their "running" is instanciation, which lets the pragma print different stuff depending on the template parameters. In CTFE-functions, you can thus only print fixed messages, but nothing like "I'm here, arg1 - " ~ arg1

It seems like low-yhanging fruit to add some mechanism to do this (a compiler builtin function call with no runtime code generated, for example).
Jun 19 2008