-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safe by default v2 #228
Open
skyline131313
wants to merge
3
commits into
dlang:master
Choose a base branch
from
skyline131313:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Safe by default v2 #228
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to write such a DIP myself; I was waiting for
-preview=dip1000
to become the default. I think that any and all declarations with no body should have explicit@safe
/@trusted
/@system
attributes and that even considering linkage is a mistake.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that considered a mistake?
You are interfacing with a language that has no notion of any safety guarantees. Ignoring differences between languages and the interfaces between them is a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
extern(C)
does not mean "this is C code", it means "C linkage" and could very well be@safe
D code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is, a
@safe
extern(C)
function that is not defined in-place is not verified by the compiler – and@safe
means that the compiler checked it (up to calls to@trusted
). I’m no expert on this, but as far as I understand it’s about mangling. Attributes are not part of the signature ofextern(C)
functions.extern(C) void f() @safe;
could be defined elsewhere asextern(C) void f() @system { … }
. I think D needs some solution to this; Maybe I’m naïve, but it could be as easy as generating mock symbols that actually include attributes that lead to linker errors when the attributes don’t match.At least until 2.096.0, this worked:
If you change
extern(C)
toextern(D)
, you get the link error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's
@safe
D code then they can just import it. It doesn't matter if it's C code, or linkage, it is still going by C's rules. Just cause safe D code can have C linkage doesn't mean it should expose a C linkage of safe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can indeed just import it, but it'll be
extern(C)
all the same. I don't know what "going by C's rules" means.If it's D code with C linkage and it's
@safe
, well, it's@safe
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing does not safeguard you from calling a
@safe
annotatedextern(C)
declared function (e.g. from a .di file) whose definition (implementation in a .d file) is annotated@system
. That’s because the annotation is not visible for the linker.I guess the easiest way would be to allow
extern(C) @safe
function declarations only if they’re also definitions. The proper way would be for D to do something that safeguards you at least in simple and obvious cases.