-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Introduce UnpackedKind #48452
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Introduce UnpackedKind #48452
Conversation
This adds an `UnpackedKind` type as a typesafe counterpart to `Kind`. This should make future changes to kinds (such as const generics!) more resilient, as the type-checker should catch more potential issues.
src/librustc/ty/subst.rs
Outdated
TYPE_TAG => unsafe { | ||
UnpackedKind::Type(&*((ptr & !TAG_MASK) as *const _)) | ||
}, | ||
_ => bug!("packed kind has invalid tag") |
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.
cc @nikomatsakis Should this be bug!
? That seems expensive. intrinsics::unreachable()
should be fine since Kind
can't be safely created with a different tag, and would avoid unnecessary cases in match
es.
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 agree that unreachable!
in this case seems ok, since we're meddling in unsafe code, and this is inside the abstraction barrier. Plus this is "inner loop" code.
r=me when the fallback case in |
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.
❤️
Ok(Kind::from(relation.relate_with_variance(variance, &a_r, &b_r)?)) | ||
} else { | ||
bug!() | ||
match (a.unpack(), b.unpack()) { |
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.
nice, I've been wanting this to be done forever =)
src/librustc/ty/subst.rs
Outdated
TYPE_TAG => unsafe { | ||
UnpackedKind::Type(&*((ptr & !TAG_MASK) as *const _)) | ||
}, | ||
_ => bug!("packed kind has invalid tag") |
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 agree that unreachable!
in this case seems ok, since we're meddling in unsafe code, and this is inside the abstraction barrier. Plus this is "inner loop" code.
@bors r+ |
📌 Commit f2b9686 has been approved by |
🌲 The tree is currently closed for pull requests below priority 99, this pull request will be tested once the tree is reopened |
Introduce UnpackedKind This adds an `UnpackedKind` type as a typesafe counterpart to `Kind`. This should make future changes to kinds (such as const generics!) more resilient, as the type-checker will be able to catch more potential issues. r? @eddyb cc @yodaldevoid
This adds an
UnpackedKind
type as a typesafe counterpart toKind
. This should make future changes to kinds (such as const generics!) more resilient, as the type-checker will be able to catch more potential issues.r? @eddyb
cc @yodaldevoid