[Issue 12000] Forward reference issue with RefCounted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 27 01:27:45 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12000


Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|DMD                         |Phobos
         Depends on|                            |12008
           Severity|regression                  |normal


--- Comment #4 from Kenji Hara <k.hara.pg at gmail.com> 2014-01-27 01:27:41 PST ---
(In reply to comment #1)
> Eliminating the dependency on Phobos:
[snip]

I separated compiler regression into issue 12008.

(In reply to comment #0)
> Consider:
> 
> import std.typecons;
> 
> struct GroupBy(R)
> {
>     struct SharedInput
>     {
>         Group unused;
>     }
> 
>     struct Group
>     {
>         private RefCounted!SharedInput _allGroups;
>     }
> }
> 
> unittest
> {
>     GroupBy!(int[]) g1;
> }
> 
> This came about while I was working on #5968. The intent here is to have each
> group have a backreference to the mother hen of all groups. However, the code
> does not compile due to protests about forward reference issues (specifically
> not knowing the size). It should, seeing as RefCounted is just a pointer so the
> size is not needed to define Group's layout.

The root cause is in the implementation of RefCounted.


import std.traits : hasIndirections;

struct RefCounted(T)
{
    ~this()
    {
        static if (hasIndirections!T) { /* ... */ }
    }
}

hasIndirections!T requires the full representation of T to calculate result.
Therefore, contrary to the Andrei's thought, current RefCounted does not become
just a pointer to T.

To fix the issue, following fix would be necessary.

struct RefCounted(T)
{
    ~this()
    {
        static if (!__traits(compiles, hasIndirections!T) || hasIndirections!T) 
        { /* ... */ }
    }
}

It means that, if hasIndirections!T fails, assume T has forward reference to
RefCounted!T.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list