Bug 13028 – [ICE] CTFE internal error: cannot evaluate at compile time

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-03T02:17:00Z
Last change time
2015-02-18T03:41:13Z
Keywords
diagnostic, ice, pull
Assigned to
nobody
Creator
safety0ff.bugz

Comments

Comment #0 by safety0ff.bugz — 2014-07-03T02:17:36Z
Removing the enum b = ___; line it works. It would be nice if it would work when the parameter is compile-time evaluable. int foo(int delegate() dg) { enum b = dg(); return b; } int bar(lazy int a) { enum b = a; return a; } void main() { static assert(foo(()=>1) == 1); static assert(bar(1) == 1); }
Comment #1 by k.hara.pg — 2014-07-17T10:51:05Z
(In reply to safety0ff.bugz from comment #0) > Removing the enum b = ___; line it works. > It would be nice if it would work when the parameter is compile-time > evaluable. > This is an invalid enhancement request issue. By definition, CTFEable function should also work in runtime. All functions are invalid definition because they cannot work in runtime. In other words, compile-time value evaluation and runtime value evaluation are strictly separated in D. An exception case is that, if a runtime evaluated expression can be folded into a constant by optimizer, you will be able to use it also in compile-time expressions. For example: void main() { immutable int x = 3; // x is a runtime variable, but int[x] sarray = [1,2,3]; // its value is known and usable in CT. auto p = &x; // x has a runtime storage. } But, optimizer cannot work beyond the boundary of function (it's in the domain of inliner). Therefore > int foo(int delegate() dg) > { > enum b = dg(); > return b; > } function parameters never be usable in CT expressions.
Comment #2 by safety0ff.bugz — 2014-08-06T17:42:37Z
(In reply to Kenji Hara from comment #1) > This is an invalid enhancement request issue. This issue is solely about having an "internal" error displayed on that wrong piece of code.
Comment #3 by k.hara.pg — 2014-12-10T04:48:44Z
Comment #4 by k.hara.pg — 2014-12-10T04:51:11Z
(In reply to Kenji Hara from comment #3) > https://github.com/D-Programming-Language/dmd/pull/4208 It will improve the diagnosic messages: test.d(3): Error: variable dg cannot be read at compile time test.d(10): Error: variable a cannot be read at compile time test.d(16): Error: CTFE failed because of previous errors in foo test.d(16): while evaluating: static assert(foo(() => 1) == 1) test.d(17): Error: CTFE failed because of previous errors in bar test.d(17): while evaluating: static assert(bar(delegate int() => 1) == 1)
Comment #5 by github-bugzilla — 2014-12-14T22:29:33Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6cf83166ee230cb7b88cb08ad99d12bdc2dcd911 fix Issue 13028 - [ICE] CTFE internal error: cannot evaluate at compile time
Comment #6 by github-bugzilla — 2015-02-18T03:41:13Z
Commit pushed to 2.067 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6cf83166ee230cb7b88cb08ad99d12bdc2dcd911 fix Issue 13028 - [ICE] CTFE internal error: cannot evaluate at compile time