Skip to content

Introduce UnpackedKind - #48452

Merged
bors merged 2 commits into
rust-lang:masterfrom
varkor:unpacked-kind
Feb 25, 2018
Merged

Introduce UnpackedKind#48452
bors merged 2 commits into
rust-lang:masterfrom
varkor:unpacked-kind

Conversation

@varkor

Copy link
Copy Markdown
Contributor

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 to `Kind`. This should make future changes to kinds (such as const generics!) more resilient, as the type-checker should catch more potential issues.
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 23, 2018
Comment threadsrc/librustc/ty/subst.rs Outdated
TYPE_TAG => unsafe {
UnpackedKind::Type(&*((ptr & !TAG_MASK) as *const _))
},
_ => bug!("packed kind has invalid tag")

Copy link
Copy Markdown
Contributor

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 matches.

Copy link
Copy Markdown
Contributor

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.

@eddyb

Copy link
Copy Markdown
Contributor

r=me when the fallback case in unpacked is resolved

@nikomatsakisnikomatsakis left a comment

Copy link
Copy Markdown
Contributor

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()) {

Copy link
Copy Markdown
Contributor

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 =)

Comment threadsrc/librustc/ty/subst.rs Outdated
TYPE_TAG => unsafe {
UnpackedKind::Type(&*((ptr & !TAG_MASK) as *const _))
},
_ => bug!("packed kind has invalid tag")

Copy link
Copy Markdown
Contributor

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.

@eddyb

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Feb 23, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit f2b9686 has been approved by eddyb

@bors

bors commented Feb 23, 2018

Copy link
Copy Markdown
Collaborator

🌲 The tree is currently closed for pull requests below priority 99, this pull request will be tested once the tree is reopened

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 23, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 24, 2018
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
bors added a commit that referenced this pull request Feb 25, 2018
@bors
bors merged commit f2b9686 into rust-lang:masterFeb 25, 2018
@varkor
varkor deleted the unpacked-kind branch February 25, 2018 10:19
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@varkor@eddyb@bors@nikomatsakis@rust-highfive