-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implemented a linkage attribute for functions and foreign statics. #9966
Conversation
// except according to those terms. | ||
|
||
#[linkage(external)] | ||
#[inline(always)] |
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.
Why inline(always)
? To check that linkage(external)
is forcing it to stay around? (Worth a comment, probably.)
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.
It makes the test behaves the same (when toggling linkage(external)
), independently of --opt-level
.
What happens for (e.g.) |
That's odd... LLVM doesn't error when using |
I'm a little uneasy about this change. Could you elaborate a little more on what the main purpose for these is going to be? I'm generally of the opinion that we should be able to infer as much of this as possible. We already infer whether to make a function externally visible (or at least we should be correctly doing so). You can very easily shoot yourself in the foot by tinkering with these linkage attributes too much, which rust strives to make it very hard to do so. This seems to be like more of a bug in other portions of the language than to attempt to allow this on a per-item basis. Our management of linkage of symbols is already hairy enough as-is, and throwing this in the mix could very easily produce unexpected results. I personally don't think that we should have the I still believe that all use cases should be encodable in some form of rust, but not necessarily through the use of attributes. Things like:
Again though, I could just be unaware of perfectly legitimate use cases which definitely need fine-grained control over linkage. My perference would be to have a different way to encode this type of use other than being able to specify the linkage per-item, though. |
@alexcrichton: A private |
I was looking over the list of linkages that llvm provides, and this is what I ended up noticing:
From this list, it really seems like the useful ones which you'd want to apply are weak and dllimport/export (although I don't know what they do, so perhaps they are encodable in other rust-isms). Overally, it's not clear to me that we're gaining much by allowing such fine-grained control of linkage attributes. The existing cases where a different linkage is desired seem like a bug that should be fixed or it's wontfix behavior. That being said, I could certainly be unaware of other use cases! |
@alexcrichton: |
The changes implemented by #9945 have landed, so I think the use case this was meant for is now well covered. I think the Windows issue is likely separate, I don't really understand why We can revisit this in the future if a use case comes up. |
…=xFrednet Fix manual_let_else produces a wrong suggestion with or-patterns Fix rust-lang#9938 changelog: Sugg: [`manual_let_else`]: Suggestions for or-patterns now include required brackets. [rust-lang#9966](rust-lang/rust-clippy#9966)
Closes #7196 and obsoletes #9945 (I've reused the test from the latter, with the added
linkage(external)
attribute).The subset of allowed linkages is left to be decided by the reviewers.