Skip to content

Check for uninhabitedness instead of never #54123

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

Closed
wants to merge 1 commit into from

Conversation

varkor
Copy link
Member

@varkor varkor commented Sep 11, 2018

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-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 11, 2018
@@ -279,7 +279,8 @@ pub fn create_function_debug_context(
}
None => {}
};
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
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

@@ -137,7 +136,7 @@ pub fn declare_fn(
let fty = FnType::new(cx, sig, &[]);
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
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -457,7 +457,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
// we can do what we like. Here, we declare that transmuting
// 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
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
Member Author

varkor commented Sep 11, 2018

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

@oli-obk
Copy link
Contributor

oli-obk commented Sep 11, 2018

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

@varkor
Copy link
Member Author

varkor commented Sep 11, 2018

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
Member Author

varkor commented Sep 20, 2018

Closing this PR in favour of merging #54125.

@varkor varkor 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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants