-
Notifications
You must be signed in to change notification settings - Fork 13.8k
the #[track_caller]
shim should not inherit #[no_mangle]
#145724
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
Open
folkertdev
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
folkertdev:track-caller-drop-no-mangle
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
Changes from all commits
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
tests/ui/rfcs/rfc-2091-track-caller/shim-does-not-modify-symbol.rs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//@ run-pass | ||
#![feature(rustc_attrs)] | ||
|
||
// The shim that is generated for a function annotated with `#[track_caller]` should not inherit | ||
// attributes that modify its symbol name. Failing to remove these attributes from the shim | ||
// leads to errors like `symbol `foo` is already defined`. | ||
// | ||
// See also https://github.com/rust-lang/rust/issues/143162. | ||
|
||
#[unsafe(no_mangle)] | ||
#[track_caller] | ||
pub fn foo() {} | ||
|
||
#[unsafe(export_name = "bar")] | ||
#[track_caller] | ||
pub fn bar() {} | ||
|
||
#[rustc_std_internal_symbol] | ||
#[track_caller] | ||
pub fn baz() {} | ||
|
||
fn main() { | ||
let _a = foo as fn(); | ||
let _b = bar as fn(); | ||
let _c = baz as fn(); | ||
} |
This file contains hidden or 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
Oops, something went wrong.
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.
Doesn't look like the
if
s are necessary? They don't seem to be communicating anything either.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
if
s prevent a clone (done byto_mut
) if nothing needs to be updated. the vast majority of shims are not#[track_caller]
functions with#[no_mangle]
, so unconditionally cloning the full attrs struct seemed expensive when we first introduced this logic.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.
hmm. what if we combined the ifs? given the explanation the current version is okay, but I feel like come comments would be beneficial (just to explain that we want to avoid expensive cloning)
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 added a comment on the
Cow::Borrowed
up top. I don't think combining the if conditions helps?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 wondering whether something like
if attrs.flags.intersects(CodegenFnAttrFlags::NO_MANGLE | CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) || attrs.symbol_name.is_some() {}
would make it look nicerThere 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 think, given the formatting, that just makes it messier. the current code may feel repetitive, but it is straightforward.
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.
like, this is shorter, but kind of too dense for my liking
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.
@rustbot ready
lmk if you do strongly feel that the above is preferable.