Replacing C's memcpy with a D implementation

Mike Franklin slavo5150 at yahoo.com
Mon Jun 11 02:49:00 UTC 2018


On Sunday, 10 June 2018 at 15:12:27 UTC, Kagamin wrote:
> On Sunday, 10 June 2018 at 12:49:31 UTC, Mike Franklin wrote:
>> There are many reasons to do this, one of which is to leverage 
>> information available at compile-time and in D's type system 
>> (type sizes, alignment, etc...) in order to optimize the 
>> implementation of these functions, and allow them to be used 
>> from @safe code.
>
> In safe code you just use assignment and array ops, backend 
> does the rest.
>
> On Sunday, 10 June 2018 at 13:27:04 UTC, Mike Franklin wrote:
>> But one think I discovered is that while we can set an array's 
>> length in @safe, nothrow, pure code, it gets lowered to a 
>> runtime hook that is neither @safe, nothrow, nor pure; the 
>> compiler is lying to us.
>
> If the compiler can't get it right then who can?


The compiler implementation is faulty.  It rewrites the 
expressions to an `extern(C)` runtime implementation that is not 
@safe, nothrow, or pure:  
https://github.com/dlang/druntime/blob/706081f3cb23f4c597cc487ce16ad3d2ed021053/src/rt/lifetime.d#L1442  The backend is not involved.

Mike


More information about the Digitalmars-d mailing list