-
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
Pad size of TypeId and remove structural equality #99189
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Maybe the padding could be uninitialized data ( |
library/core/src/any.rs
Outdated
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct TypeId { | ||
pad: u64, |
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.
This should have some comment why that field added, as it isn't obvious.
How so? I think a regular |
} | ||
|
||
const fn check_type_id<T: 'static>() -> bool { | ||
matches!(GetTypeId::<T>::VALUE, GetTypeId::<usize>::VALUE) |
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 don't think we should lose the ability to compare type ids in CTFE. Comparison is almost the only thing you can do with a type id. It's possible to make ==
work here, but if that's tricky to do without potentially accidentally stabilizing it in CTFE then I think we should look at adding an unstable const function to compare them.
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.
Note that ==
still works in CTFE, it's just pattern matching that's no longer allowed.
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.
Do you know if we already have a test case that covers that @carbotaniuman?
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, maybe I'm missing something but it doesn't appear that TypeId::of::<T>() == TypeId::of::<U>()
works in CTFE as of nightly
today:
error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): can't compare `TypeId` with `_` in const contexts
--> src/main.rs:6:23
|
6 | TypeId::of::<T>() == TypeId::of::<U>()
| ^^ no implementation for `TypeId == _`
|
= help: the trait `~const PartialEq<_>` is not implemented for `TypeId`
note: the trait `PartialEq<_>` is implemented for `TypeId`, but that implementation is not `const`
--> src/main.rs:6:23
|
6 | TypeId::of::<T>() == TypeId::of::<U>()
| ^^
As far as I can tell that would still be the case after this PR, except that we'd also lose the ability to compare type ids by matching them.
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.
Yeah, it looks like I was mistaken here, and I'll likely reopen this PR with more substantial work behind it.
In miri doing |
☔ The latest upstream changes (presumably #99802) made this pull request unmergeable. Please resolve the merge conflicts. |
A crater run was done #75923 (comment), and @m-ou-se's comment #95845 (comment) that the breakage is small and we don't really care about this anyway is probably right (thanks to @Nilstrieb for tracking this down for me). I'm personally not sure it really makes sense to do this incrementally -- we could also just wait until we actually have the hash. That said, it seems reasonable to discuss, so I'm nominating based on request from the author on Discord. |
Landing this PR now (well, mainly the "remove structural equality" part) would unblock |
Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP. I don't think we should be padding the struct right now with unused data, as @thomcc already said. I don't really see much of an advantage in doing that now vs doing that when we actually change to a new TypeId implementation. |
The main reason I was looking to land the breaking change first was so that any follow-up implementation PR wouldn't have to deal with the fallout of crater if/when that gets brought up as I didn't want to put the work in like #75923 and then get stalled. I can split off the structural equality part (and related fixes) now if that part is acceptable, and make a new PR with the widening implementation, assuming the libs team thinks this approach is the correct one. |
I can't promise you that the entire team considers that acceptable, but if you open a separate PR for that, I can start the FCP process to see if everyone is happy to go forward with it. :) |
…atch, r=dtolnay Remove structural match from `TypeId` As per rust-lang#99189 (comment). > Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP. rust-lang#99189 (comment) > Landing this PR now (well, mainly the "remove structural equality" part) would unblock `const fn` `TypeId::of`, since we only postponed that because we were guaranteeing too much. See also rust-lang#99189, rust-lang#101698
…ch, r=dtolnay Remove structural match from `TypeId` As per rust-lang#99189 (comment). > Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP. rust-lang#99189 (comment) > Landing this PR now (well, mainly the "remove structural equality" part) would unblock `const fn` `TypeId::of`, since we only postponed that because we were guaranteeing too much. See also rust-lang#99189, rust-lang#101698
…lnay Remove structural match from `TypeId` As per rust-lang/rust#99189 (comment). > Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP. rust-lang/rust#99189 (comment) > Landing this PR now (well, mainly the "remove structural equality" part) would unblock `const fn` `TypeId::of`, since we only postponed that because we were guaranteeing too much. See also #99189, #101698
…lnay Remove structural match from `TypeId` As per rust-lang/rust#99189 (comment). > Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP. rust-lang/rust#99189 (comment) > Landing this PR now (well, mainly the "remove structural equality" part) would unblock `const fn` `TypeId::of`, since we only postponed that because we were guaranteeing too much. See also #99189, #101698
This implements @eddyb's suggestions from #95845
Given that the lang-team has already committed to a full length cryptographic hash, increasing the size of
TypeId
in preparation for a future change to a cryptographic hash should be a simple stepping stone. This also removes structural equality fromTypeId
for more futureproofing.