Conversation
e3f6d77 to
30c073d
Compare
This comment has been minimized.
This comment has been minimized.
30c073d to
dd4e148
Compare
c7aa3cf to
d9d3b13
Compare
|
|
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred in compiler/rustc_attr_parsing The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
d9d3b13 to
7b3a361
Compare
7b3a361 to
2cb2f25
Compare
| assert!( | ||
| self.instances.borrow_mut().insert(instance, lldecl).is_none(), | ||
| "An instance was already present for {instance:?}" | ||
| ); |
There was a problem hiding this comment.
I'm not sure I understand when this can fail
There was a problem hiding this comment.
or why this sanity check is necessary. I believe it may be, but the comment doesn't explain what scenario this matters in or what bug we previously had with this.
There was a problem hiding this comment.
I've added explanation to the comment, the assert is indeed simply a sanity check
|
The fact that |
|
Disallowing |
|
Currently if you have two extern statics with different symbol names, they would never alias. I can very much imagine that there will be crates which break if two EIIs defined by said crate alias. Breaking both as in causing UB and as in misbehaving without UB. Also it requires having support for aliasing at the object file level, while if each static can define only a single EII, then we can get away without any aliasing support at the object file level. The definition can just have the same symbol name as the EII. And if the EII has a default, this default can either be put in a separate object file only linked when the default is used or be defined as weak symbol. |
|
Right, I agree this is also undesirable
|
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
That doesn't help though, EIIs inherently generate two symbol names for one static. Even if one is extern. And the definition can't get the same name. It should be available under the name given to the implementation as well imo. The same is true for functions atm. |
|
multiple impls does make that worse, but it's already a problem to begin with |
|
also, could you add a test that both have the same address? |
There is no inherent reason why the EII declaration and the impl have to use different symbol names afaik. If you only defining a single EII per static, then |
d2c3767 to
0de8143
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I've made the following changes:
@rustbot ready
EIIs don't do anything other than what foreign statics already do, so I don't understand why this would be needed. With foreign statics the foreign static and the static that implements the foreign static also have two symbols referring to the same address. |
0de8143 to
1b25b5a
Compare
|
r=me after rebase on #152384 |
|
@rustbot blocked |
With foreign statics the foreign static directly uses the symbol name of the target at the object file level. That is how the linker knows to match up the foreign static and the definition of the static. At the object file level symbols don't have an identity separate from their symbol name. Any two symbols with the same name are merged together. |
|
Oh right, indeed the difference is that there is an explicit alias with EII statics, which there isn't with foreign statics... For the following code #[eii(hello)]
static HELLO: u64;
#[hello]
static HELLO_IMPL: u64 = 5;The generated LLVM IR is: So while there are indeed two different symbol names, one is explicitly defined as an alias to the other one, so these should still be merged together by the linker. So I still don't see where the problem is, sorry |
|
☔ The latest upstream changes (presumably #155099) made this pull request unmergeable. Please resolve the merge conflicts. |
View all comments
This PR implements EII for statics. I've tried to mirror the implementation for functions in a few places, this causes some duplicate code but I'm also not really sure whether there's a clean way to merge the implementations.
This does not implement defaults for static EIIs yet, I will do that in a followup PR