digitalmars.D.learn - Why CTFE is context-sensitive?
- Pierre Talbot (3/3) Jan 26 2014 Hi,
- Martin Cejp (2/6) Jan 26 2014 Speed?
- Pierre Talbot (7/14) Jan 26 2014 Hmm, I knew I shouldn't have duplicated this post!
- Timon Gehr (2/5) Jan 26 2014 When does it apply?
- Pierre Talbot (12/19) Jan 26 2014 According to http://dlang.org/function.html#interpretation
- Pierre Talbot (9/16) Jan 26 2014 I start to think that it was mostly for a matter of convenience,
- Timon Gehr (11/30) Jan 26 2014 * initializer of 'enum' constant.
- yazd (2/6) Jan 26 2014 The halting problem possibly?
- =?UTF-8?B?U2ltZW4gS2rDpnLDpXM=?= (17/19) Jan 26 2014 Mostly because it's not necessary, and takes more time than simply
- Pierre Talbot (8/30) Jan 27 2014 We could do opportunistic CTFE by default, and if the user want
- Brad Roberts (5/32) Jan 27 2014 One of the problems is on the opposite side, ensuring it's NOT done when...
Hi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?
Jan 26 2014
On Sunday, 26 January 2014 at 09:59:01 UTC, Pierre Talbot wrote:Hi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?Speed?
Jan 26 2014
On Sunday, 26 January 2014 at 12:52:38 UTC, Martin Cejp wrote:On Sunday, 26 January 2014 at 09:59:01 UTC, Pierre Talbot wrote:Hmm, I knew I shouldn't have duplicated this post! The speed is certainly a factor but an option could have been added to the compiler to enable context-sensitivity in case we'd like the compiler to be faster (or at least, an option to enable context-insensivity). So it doesn't sound to me to be the only reason.Hi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?Speed?
Jan 26 2014
On 01/26/2014 10:59 AM, Pierre Talbot wrote:Hi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?When does it apply?
Jan 26 2014
On Sunday, 26 January 2014 at 13:48:47 UTC, Timon Gehr wrote:On 01/26/2014 10:59 AM, Pierre Talbot wrote:According to http://dlang.org/function.html#interpretation * initialization of a static variable * dimension of a static array * argument for a template value parameter As shown in the examples: int square(int i) { return i * i; } void foo() { writeln(square(4)); // run time }Hi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?When does it apply?
Jan 26 2014
On Sunday, 26 January 2014 at 15:06:30 UTC, Pierre Talbot wrote:On Sunday, 26 January 2014 at 13:48:47 UTC, Timon Gehr wrote:I start to think that it was mostly for a matter of convenience, if we use CTFE everywhere, we need a way to desactivate it (for example for code depending on endianness or specific floating arithmetic model). I read somewhere that it was really nice to not introduce new keywords (maybe needed if we want to explicitly deactivate this optimization). Through it's just pure speculation and I'd be glad to have the real reason.On 01/26/2014 10:59 AM, Pierre Talbot wrote:Hi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?
Jan 26 2014
On 01/26/2014 04:06 PM, Pierre Talbot wrote:On Sunday, 26 January 2014 at 13:48:47 UTC, Timon Gehr wrote:* initializer of 'enum' constant. * argument to pragma(msg, ...) * argument to string mixin * static if condition * static assert condition * Length of fixed-length array * Index and slice indices into template argument list * ...On 01/26/2014 10:59 AM, Pierre Talbot wrote:According to http://dlang.org/function.html#interpretation * initialization of a static variable * dimension of a static array * argument for a template value parameterHi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?When does it apply?As shown in the examples: int square(int i) { return i * i; } void foo() { writeln(square(4)); // run time }This is what we are already doing, so it makes no sense to ask why we don't do it. I was asking what would be the alternative criterion.
Jan 26 2014
On Sunday, 26 January 2014 at 09:59:01 UTC, Pierre Talbot wrote:Hi, I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?The halting problem possibly?
Jan 26 2014
On 2014-01-26 09:59, Pierre Talbot wrote:> Hi,I was wondering why CTFE is context sensitive, why don't we check every expressions and run the CTFE if it applies?Mostly because it's not necessary, and takes more time than simply compiling it. For an optimization step, opportunistic CTFE would certainly be possible (it is, after all, simply constant folding on steroids). The situations in which CTFE is attempted today are when it's explicitly required - either because the value is used at compile time, or because it's assigned to a manifest constant or static variable (which are defined to be required to be known at compile time). This means the compiler does not need to spend inordinate amounts of time testing to see if the code compiles with CTFE, and that it can give sensible error messages when something cannot be CTFE'd. If instead opportunistic CTFE were the norm, you would need to disassemble your program to see if the compiler did in fact CTFE the code that you think it should. -- Simen
Jan 26 2014
On Monday, 27 January 2014 at 01:39:47 UTC, Simen Kjærås wrote:On 2014-01-26 09:59, Pierre Talbot wrote:> Hi,We could do opportunistic CTFE by default, and if the user want to ensure it is done, instead of disassemble the program, he could just use the usual techniques (static, ...). But ok, what I wanted to hear is that it is theoretically possible but technically problematic. Thanks to all, PierreI was wondering why CTFE is context sensitive, why don't wecheckevery expressions and run the CTFE if it applies?Mostly because it's not necessary, and takes more time than simply compiling it. For an optimization step, opportunistic CTFE would certainly be possible (it is, after all, simply constant folding on steroids). The situations in which CTFE is attempted today are when it's explicitly required - either because the value is used at compile time, or because it's assigned to a manifest constant or static variable (which are defined to be required to be known at compile time). This means the compiler does not need to spend inordinate amounts of time testing to see if the code compiles with CTFE, and that it can give sensible error messages when something cannot be CTFE'd. If instead opportunistic CTFE were the norm, you would need to disassemble your program to see if the compiler did in fact CTFE the code that you think it should. -- Simen
Jan 27 2014
On 1/27/14 10:40 AM, Pierre Talbot wrote:On Monday, 27 January 2014 at 01:39:47 UTC, Simen Kjærås wrote:One of the problems is on the opposite side, ensuring it's NOT done when you don't want it to be. Consider an example where you have a blob of obfuscated data and a de-obfuscation routine. It _could_ be executed at compile time, but that defeats the point. What we have right now puts the control in the hands of the developer.On 2014-01-26 09:59, Pierre Talbot wrote:> Hi,We could do opportunistic CTFE by default, and if the user want to ensure it is done, instead of disassemble the program, he could just use the usual techniques (static, ...). But ok, what I wanted to hear is that it is theoretically possible but technically problematic. Thanks to all, PierreI was wondering why CTFE is context sensitive, why don't wecheckevery expressions and run the CTFE if it applies?Mostly because it's not necessary, and takes more time than simply compiling it. For an optimization step, opportunistic CTFE would certainly be possible (it is, after all, simply constant folding on steroids). The situations in which CTFE is attempted today are when it's explicitly required - either because the value is used at compile time, or because it's assigned to a manifest constant or static variable (which are defined to be required to be known at compile time). This means the compiler does not need to spend inordinate amounts of time testing to see if the code compiles with CTFE, and that it can give sensible error messages when something cannot be CTFE'd. If instead opportunistic CTFE were the norm, you would need to disassemble your program to see if the compiler did in fact CTFE the code that you think it should. -- Simen
Jan 27 2014