Thread overview
[Issue 4977] New: cannot use nothrow or pure with Rebindable
Oct 03, 2010
Jonathan M Davis
Oct 03, 2010
Jonathan M Davis
Oct 03, 2010
Jonathan M Davis
Oct 03, 2010
Jonathan M Davis
Aug 24, 2011
Kenji Hara
Sep 06, 2011
Kenji Hara
October 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4977

           Summary: cannot use nothrow or pure with Rebindable
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: jmdavisProg@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-10-02 17:39:46 PDT ---
Rebindable does nothing about nothrow or pure. None of its functions are marked on nothrow or pure, making it rather difficult to use Rebindable with a type which has carefully been made to correctly use nothrow and/or pure.

The first thing would be to make opDot() nothrow and pure. I'm pretty sure that you can get away with that (though pure may not be possible until the next version of the compiler is released with the changes to pure that Don suggested).

opAssign() would probably be just as easy, though I'm not sure. Since we're dealing with copying classes, interfaces, or arrays, I think that you can just make opAssign nothrow with no problem (since you have no postblit constructor to worry about possibly throwing). On purity, I'm not so sure. It might work now, or it might require the changes Don suggested, but I think that it will work at that point.

Since the constructor uses opAssign(), it will probably be just as easy/difficult to change as opAssign will be.

In any case, as it stands, its rather difficult to use either nothrow or pure with Rebindable, which either severely limits where you can use Rebindable, or it severely limits the type that you put in Rebindable.

rebindable() will likely have to be changed appropriately as well.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4977



--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-10-02 18:25:53 PDT ---
It looks like opDot() doesn't work with const or immutable Rebindable!()'s. So,
it probably needs a second version which is const (and possible a third for
immutable) in order to work with them. Otherwise, const member functions don't
work very well with member variables which are Rebindable!().

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4977



--- Comment #2 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-10-02 18:39:56 PDT ---
Here's a first attempt at a solution:

Rebindable(T) if (is(T == class) || is(T == interface) || isArray!(T))
{
    static if (!is(T X == const(U), U) && !is(T X == immutable(U), U))
    {
        alias T Rebindable;
    }
    else static if (isArray!(T))
    {
        alias const(ElementType!(T))[] Rebindable;
    }
    else
    {
        struct Rebindable
        {
            private union
            {
                T original;
                U stripped;
            }

            void opAssign(T another) nothrow
            {
                stripped = cast(U) another;
            }

            void opAssign(Rebindable another) nothrow
            {
                stripped = another.stripped;
            }

            static if (is(T == const U))
            {
                // safely assign immutable to const
                void opAssign(Rebindable!(immutable U) another) nothrow
                {
                    stripped = another.stripped;
                }
            }

            this(T initializer) nothrow
            {
                opAssign(initializer);
            }

            @property T get() const pure nothrow
            {
                return original;
            }

            T opDot() pure nothrow
            {
                return original;
            }

            T opDot() const pure nothrow
            {
                return original;
            }
        }
    }
}


With the current purity rules, I can't make opAssign() pure. It complains about assigning to const. I don't know whether or nat that will be fixed with the relaxed purity rules suggested by Don.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4977



--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-10-02 19:53:51 PDT ---
With the fix for bug # 3318, the new get property function now joins opDot() in needing a const version with both versions being nothrow.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 24, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4977


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2011-08-23 20:28:07 PDT ---
https://github.com/D-Programming-Language/phobos/pull/213

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4977


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2011-09-06 03:05:22 PDT ---
https://github.com/D-Programming-Language/phobos/commit/936f2a4c38dcca8cfe0a7e4247bddcff2f19f8ba

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