Repository navigation
Fix codegen of never return functions - #1062
Conversation
I have removed the Nevers hook and I have also introduced two stubs in
our std library to provide more user friendly errors
(std::process::{abort, exit})
tedinski
left a comment
There was a problem hiding this comment.
I think just a style thing: I prefer we use match instead of an if let as an expression.
| pub use std::*; | ||
|
|
||
| // Override process calls with stubs. | ||
| pub mod process; |
There was a problem hiding this comment.
I vaguely recall us having issues with overriding things here that weren't macros. Was that resolved somehow?
There was a problem hiding this comment.
The one I recall failing to override was std::mem::swap, which turned out was because we have a hook for it:
| // Transmuting to an uninhabited type is UB. | ||
| "transmute" => self.codegen_fatal_error( | ||
| PropertyClass::UnsupportedConstruct, | ||
| "transmuting to uninhabited type", | ||
| PropertyClass::DefaultAssertion, | ||
| "transmuting to uninhabited type has undefined behavior", |
There was a problem hiding this comment.
Ah, I made the wrong call helping Jai. Good catch. :)
|
|
||
| let (p, target) = destination.unwrap(); | ||
| let (place, target) = | ||
| if let Some((p, t)) = destination { (Some(p), Some(t)) } else { (None, None) }; |
There was a problem hiding this comment.
Nit: This boggled me. Can we convert to match instead of if let?
There was a problem hiding this comment.
I can. But why did it bother you?
There was a problem hiding this comment.
I think my brain treats if let as statement-like and match as expression-like. This is despite being happy with if as expression-like.
It's possible it's just me needing to get used to it. If you disagree, no problem.
There was a problem hiding this comment.
It took me some time to get used to as well :)
There was a problem hiding this comment.
If you don't mind, I prefer to move on with this PR since there's nothing else to change.
I don't have any strong opinion about this. I tend to favor if let when I'm looking for one specific match. It's less verbose and clear to me that it's an all or nothing situation. We can discuss this later and if one is preferred over the other, maybe we can have a little convention page.
There was a problem hiding this comment.
Yeah, that's fine, I prefer velocity over this nit.
| let call_stmt = if let Some(place) = place { | ||
| self.codegen_expr_to_place(place, call).with_location(loc.clone()) | ||
| } else { | ||
| call.as_stmt(loc.clone()) | ||
| }; |
| if i == 2 { | ||
| // This should never happen. | ||
| process::abort(); | ||
| process::exit(1); |
There was a problem hiding this comment.
The comment says test abort but now we're calling exit. Is there a reason for choosing either?
There was a problem hiding this comment.
I just wanted to increase test coverage
| Description: "Function abort() was invoked"\ | ||
| in function std::process::abort | ||
|
|
||
| Status: SUCCESS\ |
There was a problem hiding this comment.
I was expecting this to be UNREACHABLE, but it isn't because std::exit calls panic which we currently don't override. If we want it to be reported as UNREACHABLE (I think it should, but I'm not sure), then we can change the panic!(msg) to assert!(false, msg).
There was a problem hiding this comment.
We can't. It won't compile because of the never return. I think we should instrument panic inside the compiler to have a reach check.
|
|
||
| struct Nevers; | ||
|
|
||
| impl<'tcx> GotocHook<'tcx> for Nevers { |
There was a problem hiding this comment.
Nice to get rid of this!
|
|
||
| let (p, target) = destination.unwrap(); | ||
| let (place, target) = | ||
| if let Some((p, t)) = destination { (Some(p), Some(t)) } else { (None, None) }; |
There was a problem hiding this comment.
It took me some time to get used to as well :)
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| //! This module introduces stubs for process methods. |
Yes it does. |
I have removed the Nevers hook and I have also introduced the following stubs in our std library to provide more user friendly errors: - std::process::abort - std::process::exit
I have removed the Nevers hook and I have also introduced the following stubs in our std library to provide more user friendly errors: - std::process::abort - std::process::exit
Description of changes:
I have removed the Nevers hook and I have also introduced two stubs in our std library to provide more user friendly errors. Functions overriden: std::process::{abort, exit}
Resolved issues:
Resolves #648 and resolves #751.
Call-outs:
I did add a tiny fix to a wrong PropertyClass that I noticed while working on this fix.
Testing:
How is this change tested? New test
Is this a refactor change? No
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.