Bug 7900 – CTFE Internal error with -inline and associative arrays
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-13T20:38:00Z
Last change time
2012-11-30T01:05:12Z
Keywords
CTFE, ice
Assigned to
nobody
Creator
briancschott
Comments
Comment #0 by briancschott — 2012-04-13T20:38:32Z
Reduced test case created with Dustmite and a bit of hand-editing:
--------------------------------
import std.range;
class Trie(K, V)
{
void add(K key, V val)
{
Trie!(K,V) current = this;
foreach(keyPart; key)
{
current.children[keyPart] = new Trie!(K, V);
}
}
Trie!(K,V)[ElementType!K] children;
}
string fun(string[] args ...)
{
auto t = new Trie!(string, string);
t.add(args[0], "");
foreach(v; t.children)
if (v.children.length) {}
return "";
}
void main()
{
mixin(fun("=", "TokenType.assign"));
}
--------------------------------
testcase.d(21): Error: CTFE internal error: illegal value ��D.children
dmd: interpret.c:6678: void VarDeclaration::setValue(Expression*): Assertion `isCtfeValueValid(newval)' failed.
Aborted
-------------------------------
No, that garbage in the error message is not a copy-paste error. It's different each time I try to build, which leads me to suspect that something in the compiler was uninitialized.
Possibly related: changing line 21 to foreach(v; t.children.values) results in this error:
dmd: interpret.c:5527: TypeAArray* toBuiltinAAType(Type*): Assertion `t->ty == Tstruct' failed.
Aborted
Comment #1 by briancschott — 2012-04-13T20:42:48Z
I just realized that the dropdown options are out-of-date. I have reproduced this on 2.059 and 2.058. The compile only fails with the -inline switch.
Comment #2 by clugdbug — 2012-04-16T03:42:59Z
(In reply to comment #1)
> I just realized that the dropdown options are out-of-date.
They are not out of date. They contain a lot of obsolete tags. Nobody should use anything other than D1, D2, D1&D2.
Comment #3 by lovelydear — 2012-04-21T11:31:15Z
Same issue on Win32 2.059. The windows version gives the file/line of the assertion, though.
PS E:\DigitalMars\dmd2\samples> rdmd -inline bug.d
bug.d(21): Error: CTFE internal error: illegal value P▄S.children
Assertion failure: 'isCtfeValueValid(newval)' on line 6678 in file 'interpret.c'
Comment #4 by briancschott — 2012-05-04T18:37:02Z
Using DMD from git (b488853f4d3617945851d5d0a2ac20ccb7dab631), the error message now shows:
tmp.d(21): Error: CTFE internal error: illegal value TOK232.children
dmd: interpret.c:6884: void VarDeclaration::setValue(Expression*): Assertion `isCtfeValueValid(newval)' failed.
Aborted
The corrupted output is now gone, so that's a good thing. Test case still compiles without -inline and fails when it is present.
Reduced test case:
class Trie {
Trie[dchar] children;
}
int bug7900() {
Trie t = new Trie;
t.children['='] = new Trie;
foreach(v; t.children)
if (v.children.length) {}
return 1;
}
static assert(bug7900());