Conversation
e3f6d77 to
30c073d
Compare
This comment has been minimized.
This comment has been minimized.
30c073d to
dd4e148
Compare
c7aa3cf to
d9d3b13
Compare
|
|
||
| // Finally, resolve all regions. This catches wily misuses of | ||
| // lifetime parameters. | ||
| let errors = infcx.resolve_regions(external_impl, param_env, []); |
There was a problem hiding this comment.
I pass an empty array for the assumed_wf_tys here, I can't really find what this argument is for, is this correct?
There was a problem hiding this comment.
Passing an empty array in the resolve_regions call inside compare_eii_function_types causes no tests to fail, so would also like to add a test for that once I understand what it does
There was a problem hiding this comment.
seems to be related to the "implied bounds hack" which seems to be part of how we resolve GATs in traits. Since this code is mostly adapted from method comparison in traits that makes sense to me, but I don't think we need it for EIIs. @lcnr could you confirm that?
There was a problem hiding this comment.
There was a problem hiding this comment.
relevant for static FOO<'a, 'b>: &'a &'b () = &&(); to add an assumption that 'b: 'a holds.
Given that statics don't have any where-bounds/generics anyways, this shouldn't matter
|
|
|
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 |
It is the other way around, a single item can implement multiple EIIs. The definition of the EII is an TLDR: It is exactly as sound as external statics are, since it's basically just an external static |
2cb2f25 to
d2c3767
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. |
|
@rustbot ready |
|
it's correct that with EIIs you can get multiple statics aliasing eachother. We might want to disallow static mut EIIs completely? |
|
even with a single EII, #[eii(a)]
static FOO: usize;
#[a]
static BAR: usize = 3;
fn main() {
assert_eq!(
&BAR as *const _ as usize,
&FOO as *const _ as usize
);
} |
|
The thing is that FOO is not a unsafe extern "Rust" {
safe static FOO: usize;
}
mod imp {
#[unsafe(no_mangle)]
pub static FOO: usize = 3;
}
fn main() {
assert_eq!(
&FOO as *const _ as usize,
&imp::FOO as *const _ as usize
);
}i.e. Is this code unsound? |
|
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 |
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