digitalmars.D.learn - Debugging CTFE
- Matthias Walter (4/4) Jun 17 2008 Hello,
- Jarrett Billingsley (10/16) Jun 17 2008 No, no, and no. CTFE support in the current frontend has some rather
- Ary Borenszweig (8/27) Jun 17 2008 After I finish making Descent support D2, I'll try to make templates and...
- Extrawurst (4/7) Jun 18 2008 You are working on this at the very moment ? Thats great to hear, any
- Ary Borenszweig (9/17) Jun 18 2008 I hope to have it done in about a month or less, I'm trying to port a
- Koroskin Denis (3/19) Jun 18 2008 Of course there is!!!
- Don (11/31) Jun 19 2008 I disagree. I've not had much trouble with CTFE. The really, really nice...
- Matthias Walter (5/42) Jun 19 2008 But in my case, the runtime-function needed some milliseconds, allocatin...
- Don (5/47) Jun 19 2008 That'll be issue #1382. You can only do a few thousand memory
- Koroskin Denis (3/55) Jun 19 2008 IIRC, there is a Hans Boehm garbage Collector available for MDC, could
- Koroskin Denis (4/12) Jun 17 2008 You can use pragma(msg, "hello there!") to output some text at compile
- BCS (10/27) Jun 17 2008 I don't /think/ that works for what is wanted:
- Koroskin Denis (24/48) Jun 17 2008 You are right. But although it doesn't work (currently) for CTFE, it doe...
- Max Samukha (5/19) Jun 17 2008 The only way to print a debugging message from the inside of
- BCS (2/12) Jun 17 2008 Walter,can we plese get some debugging hooks in the CTFE stuff?
- Fawzi Mohamed (17/31) Jun 18 2008 would be nice, actually a compile-time stacktrace upon failure is all I
- Matthias Walter (2/18) Jun 19 2008 This only helps for templates, as their "running" is instanciation, whic...
- Robert Fraser (4/24) Jun 19 2008 It seems like low-yhanging fruit to add some mechanism to do this (a
- Matthias Walter (2/64) Jun 19 2008 Yes, the problem is, that compile-time functions must also be runtime-ex...
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
Jun 17 2008
"Matthias Walter" <Matthias.Walter st.ovgu.de> wrote in message news:g38na9$2gs7$1 digitalmars.com...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?No, no, and no. CTFE support in the current frontend has some rather unworkable disadvantages. For one, it's terribly buggy. You're better off trying to convert it to templates in most cases. For two, CTFE is interpreting a garbage-collected language but is not itself garbage-collected, meaning that memory-unconscious code evaluated at compile time (i.e. a loop that appends data to the end of a string) will just leak like hell and cause the compiler to easily use up several GB of memory. That might be what's happening to your code. Or it could be a bug in CTFE.
Jun 17 2008
Jarrett Billingsley a écrit :"Matthias Walter" <Matthias.Walter st.ovgu.de> wrote in message news:g38na9$2gs7$1 digitalmars.com...After I finish making Descent support D2, I'll try to make templates and CTFE debuggable (i.e. you put a breakpoint, you right click on a template or a function and select "Debug at compile-time"). The advantage here is, it's java code, so the intepreted code does get garbage collected. ;-) I don't think it's hard to do, all the information is available in the front-end for this. Of course, any help will be appreciated.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?No, no, and no. CTFE support in the current frontend has some rather unworkable disadvantages. For one, it's terribly buggy. You're better off trying to convert it to templates in most cases. For two, CTFE is interpreting a garbage-collected language but is not itself garbage-collected, meaning that memory-unconscious code evaluated at compile time (i.e. a loop that appends data to the end of a string) will just leak like hell and cause the compiler to easily use up several GB of memory. That might be what's happening to your code. Or it could be a bug in CTFE.
Jun 17 2008
Ary Borenszweig schrieb:After I finish making Descent support D2, I'll try to make templates and CTFE debuggable (i.e. you put a breakpoint, you right click on a template or a function and select "Debug at compile-time").You are working on this at the very moment ? Thats great to hear, any idea when its gonna be released ? Thats what i am waiting for all the time ;)
Jun 18 2008
Extrawurst a écrit :Ary Borenszweig schrieb:I hope to have it done in about a month or less, I'm trying to port a little bit each day. And then after porting it's about moving the parser stuff up to the core stuff (public AST, signature) and then to the UI stuff (labels for const and invariant, etc.). But it's a race against Walter's releases... See, now after I finish porting to DMD 2.013, I'll have to port to DMD 2.015 :-P (but that should be much easier than porting from D1 to D2) It's great to hear there is interest in Descent for D2.After I finish making Descent support D2, I'll try to make templates and CTFE debuggable (i.e. you put a breakpoint, you right click on a template or a function and select "Debug at compile-time").You are working on this at the very moment ? Thats great to hear, any idea when its gonna be released ? Thats what i am waiting for all the time ;)
Jun 18 2008
On Wed, 18 Jun 2008 15:20:23 +0400, Ary Borenszweig <ary esperanto.org.ar> wrote:Extrawurst a écrit :Of course there is!!!Ary Borenszweig schrieb:I hope to have it done in about a month or less, I'm trying to port a little bit each day. And then after porting it's about moving the parser stuff up to the core stuff (public AST, signature) and then to the UI stuff (labels for const and invariant, etc.). But it's a race against Walter's releases... See, now after I finish porting to DMD 2.013, I'll have to port to DMD 2.015 :-P (but that should be much easier than porting from D1 to D2) It's great to hear there is interest in Descent for D2.After I finish making Descent support D2, I'll try to make templates and CTFE debuggable (i.e. you put a breakpoint, you right click on a template or a function and select "Debug at compile-time").You are working on this at the very moment ? Thats great to hear, any idea when its gonna be released ? Thats what i am waiting for all the time ;)
Jun 18 2008
Jarrett Billingsley wrote:"Matthias Walter" <Matthias.Walter st.ovgu.de> wrote in message news:g38na9$2gs7$1 digitalmars.com...I disagree. I've not had much trouble with CTFE. The really, really nice thing about CTFE is that you can write it as a runtime function, and make sure it works before using it a compile time. CTFE functions)... For two, CTFE isHello, 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?No, no, and no. CTFE support in the current frontend has some rather unworkable disadvantages. For one, it's terribly buggy.You're better off trying to convert it to templates in most cases.interpreting a garbage-collected language but is not itself garbage-collected, meaning that memory-unconscious code evaluated at compile time (i.e. a loop that appends data to the end of a string) will just leak like hell and cause the compiler to easily use up several GB of memory. That might be what's happening to your code.That's very likely. The maximum size of code you can write with CTFE is pretty small.Or it could be a bug in CTFE.bugzilla, I reckon.
Jun 19 2008
Don Wrote:Jarrett Billingsley wrote:But in my case, the runtime-function needed some milliseconds, allocating not more than 1 MB data. the compiler then allocated 1 GB until I killed the process. I guess, there might be some other bugs. Unfortunatly, I was unable to make proofing code more easy to get the cause of the bug. Anyway, I now don't use functions for much stuff, but try to achieve my needs with templates, although template programming is sometimes a bit messier. But it works and debugging via pragmas is like printf-debugging in C and thus just a matter of time :) Training more functional thinking is also helpful for other things... best regards and thanks for the tips Matthias"Matthias Walter" <Matthias.Walter st.ovgu.de> wrote in message news:g38na9$2gs7$1 digitalmars.com...I disagree. I've not had much trouble with CTFE. The really, really nice thing about CTFE is that you can write it as a runtime function, and make sure it works before using it a compile time. CTFE functions)... For two, CTFE isHello, 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?No, no, and no. CTFE support in the current frontend has some rather unworkable disadvantages. For one, it's terribly buggy.You're better off trying to convert it to templates in most cases.interpreting a garbage-collected language but is not itself garbage-collected, meaning that memory-unconscious code evaluated at compile time (i.e. a loop that appends data to the end of a string) will just leak like hell and cause the compiler to easily use up several GB of memory. That might be what's happening to your code.That's very likely. The maximum size of code you can write with CTFE is pretty small.Or it could be a bug in CTFE.bugzilla, I reckon.
Jun 19 2008
Matthias Walter wrote:Don Wrote:allocations (including ~) before CTFE dies. Basically, you can use CTFE for very small tasks, and for libraryJarrett Billingsley wrote:But in my case, the runtime-function needed some milliseconds, allocating not more than 1 MB data. the compiler then allocated 1 GB until I killed the process. I guess, there might be some other bugs. Unfortunatly, I was unable to make proofing code more easy to get the cause of the bug."Matthias Walter" <Matthias.Walter st.ovgu.de> wrote in message news:g38na9$2gs7$1 digitalmars.com...I disagree. I've not had much trouble with CTFE. The really, really nice thing about CTFE is that you can write it as a runtime function, and make sure it works before using it a compile time. CTFE functions)... For two, CTFE isHello, 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?No, no, and no. CTFE support in the current frontend has some rather unworkable disadvantages. For one, it's terribly buggy.You're better off trying to convert it to templates in most cases.interpreting a garbage-collected language but is not itself garbage-collected, meaning that memory-unconscious code evaluated at compile time (i.e. a loop that appends data to the end of a string) will just leak like hell and cause the compiler to easily use up several GB of memory. That might be what's happening to your code.That's very likely. The maximum size of code you can write with CTFE is pretty small.Or it could be a bug in CTFE.bugzilla, I reckon.Anyway, I now don't use functions for much stuff, but try to achieve my needs with templates, although template programming is sometimes a bit messier. But it works and debugging via pragmas is like printf-debugging in C and thus just a matter of time :) Training more functional thinking is also helpful for other things... best regards and thanks for the tips Matthias
Jun 19 2008
On Thu, 19 Jun 2008 14:11:55 +0400, Don <nospam nospam.com.au> wrote:Matthias Walter wrote:IIRC, there is a Hans Boehm garbage Collector available for MDC, could Walter integrate it into DMD and solve the problem? :)Don Wrote:allocations (including ~) before CTFE dies. Basically, you can use CTFE for very small tasks, and for libraryJarrett Billingsley wrote:But in my case, the runtime-function needed some milliseconds, allocating not more than 1 MB data. the compiler then allocated 1 GB until I killed the process. I guess, there might be some other bugs. Unfortunatly, I was unable to make proofing code more easy to get the cause of the bug."Matthias Walter" <Matthias.Walter st.ovgu.de> wrote in message news:g38na9$2gs7$1 digitalmars.com...I disagree. I've not had much trouble with CTFE. The really, really nice thing about CTFE is that you can write it as a runtime function, and make sure it works before using it a compile time. CTFE functions)... For two, CTFE isHello, 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?No, no, and no. CTFE support in the current frontend has some rather unworkable disadvantages. For one, it's terribly buggy.You're better off trying to convert it to templates in most cases.interpreting a garbage-collected language but is not itself garbage-collected, meaning that memory-unconscious code evaluated at compile time (i.e. a loop that appends data to the end of a string) will just leak like hell and cause the compiler to easily use up several GB of memory. That might be what's happening to your code.That's very likely. The maximum size of code you can write with CTFE is pretty small.Or it could be a bug in CTFE.bugzilla, I reckon.Anyway, I now don't use functions for much stuff, but try to achieve my needs with templates, although template programming is sometimes a bit messier. But it works and debugging via pragmas is like printf-debugging in C and thus just a matter of time :) Training more functional thinking is also helpful for other things... best regards and thanks for the tips Matthias
Jun 19 2008
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 WalterYou can use pragma(msg, "hello there!") to output some text at compile time.
Jun 17 2008
Reply to Koroskin,On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter <Matthias.Walter st.ovgu.de> wrote:I don't /think/ that works for what is wanted: char[] CTFE() { char[] c = "hello world", for(;c.length >0; c=c[0..$-1]) pragma(msg, c); return c; } // not testedHello, 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 WalterYou can use pragma(msg, "hello there!") to output some text at compile time.
Jun 17 2008
On Tue, 17 Jun 2008 20:56:00 +0400, BCS <ao pathlink.com> wrote:Reply to Koroskin,You are right. But although it doesn't work (currently) for CTFE, it does for templates: template itoa(uint i) { static if (i < 10) const char[] itoa = "" ~ cast(char)(i + '0'); else const char[] itoa = itoa!(i / 10) ~ itoa!(i % 10); } template factorial(int i) { pragma(msg, "Calculating factorial of " ~ itoa!(i)); static if (i < 2) { const int factorial = 1; } else { const int factorial = factorial!(i-1)*i; } } int main() { const int t = factorial!(100); return 0; }On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter <Matthias.Walter st.ovgu.de> wrote:I don't /think/ that works for what is wanted: char[] CTFE() { char[] c = "hello world", for(;c.length >0; c=c[0..$-1]) pragma(msg, c); return c; } // not testedHello, 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 WalterYou can use pragma(msg, "hello there!") to output some text at compile time.
Jun 17 2008
On Tue, 17 Jun 2008 20:45:48 +0400, "Koroskin Denis" <2korden gmail.com> wrote:On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter <Matthias.Walter st.ovgu.de> wrote:The only way to print a debugging message from the inside of compile-time function is to use assert(false, "hallo"); but it breaks execution.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 WalterYou can use pragma(msg, "hello there!") to output some text at compile time.
Jun 17 2008
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 WalterWalter,can we plese get some debugging hooks in the CTFE stuff?
Jun 17 2008
On 2008-06-17 19:42:33 +0200, BCS <ao pathlink.com> said:Reply to Matthias,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. FawziHello, 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 WalterWalter,can we plese get some debugging hooks in the CTFE stuff?
Jun 18 2008
Koroskin Denis Wrote:On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter <Matthias.Walter st.ovgu.de> wrote: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 - " ~ arg1Hello, 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 WalterYou can use pragma(msg, "hello there!") to output some text at compile time.
Jun 19 2008
Matthias Walter Wrote:Koroskin Denis Wrote: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).On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter <Matthias.Walter st.ovgu.de> wrote: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 - " ~ arg1Hello, 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 WalterYou can use pragma(msg, "hello there!") to output some text at compile time.
Jun 19 2008
Koroskin Denis Wrote:On Tue, 17 Jun 2008 20:56:00 +0400, BCS <ao pathlink.com> wrote:Yes, the problem is, that compile-time functions must also be runtime-executable (and pragma must not depend on runtime variables), which I think, should not be a necessarity. But I guess this makes sense from Walters point of view, so this won't change in near future, I guess.Reply to Koroskin,You are right. But although it doesn't work (currently) for CTFE, it does for templates: template itoa(uint i) { static if (i < 10) const char[] itoa = "" ~ cast(char)(i + '0'); else const char[] itoa = itoa!(i / 10) ~ itoa!(i % 10); } template factorial(int i) { pragma(msg, "Calculating factorial of " ~ itoa!(i)); static if (i < 2) { const int factorial = 1; } else { const int factorial = factorial!(i-1)*i; } } int main() { const int t = factorial!(100); return 0; }On Tue, 17 Jun 2008 20:04:25 +0400, Matthias Walter <Matthias.Walter st.ovgu.de> wrote:I don't /think/ that works for what is wanted: char[] CTFE() { char[] c = "hello world", for(;c.length >0; c=c[0..$-1]) pragma(msg, c); return c; } // not testedHello, 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 WalterYou can use pragma(msg, "hello there!") to output some text at compile time.
Jun 19 2008