On Wed, Jul 10, 2013 at 6:11 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Wednesday, July 10, 2013 18:06:00 Timothee Cour wrote:<br>
> import std.array;<br>
><br>
> void main(){<br>
> //enum a1=[1].array;//NG: Error: gc_malloc cannot be interpreted at<br>
> compile time<br>
> enum a2=" ".array;//OK<br>
><br>
> import std.string;<br>
> //enum a3=" ".splitLines.array;//NG<br>
> enum a4="".splitLines.array;//OK<br>
> enum a5=" ".split.array;//OK<br>
> //enum a6=" a ".split.array;//NG<br>
> import std.algorithm:filter;<br>
> enum a7=" a ".split.filter!(a=>true).array;<br>
> auto a8=" a ".split.array;<br>
> assert(a8==a7);<br>
> enum a9=[1].filter!(a=>true).array;//OK<br>
> }<br>
><br>
><br>
> I don't understand why the NG above fail (with Error: gc_malloc cannot be<br>
> interpreted at compile time)<br>
><br>
> furthermore, it seems we can bypass the CT error with interleaving<br>
> filter!(a=>true) (see above), which is even weirder.<br>
<br>
</div></div>I expect that it's a matter of code path. Some code paths don't hit anything<br>
which is illegal in CTFE, but apparently at least one of them uses gc_malloc,<br>
which is apparently illegal in CTFE, so when it gets hit, CTFE fails.<br>
Presumably, to fix it, either it needs to be changed to not use gc_malloc or<br>
changed so that it doesn't use gc_malloc with CTFE (by using __ctfe). I'd have<br>
to actually dig through the code to verify exactly what it's doing though.<br>
<span class="HOEnZb"><font color="#888888"><br>
- Jonathan M Davis<br>
</font></span></blockquote></div><br><div>in the meantime, one can do:</div><div><div><br></div><div>auto ctfe_array(T)(T a){</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>import std.algorithm:filter;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>import std.array:array;</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>return a.filter!(a=>true).array;</div><div>}</div></div><div>
unittest{</div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">  //enum a1=[1].array;//NG</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">  enum a2=[1].</span> ctfe_array<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">;//OK</span></div>
<div>}</div><div><br></div><div>but why not change std.array.array to this:</div><div><br></div><div><div>auto array(T)(T a){</div></div><div>if(__ctfe){</div><div>import std.algorithm:filter;</div><div>return a.filter!(a=>true). arrayImpl;</div>
<div>}</div><div>else{</div><div>return arrayImpl(a);</div><div>}</div><div>}</div><div><br></div><div><div>auto arrayImpl(T)(T a){...}//move current implementation here</div></div><div><br></div><div>That would at least temporarily solve the problem, until a better fix is found.</div>