Debugging CTFE

Fawzi Mohamed fmohamed at mac.com
Wed Jun 18 02:43:12 PDT 2008


On 2008-06-17 19:42:33 +0200, BCS <ao at pathlink.com> said:

> Reply to Matthias,
> 
>> 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
> 
> Walter,can we plese get some debugging hooks in the CTFE stuff?

would be nice, actually a compile-time stacktrace upon failure is all I 
would need :)

anyway I had once the same problem, in my case it was something like this

class A(T,int i){
  A!(T,i+1) growI(int b){}
}

that forced the instantiation of A!(T,i+1) which in turn forced the 
instantiation of ...

moving the  function out of the class fixed the things
	A!(T,i+1) growI(T,int i)(A!(T,i)a,int b){}

In general I have found some very weird bugs (absence of this, getting 
tuck in some dependencies,...) with template member functions (that 
seem to be there in dmd since long), so when possible I use external 
templates, and limit the use of mixins.
Doing it it worked out quite well.

Fawzi



More information about the Digitalmars-d-learn mailing list