On 9/27/23 11:30 PM, Nicholas Wilson wrote:
>I have need of the ability to suppress the code generation of functions for using mixin generation functions with dcompute. Below is a link to a PR to implement that functionality.
https://github.com/dlang/dmd/pull/15636
What are peoples thoughts on this?
Have you tried immediately-called lambdas?
What I need is for this to work:
void foo() @nogc
{
int[] buf;
if (__ctfe) {
buf = new int[10000];
}
else {
buf = (cast(int*)malloc(int.sizeof * 10000))[0 .. 10000];
}
scope(exit) if(!__ctfe) free(buf.ptr);
... // use buf
}
We need the compiler to back-off when it comes to enforcing runtime attributes in compile-time-only blocks. Without it, reasonable backup plans don't exist for what seems like obvious allowances. BetterC CTFE code becomes impossible, etc.
I'd also like to see assert(__ctfe)
just suppress code generation, as mentioned.
-Steve