Skip to content

Check for uninhabitedness instead of never - #54123

Closed
varkor wants to merge 1 commit into
rust-lang:masterfrom
varkor:never-to-uninhabited
Closed

Check for uninhabitedness instead of never#54123
varkor wants to merge 1 commit into
rust-lang:masterfrom
varkor:never-to-uninhabited

Conversation

@varkor

Copy link
Copy Markdown
Contributor

Instead of checking for !, in many places we can simply check that a type is uninhabited.

Pulled out of #47291 and #50262.

r? @nikomatsakis

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 11, 2018
};
if cx.layout_of(sig.output()).abi == ty::layout::Abi::Uninhabited {
// Tell LLVM that functions that return uninhabited types will not return.
if sig.output().conservative_is_uninhabited() {

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.

isn't this way more conservative than the layout check? I think this should stay being the layout check. It does not influence type checking, just llvm optimizations

let llfn = declare_raw_fn(cx, name, fty.llvm_cconv(), fty.llvm_type(cx));

if cx.layout_of(sig.output()).abi == layout::Abi::Uninhabited {
if sig.output().conservative_is_uninhabited() {

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.

same here

// into an uninhabited type is impossible, so anything following
// it must be unreachable.
assert_eq!(bx.cx.layout_of(sig.output()).abi, layout::Abi::Uninhabited);
assert!(sig.output().conservative_is_uninhabited());

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.

similarly here, the previous assert was stronger

@varkor

Copy link
Copy Markdown
ContributorAuthor

@oli-obk: with #54125, conservative_is_uninhabited should be slightly stronger.

@oli-obk

Copy link
Copy Markdown
Contributor

Ah makes sense, still not sure if these PRs can be reviewed independently

@varkor

Copy link
Copy Markdown
ContributorAuthor

Yeah, in retrospect, the order of dependency would work better flipped.

@nikomatsakis: it might make sense to review #54125 directly (as that PR includes the changes here) instead.

@varkor

Copy link
Copy Markdown
ContributorAuthor

Closing this PR in favour of merging #54125.

@varkorvarkor closed this Sep 20, 2018
@varkor
varkor deleted the never-to-uninhabited branch September 20, 2018 19:23
bors added a commit that referenced this pull request Sep 26, 2018
…, r=<try>
Less conservative uninhabitedness check
Extends the uninhabitedness check to structs, non-empty enums, tuples and arrays.
Pulled out of #47291 and #50262. Blocked on #54123.
r? @nikomatsakis
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@varkor@oli-obk@nikomatsakis@rust-highfive