[Dlang-internal] Detect CTFE in AssignExp:semantic

Martin Nowak via Dlang-internal dlang-internal at puremagic.com
Wed Jan 11 06:16:03 PST 2017


On Wednesday, 11 January 2017 at 09:05:44 UTC, Lucia Cojocaru 
wrote:
> The dmd code (e2ir.d and expression.d are of interest):
> https://github.com/somzzz/dmd/commit/8bccc49ba661567c523545650aad30c01fd25090

Calls for the old dmd<->C-API are very different from template 
functions calls, e.g. take a look at how _xOpEquals is called.
https://github.com/dlang/dmd/blob/538a895157acdbbfc5869791f9504f7e86b4fdd0/src/clone.d#L496

> The druntime template:

https://github.com/somzzz/druntime/commit/6cf9cbc6650697d8a038be7076e588601aefe954

> The example which doesn't compile is a standalone code snippet 
> which reproduces the error encountered. I started from the code 
> in druntime and simplified it to that point. As of your 
> suggestions, I will simplify it further and come back with 
> another example.

You cannot distinguish between ctfe/non-ctfe during semantic. 
Only the backend/glue layer differs between CTFE (interpret.d) 
and IR/codegen (e2ir).
If you want to convert a C-API intrinsic to a template function 
call, you'd usually deal with __ctfe in druntime not in the 
compiler.
DMD will always call the druntime function and if that happens 
during CTFE, it'll get interpreted.


More information about the Dlang-internal mailing list