-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Check for uninhabitedness instead of never #54123
Conversation
@@ -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() { |
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.
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() { |
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.
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()); |
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.
similarly here, the previous assert was stronger
Ah makes sense, still not sure if these PRs can be reviewed independently |
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. |
Closing this PR in favour of merging #54125. |
…, 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
Instead of checking for
!
, in many places we can simply check that a type is uninhabited.Pulled out of #47291 and #50262.
r? @nikomatsakis