-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
TypeId differs between builds #61553
Comments
Marking as a possible soundness hole until shown otherwise. |
Not a rustc bug and I think not a soundness bug either. When compiling from
TypeId changes depending on this flag. Given fn type_of<T:'static>(t: T) -> std::any::TypeId {
std::any::TypeId::of::<T>()
}
fn main() {
println!("{:?}", type_of(main));
} The output changes as such:
|
@nagisa Are you trying to say that building the same crate from different paths should change TypeId? My point is pretty concrete:
|
@nagisa |
(Note that, from when I've seen it on multiple projects in and outside of Rust, the word "globally", for better or for worse, does not cover the scope of Earth's globe itself. The scope of "globally" is, unfortunately, often quite dependent on the local context...) |
triage: Leaving nominated to discuss at T-compiler meeting. (I suspect I may need to add T-lang as well, but I'll wait until the meeting to do so.) |
I don’t… know, but consider, for example, why the
I’m not sure why cargo uses a different |
@nagisa / No idea why I reported it to cargo repo. |
So, I think the term global here means "global to within one binary". When you build a given binary, the type-id for the same type ought to be consistent for all uses of that. But if you have the same crate with distinct metadata, that is treated by the compiler as two different versions of the crate -- i.e., there are two types. This is like having two distinct cargo versions. I think that's what's happening here. |
Ok. Now I begin to see the idea. Also you can easily see that library TypeId is also the same as main binary's, but still different between two compilations. |
triage: I believe this is not a bug, but rather the system operating as designed (that is, it is operating with an expected amount of freedom in terms of how it assigns type-id values). Leaving unprioritized (with intent to close) but also nominated so that lang team gets chance to confirm or contradict my aforementioned belief. |
It's kind of strange that nobody seems to notice the exact issue which sticks out of this "feature" - the inability to reliably handle exceptions crossing dynamic library boundaries. |
@MageSlayer sorry for being slow to get back to you. The conclusion of this issue is that the current behavior -- at least from rustc's point-of-view -- is expected. Distinct It's true that we don't really have strong support for handling exceptions across dylib boundaries. That might be an interesting thing to try and address, but that would be a new feature, and hence best addressed by trying to write a Pre-RFC on internals to explore the problem and perhaps eventually through an RFC. Thanks for filing the issue! |
Hi
I am getting strange inconsistencies between type_id results between crate compilations.
Please see attached test.
Tested in Rust Nightly:
To reproduce:
cargo-issue-1244.tar.gz
The text was updated successfully, but these errors were encountered: