Thread overview
ctfe reduction
Mar 21, 2017
StarGrazer
Mar 21, 2017
Stefan Koch
Mar 21, 2017
ag0aep6g
Mar 21, 2017
H. S. Teoh
Mar 21, 2017
Jack Stouffer
March 21, 2017
One problem with ctfe's is that the compiler is a bit ignorant.

e.g.,

auto e = X!"y";

It is clear that e, when defined is a manifest constant(simply because one can do)

enum ee = X!"y";
auto e = ee;

But one can't do

auto e = X!"y";
pragma(msg, e);


yet one can do

enum ee = X!"y";
auto e = ee;
pragma(msg, ee);


It seems that the compiler can be smart enough to figure this out. It simply creates an intermediate analogous to the above. Then we can do

auto e = X!"y";
pragma(msg, e)

and the compiler is smart enough to make it work.

There is no downside because it simply extends pragma to seem like it works for the more general case. The compiler already has to create the values internally so very little extra overhead(just the placeholder for the intermediate step) is required.

When code building, this will save significant space.




March 21, 2017
On Tuesday, 21 March 2017 at 17:56:33 UTC, StarGrazer wrote:
> One problem with ctfe's is that the compiler is a bit ignorant.
>
> e.g.,
>
> auto e = X!"y";
>
> It is clear that e, when defined is a manifest constant(simply because one can do)
>
> enum ee = X!"y";
> auto e = ee;
>
> But one can't do
>
> auto e = X!"y";
> pragma(msg, e);
>
>
> yet one can do
>
> enum ee = X!"y";
> auto e = ee;
> pragma(msg, ee);
>
>
> It seems that the compiler can be smart enough to figure this out. It simply creates an intermediate analogous to the above. Then we can do
>
> auto e = X!"y";
> pragma(msg, e)
>
> and the compiler is smart enough to make it work.
>
> There is no downside because it simply extends pragma to seem like it works for the more general case. The compiler already has to create the values internally so very little extra overhead(just the placeholder for the intermediate step) is required.
>
> When code building, this will save significant space.

Making the compiler smarter. Is often unwise;
Since smarter compilers tend to be much harder to debug.

Also I can confidently say this:

"CTFE performance will soon be no problem anymore."

March 21, 2017
On 03/21/2017 06:56 PM, StarGrazer wrote:
> One problem with ctfe's is that the compiler is a bit ignorant.
>
> e.g.,
>
> auto e = X!"y";
>
> It is clear that e, when defined is a manifest constant(simply because
> one can do)

e is not a manifest constant. X!"y" is presumably a compile-time constant, but that doesn't transfer to e.

> enum ee = X!"y";
> auto e = ee;

This shows that you can go from a static value to a dynamic value.

> But one can't do
>
> auto e = X!"y";
> pragma(msg, e);

But you can't go from a dynamic value to a static one. pragma(msg, ...) needs a static value, but e is dynamic.

> yet one can do
>
> enum ee = X!"y";
> auto e = ee;
> pragma(msg, ee);

You're not using e here. Did you mean to write `pragma(msg, e);`? That doesn't work for the same reason as the one above.

Aside: Your code doesn't involve any (visible) CTFE. CTFE is different from templates.
March 21, 2017
On Tue, Mar 21, 2017 at 05:56:33PM +0000, StarGrazer via Digitalmars-d wrote:
> One problem with ctfe's is that the compiler is a bit ignorant.
[...]

The reason for this is that pragma(msg) is not a CTFE construct, but an AST construct.  It is evaluated when the compiler is building the abstract syntax tree of the code, and discarded thereafter. CTFE does not even see pragma(msg)'s.

More details here:

http://forum.dlang.org/post/mailman.1113.1489778027.31550.digitalmars-d-learn@puremagic.com


T

-- 
Lottery: tax on the stupid. -- Slashdotter
March 21, 2017
On Tuesday, 21 March 2017 at 17:56:33 UTC, StarGrazer wrote:
> One problem with ctfe's is that the compiler is a bit ignorant.
>
> e.g.,
>
> auto e = X!"y";
>
> It is clear that e, when defined is a manifest constant(simply because one can do)
>
> enum ee = X!"y";
> auto e = ee;
>
> But one can't do
>
> auto e = X!"y";
> pragma(msg, e);
>
>
> yet one can do
>
> enum ee = X!"y";
> auto e = ee;
> pragma(msg, ee);
>
>
> It seems that the compiler can be smart enough to figure this out.

Explicit is better than implicit.
Simple is better than complex.

Beware of compilers "figuring out" things for you.