Replacing C's memcpy with a D implementation

Mike Franklin slavo5150 at yahoo.com
Mon Jun 11 03:43:10 UTC 2018


On Monday, 11 June 2018 at 03:31:05 UTC, Walter Bright wrote:
> On 6/10/2018 7:49 PM, Mike Franklin wrote:
>> On Sunday, 10 June 2018 at 15:12:27 UTC, Kagamin wrote:
>>> 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.
>
> It's only faulty if there's a bug in it. It's essentially 
> @trusted code.

That only addresses the @safe attribute, and that code is much 
too complex for anyone to audit it and certify it as safe.

Exceptions are also not all handled, so there is no way it can 
pass as nothrow.

The runtime call needs to be replaced with a template that can 
take advantage of D's compile-time type information instead of 
`TypeInfo`, but doing so will force the implementation through 
semantic processing, which, in it's current state, will fail to 
compile.  It needs to be refactored, and creating @safe, nothrow, 
pure building blocks will help with that, hence the topic of this 
thread.

Mike


More information about the Digitalmars-d mailing list