Bug 14844 – [REG2.068a] __traits(allMembers) must not visit yet not instantiated template members

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-28T16:56:00Z
Last change time
2015-08-05T01:30:09Z
Keywords
ice, pull
Assigned to
nobody
Creator
wikodes

Comments

Comment #0 by wikodes — 2015-07-28T16:56:23Z
Compiler: dmd-2.068.beta2 Reduced code with dustmite. It isn't valid D code any more but reproduces the compiler bug that occurred when compiling the complete source. Compiler message: dmd: attrib.c:1233: virtual Dsymbols* StaticIfDeclaration::include(Scope*, ScopeDsymbol*): Assertion `scopesym' failed. Code: module app; import std.string; import std.typecons; static this() { runUnitTests!app; } alias CppNs = Typedef!string; bool runUnitTests(COMPOSITES...)() { g_runner.runUnitTests!COMPOSITES; } class TestRunner { bool runUnitTests(COMPOSITES...)() { foreach (comp; COMPOSITES) if (runUnitTestsImpl!comp) ret; } bool runUnitTestsImpl(COMPOSITE...)() { bool ret; foreach (M; __traits(allMembers, COMPOSITE)) static if (__traits(compiles, __traits(getMember, COMPOSITE, M)) && !isModule!(__traits(getMember, COMPOSITE, M))) if (runUnitTestsImpl!(__traits(getMember, COMPOSITE, M))) ret = false; return ret; } } TestRunner g_runner; template isModule(DECL...) { enum isModule = DECL[0].stringof.startsWith("module "); }
Comment #1 by code — 2015-07-28T23:03:25Z
A bit more reduced, but I don't understand enough of the addMember/include/scope part of dmd to fix this. module app; import std.typecons; alias CppNs = Typedef!string; bool runUnitTestsImpl(alias COMPOSITE)() { foreach (M; __traits(allMembers, COMPOSITE)) static if (__traits(compiles, __traits(getMember, COMPOSITE, M)) && !isModule!(__traits(getMember, COMPOSITE, M))) if (runUnitTestsImpl!(__traits(getMember, COMPOSITE, M))) return false; return true; } template isModule(alias DECL) { enum isModule = startsWith(DECL.stringof, "module "); } bool startsWith(Needle)(string doesThisStart, Needle withThis) { return doesThisStart.length >= withThis.length && doesThisStart[0 .. withThis.length] == withThis; } alias run = runUnitTestsImpl!app;
Comment #2 by k.hara.pg — 2015-07-29T03:47:08Z
(In reply to Martin Nowak from comment #1) > A bit more reduced, but I don't understand enough of the > addMember/include/scope part of dmd to fix this. At that line in attrib.c, the assert checks that the StaticIfDeclaration is correctly recognizing the enclosing ScopeDsymbol (it's set in the preceding addMember pass), and eventually checks the order of semantic analysis passes is correct (the condition evaluation must happen after that addMember pass completion). But, current __traits(allMembers) iterates the members of yet not instantiated templates, and it violates dmd internal invariants for forward reference resolution. Minimized test case; struct Typedef { template opDispatch(string name) { static if (true) // __traits(allMembers) must not visit here { } } } bool runUnitTestsImpl() { foreach (M; __traits(allMembers, Typedef.opDispatch)) { } return true; }
Comment #3 by k.hara.pg — 2015-07-29T10:45:42Z
Comment #4 by wikodes — 2015-07-29T11:32:06Z
Amazing response. The speed and quality! Good job :)
Comment #5 by github-bugzilla — 2015-07-30T20:30:05Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/9e6ad65840b86acc7406f30704e898366bb93cb8 fix Issue 14844 - __traits(allMembers) must not visit yet not instantiated template members https://github.com/D-Programming-Language/dmd/commit/d69289bb56952a1e259fd2e6f07b8b7d4fad9d16 Merge pull request #4846 from 9rnsr/fix14844 [REG2.068a] Issue 14844 - __traits(allMembers) must not visit yet not instantiated template members
Comment #6 by github-bugzilla — 2015-08-05T01:30:09Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/9e6ad65840b86acc7406f30704e898366bb93cb8 fix Issue 14844 - __traits(allMembers) must not visit yet not instantiated template members https://github.com/D-Programming-Language/dmd/commit/d69289bb56952a1e259fd2e6f07b8b7d4fad9d16 Merge pull request #4846 from 9rnsr/fix14844