On Monday, 26 March 2018 at 14:17:03 UTC, Jonathan M Davis wrote:
Rebindable does is pretty questionable as far as the type system goes, but it does what it does by forcing pointer semantics on a class reference, so the point is arguable.

Yeah, I've always assumed that Rebindable cannot be implemented without internally breaking the type system, then exposing a safe interface.

But this sparked my interest, I've dug out the Rebindable code:

    private mixin template RebindableCommon(T, U, alias This)
if (is(T == class) || is(T == interface) || isAssociativeArray!T)
    {
        private union
        {
            T original; // e.g., immutable(A) for classs A
            U stripped; // the unqualified type, e.g., A
        }
        // ...
    }

Does Rebindable-using code, oblivious of the hacks inside Rebindable, remain 100 % safe even with aggressive compiler optimizations? For class A, inside Rebindable!(immutable A), there is a union of (immutable A) and A. I suspect that the D compiler is allowed to treat this reference to (immutable A) as immutable itself. Have there never been bugs here when, later, stripped = another.stripped;?

-- Simon

Reply via email to