digitalmars.D.learn - How do I check if a function got CTFE?
- AsmMan (9/9) Oct 02 2014 I'd like to check if a function got CTFE, ie, the compiler was
- Adam D. Ruppe (10/13) Oct 02 2014 You have to explicitly force ctfe with context, it is never done
- AsmMan (4/11) Oct 02 2014 That's the point. I thought the compiler did it by checking
- anonymous (10/20) Oct 02 2014 Sorry, can't help with you objconv, COFF, ELF, etc.
- AsmMan (7/18) Oct 02 2014 I was thiking the dmd compiler did CTFE without someone ask for
- anonymous (3/9) Oct 02 2014 Yeah, that would be constant folding. The compiler is free to do
- H. S. Teoh via Digitalmars-d-learn (6/16) Oct 02 2014 CTFE grew out of constant-folding in dmd. In the dmd code, it is
- monarch_dodra (6/12) Oct 02 2014 A convenient way to force ctfe is "eval":
- Gary Willoughby (3/13) Oct 02 2014 You could use __ctfe
I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time. I'm trying to convert the binary executable to assembly by using objconv tool but I'm finding it very diffucult to find anything in there, since some converters I've used which does ELF to ASM keep the function name, e.g, foo() function is a foo label somewhere in the file but this convert doesn't and use some numbers instead of. I don't know if it's related how is the windows object file format designed.
Oct 02 2014
On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote:I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time.You have to explicitly force ctfe with context, it is never done automatically, and if it fails, the build will fail and you get a compile time error. So if you write enum f = foo(); or static f = foo(); or similar initializations and the build succeeds, you know it got ctfe'd. Otherwise, it wasn't.
Oct 02 2014
On Thursday, 2 October 2014 at 18:02:30 UTC, Adam D. Ruppe wrote:On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote:That's the point. I thought the compiler did it by checking things like constant arguments + function purity or so. This was exactly my issue. Thanks!I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time.You have to explicitly force ctfe with context, it is never done automatically, and if it fails, the build will fail and you get a compile time error.
Oct 02 2014
On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote:I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time. I'm trying to convert the binary executable to assembly by using objconv tool but I'm finding it very diffucult to find anything in there, since some converters I've used which does ELF to ASM keep the function name, e.g, foo() function is a foo label somewhere in the file but this convert doesn't and use some numbers instead of. I don't know if it's related how is the windows object file format designed.Sorry, can't help with you objconv, COFF, ELF, etc. A little something about terminology though: "CTFE" in the narrower sense refers to those occurrences of compile time evaluation that are specified to happen. Static initializers are CTFE-ed, for example. CTFE is not an optimization that a compiler may or may not do. The term for the optimization would be "constant folding", I think. Your question, as I understand it, is about constant folding, not about CTFE.
Oct 02 2014
On Thursday, 2 October 2014 at 18:17:12 UTC, anonymous wrote:On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote:I was thiking the dmd compiler did CTFE without someone ask for this, in the way as I've mentioned, checking for constant arguments + function's purity and if all this is true, it did the CTFE rather than generate code to compute it at run-time. In the case of it did happen, I just wanted to know. It was my misunderstsooding how it does works in dmd.I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time. I'm trying to convert the binary executable to assembly by using objconv tool but I'm finding it very diffucult to find anything in there, since some converters I've used which does ELF to ASM keep the function name, e.g, foo() function is a foo label somewhere in the file but this convert doesn't and use some numbers
Oct 02 2014
On Thursday, 2 October 2014 at 18:42:56 UTC, AsmMan wrote:I was thiking the dmd compiler did CTFE without someone ask for this, in the way as I've mentioned, checking for constant arguments + function's purity and if all this is true, it did the CTFE rather than generate code to compute it at run-time. In the case of it did happen, I just wanted to know. It was my misunderstsooding how it does works in dmd.Yeah, that would be constant folding. The compiler is free to do that. It's just not called "CTFE" then.
Oct 02 2014
On Thu, Oct 02, 2014 at 07:04:56PM +0000, anonymous via Digitalmars-d-learn wrote:On Thursday, 2 October 2014 at 18:42:56 UTC, AsmMan wrote:CTFE grew out of constant-folding in dmd. In the dmd code, it is essentially still just a constant-folder, albeit a superpowered one. :-P T -- It is of the new things that men tire --- of fashions and proposals and improvements and change. It is the old things that startle and intoxicate. It is the old things that are young. -- G.K. ChestertonI was thiking the dmd compiler did CTFE without someone ask for this, in the way as I've mentioned, checking for constant arguments + function's purity and if all this is true, it did the CTFE rather than generate code to compute it at run-time. In the case of it did happen, I just wanted to know. It was my misunderstsooding how it does works in dmd.Yeah, that would be constant folding. The compiler is free to do that. It's just not called "CTFE" then.
Oct 02 2014
On Thursday, 2 October 2014 at 18:42:56 UTC, AsmMan wrote:I was thiking the dmd compiler did CTFE without someone ask for this, in the way as I've mentioned, checking for constant arguments + function's purity and if all this is true, it did the CTFE rather than generate code to compute it at run-time. In the case of it did happen, I just wanted to know. It was my misunderstsooding how it does works in dmd.A convenient way to force ctfe is "eval": http://dlang.org/function.html (search for "eval!") Though you'd change "const" for "enum". Unfortunately, it's not in Phobos, but it should be! https://issues.dlang.org/show_bug.cgi?id=11811
Oct 02 2014
On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote:I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time. I'm trying to convert the binary executable to assembly by using objconv tool but I'm finding it very diffucult to find anything in there, since some converters I've used which does ELF to ASM keep the function name, e.g, foo() function is a foo label somewhere in the file but this convert doesn't and use some numbers instead of. I don't know if it's related how is the windows object file format designed.You could use __ctfe http://forum.dlang.org/thread/yzioyjhiqedktswkweop forum.dlang.org
Oct 02 2014