newCTFE Status April 2018
Stefan Koch
uplink.coder at googlemail.com
Sun Apr 8 09:44:04 UTC 2018
Hi Guys,
I have just implemented dynamic cast.
Or rather I have debugged it.
The generated byte-code for dynamic cast itself was correct.
However per function only one dynamic cast would be generated.
To generate my dynamic casts I loop through my type table and
look for classes which are dynamic cast targets.
like this
---
bool needDynamicCast(BCType type)
{
foreach(dc;known_dyncasts)
{
if (dc.targetType == type)
return false;
}
return true;
}
what follows is the simplified definition of BCType at the point
of the bug
enum BCTypeEnum
{
u32, i32, Class, Ptr, Struct, Void;
}
struct BCType
{
BCTypeEnum kind;
alias kind this;
uint typeIndex;
}
Because the members exposed by alias this_ed members take
priority over the members of the containing struct.
the comparison will only compare the kind of the type.
And ignore the typeIndex.
Which then means that every classType is considered equal to
every other classType.
Which will cause every class to refer to the same dynamic cast,
which is only generated for the first dynamic cast encountered.
The Moral of this, if you use any implicitly generated members,
stay away from alias this.
chances are minor changes to the contained type make it shadow
certain members that it did not shadow before, and in case of
auto-generated members you cannot even insert debug_prints to
ensure they are being called.
Before I noticed the bug I rewrote a lot of my low-level code
(because I thought my code-generation was at fault) introducing
even more bugs which I had to fix after I found the real culprit.
Regards,
Stefan
PS. my vacation is over so it will most likely grow silent around
newCTFE again.
Rest assured though that it is not dead and is being worked on!
It's just that my time-budget severely decreased.
See you at dconf!
More information about the Digitalmars-d
mailing list