On Friday, May 22, 2020 9:29:03 AM MDT Timon Gehr via Digitalmars-d-announce 
wrote:
> On 22.05.20 16:49, bachmeier wrote:
> > I don't see that marking an extern(C) function @trusted buys you
> > anything, at least not until you can provide a compiler guarantee for
> > arbitrary C code.
>
> It buys you the ability to call that function from @safe code. Clearly
> you can't mark it @safe because the compiler has not checked it.

Yes, and @trusted in general buys you the ability to segregate and find code
that is doing stuff that the compiler was unable to prove was @safe. Then
when there's a bug related to memory safety, you know where to look.

C functions cannot be @safe, because they haven't been vetted by the
compiler. So, either what they're doing is actually memory safe (and it's
fine to mark whem with @trusted), or what it's doing is memory safe if used
correctly, and the calling code needs to be marked @trusted when using it
correctly. Either way, the code with potential memory safety issues is
segregated, and so when inevitably you do run into a memory safety bug, you
know that it's either the @trusted code or the @system code that it calls
which needs to be fixed.

Of course, with this DIP, @safe no longer truly means that the code was
vetted by @safety by the compiler but rather that all of the code that the
compiler can see has been vetted for @safety, meaning that when there is an
@safety bug, you must look not only for @trusted code, but you must look for
non-extern(D) declarations which have been implictly treated as @trusted by
the compiler. @safe still has value (and may even provide more value in that
it will be used more often), but it provides much weaker guarantees in the
process.

- Jonathan M Davis



Reply via email to