DIPs icon indicating copy to clipboard operation
DIPs copied to clipboard

Disallow Unsafe Declarations

Open skyline131313 opened this issue 2 years ago • 5 comments

skyline131313 avatar Jun 15 '22 15:06 skyline131313

Please add your real name and contact info to the author field.

mdparker avatar Jun 16 '22 00:06 mdparker

Forbidding trusted is both impractical and inconsistent (see the above comments). Forbidding safe is easy to justify, as that means mechanically checked. The DIP rationale might need to be very robust however as it seems from past forum discussions that Walter might oppose that. The DIP would need to address Walters specific criticisms. They can be found in the safe by default DIP forum discussions.

ntrel avatar Aug 01 '22 11:08 ntrel

I need your name and contact info, please. I don't understand why Walter's name is on it. Could you elaborate?

mdparker avatar Aug 22 '22 03:08 mdparker

Here's how you can break extern functions:

extern(C) int getpid() @system
{
	//unsafe code here
}

anon17 avatar Sep 26 '22 19:09 anon17

I don't think there is any good reason to prevent annotating an external function @trusted. Consider a safe external function, like abs in the C standard library. Today, it can declared as extern(C) @trusted int abs(int);. With this proposal, this will break, and the declaration will have to be changed to

pragma(mangle, "abs") private extern(C) @system int abs_(int);
@trusted int abs(int arg){return abs_(arg);}

This, in addition to the breakage, is much more verbose and ugly. I don't see what this accomplishes.

Now, preventing @safe on external non-D declarations is a promising idea. Since an external C or C++ function will have to be manually verified for @safety just like a @trusted function, it would make sense that the declaration had to be @trusted.

dukc avatar Nov 12 '22 09:11 dukc