Thread overview
AA ignores disabling of postblit for key types
Oct 21, 2016
Nordlöw
Oct 21, 2016
Nordlöw
Oct 21, 2016
Jonathan M Davis
Nov 04, 2016
Nordlöw
October 21, 2016
The following code


import std.stdio;

struct S(E)
{
    static typeof(this) withElement(E x)
    {
        typeof(return) that;
        that._ptr = cast(E*)malloc(1*E.sizeof);
        *(that._ptr) = x;
        return that;
    }

    // @disable this(this);
    this(this) { assert(false); }

    ~this()
    {
        writeln("freeing:", _ptr);
        free(_ptr);
    }

    E* _ptr;
}

unittest
{
    alias Key = S!int;
    int[Key] x;
    writeln("before");
    x[Key.withElement(11)] = 42;
    writeln("after");
}

extern (C):
void* malloc(size_t);
void free(void*);


assert as


before
freeing:706490
core.exception.AssertError@aaNoMoveCrash.d(18): Assertion failure
----------------
??:? [0x411a3f]
??:? [0x41028f]
aaNoMoveCrash.d:18 [0x402b73]
??:? [0x413be5]
??:? [0x4126a8]
aaNoMoveCrash.d:34 [0x402a46]
??:? [0x410230]
??:? [0x41c8a0]
??:? [0x4113cb]
??:? [0x4162e6]
??:? [0x416374]
??:? [0x416277]
??:? [0x4113a7]
??:? [0x41c792]
??:? [0x412dfa]
??:? [0x412d98]
??:? [0x412d12]
??:? [0x4103bf]
??:? __libc_start_main [0x8452a82f]
freeing:706490


It seems AA's doesn't respect disabling of postblit for its Key-type even when it's sent as an r-value.

This is a serious bug.

Is this know?

Can somebody give hints to where I can start digging in DMD for fixing this?
October 21, 2016
On Friday, 21 October 2016 at 12:18:28 UTC, Nordlöw wrote:
>     this(this) { assert(false); }

If this is changed to


      @disable this(this);


I instead get a segfault because of a double free:


before
freeing:591490
after
freeing:591490
*** Error in ...

Pretty serious bug.
October 21, 2016
On Friday, October 21, 2016 12:18:28 Nordlöw via Digitalmars-d wrote:
> It seems AA's doesn't respect disabling of postblit for its Key-type even when it's sent as an r-value.
>
> This is a serious bug.

Well, I wouldn't expect it to work to use a non-copyable type as a key, but that should just result in a compilation error, not the mess that you're seeing. It wouldn't surprise me at all if the problem relates to the fact that the AA implementation uses void* internally (at least, from what I recall, that's what it does, which historically has meant a number of fun type-related bugs).

- Jonathan M Davis


November 04, 2016
On Friday, 21 October 2016 at 18:35:38 UTC, Jonathan M Davis wrote:
> On Friday, October 21, 2016 12:18:28 Nordlöw via Digitalmars-d wrote:
>> It seems AA's doesn't respect disabling of postblit for its Key-type even when it's sent as an r-value.
>>
>> This is a serious bug.
>
> Well, I wouldn't expect it to work to use a non-copyable type as a key, but that should just result in a compilation error, not the mess that you're seeing. It wouldn't surprise me at all if the problem relates to the fact that the AA implementation uses void* internally (at least, from what I recall, that's what it does, which historically has meant a number of fun type-related bugs).
>
> - Jonathan M Davis

AFACT, it *should* be able to work with non-copyable types if argument is an r-value. If somebody points out where to start digging for this DMD I can give it at try.

1. issue a error when index is an l-value of noncopyable type
2. move the index if it's an r-value