January 16, 2017 Re: Detect CTFE in AssignExp:semantic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Nowak | On Thursday, 12 January 2017 at 11:09:09 UTC, Martin Nowak wrote: > On Wednesday, 11 January 2017 at 23:44:29 UTC, Stefan Koch wrote: >> it could still be that you are assigning from a const slice. > > In which case ref for the foreach parameter still works. I updated the code based on your comments. Let me know if this is better. The issue still persists. druntime https://github.com/somzzz/druntime/commit/fb51f34cb0bdd96daaa92ab22773bf93778d4d11 dmd https://github.com/somzzz/dmd/commit/b3cf4625ce733e4b3f219bcd5069d9042430b594 |
January 17, 2017 Re: Detect CTFE in AssignExp:semantic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lucia Cojocaru | On 01/16/2017 11:22 PM, Lucia Cojocaru wrote: > druntime https://github.com/somzzz/druntime/commit/fb51f34cb0bdd96daaa92ab22773bf93778d4d11 https://github.com/somzzz/druntime/commit/fb51f34cb0bdd96daaa92ab22773bf93778d4d11#commitcomment-20497420 > dmd https://github.com/somzzz/dmd/commit/b3cf4625ce733e4b3f219bcd5069d9042430b594 Looks like you're running into some issues with the "magic" temporary variables generated by the compiler. https://github.com/dlang/dmd/blob/a5f823a59d11bb02a56384891eb80a55af467e00/src/statementsem.d#L886-L907 The error is generated here https://github.com/dlang/dmd/blob/c1d138cc3860ecf8cbe06090cc321f4d5502b6ee/src/dinterpret.d#L2441 with hasValue(v) == false meaning that the variable was not interpreted (put on the stack) before usage. I guess this happens because you're actually converting the initialization of the temporary into a function call. T __r154 = slice[]; lowered into: _d_arraycopyT(__r154, slice[]); So the function call gets interpreted before the variable was initialized by CTFE, not exactly sure how to best resolve this. Maybe simply skip lowering ConstructExp (subclass of AssignExp used for construction) for now. You can recognize construction inside of AssignExp by looking at the op, `op == TOKconstruct`. -Martin |
January 16, 2017 Re: Detect CTFE in AssignExp:semantic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lucia Cojocaru | On 1/16/2017 2:09 PM, Lucia Cojocaru wrote:
> ptrdiff_t f(char[] s) {
> // foreach(c; s) if (c == '.') return 0; // (0)fails with the same error
> message
> foreach(char c; s) if (c == '.') return 0; // (1)
> // foreach(dchar c; s) if (c == '.') return 0; // (2) different compile
> path, doesn't fail
>
> /*
> for (size_t i = 0; i < s.length; i++)
> {
> if (s[i] == '.') return i;
> }
> */
> return -1;
> }
>
> pragma(msg, f(['z', 'b', 'c', '.', 'd']));
I just compiled it with:
dmd -c bug8
and it prints:
0
with no error message.
|
January 17, 2017 Re: Detect CTFE in AssignExp:semantic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Tuesday, 17 January 2017 at 03:32:41 UTC, Walter Bright wrote: > > I just compiled it with: The problem comes from also doing the lowering for initialization, hence the CTFE interpreter has never seen the variable value before it is used. http://forum.dlang.org/post/o5jrti$n0t$1@digitalmars.com |
January 17, 2017 Re: Detect CTFE in AssignExp:semantic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Nowak | On 1/17/2017 4:39 AM, Martin Nowak wrote:
> The problem comes from also doing the lowering for initialization, hence the
> CTFE interpreter has never seen the variable value before it is used.
> http://forum.dlang.org/post/o5jrti$n0t$1@digitalmars.com
Thanks!
|
Copyright © 1999-2021 by the D Language Foundation