-
Notifications
You must be signed in to change notification settings - Fork 142
Create an RMC crate and load it as part of rmc-rustc #597
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
Changes from all commits
4b79bbf
f05a451
25d1a54
7f458dc
2f22516
ba6ebff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,7 +147,7 @@ impl CodegenBackend for GotocCodegenBackend { | |
|
|
||
| fn link( | ||
| &self, | ||
| _sess: &Session, | ||
| sess: &Session, | ||
| codegen_results: Box<dyn Any>, | ||
| outputs: &OutputFilenames, | ||
| ) -> Result<(), ErrorReported> { | ||
|
|
@@ -157,18 +157,21 @@ impl CodegenBackend for GotocCodegenBackend { | |
| .downcast::<GotocCodegenResult>() | ||
| .expect("in link: codegen_results is not a GotocCodegenResult"); | ||
|
|
||
| // "path.o" | ||
| let base_filename = outputs.path(OutputType::Object); | ||
| // No output should be generated if user selected no_codegen. | ||
| if !sess.opts.debugging_opts.no_codegen && sess.opts.output_types.should_codegen() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be in the same PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The regression will fail if this is not here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can submit a separate PR and merge it first if that makes more sense.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // "path.o" | ||
| let base_filename = outputs.path(OutputType::Object); | ||
|
|
||
| let symtab_filename = base_filename.with_extension("symtab.json"); | ||
| debug!("output to {:?}", symtab_filename); | ||
| let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap(); | ||
| write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap(); | ||
| let symtab_filename = base_filename.with_extension("symtab.json"); | ||
| debug!("output to {:?}", symtab_filename); | ||
| let mut out_file = ::std::fs::File::create(&symtab_filename).unwrap(); | ||
| write!(out_file, "{}", result.symtab.to_irep().to_json().pretty().to_string()).unwrap(); | ||
|
|
||
| let type_map_filename = base_filename.with_extension("type_map.json"); | ||
| debug!("type_map to {:?}", type_map_filename); | ||
| let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap(); | ||
| write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap(); | ||
| let type_map_filename = base_filename.with_extension("type_map.json"); | ||
| debug!("type_map to {:?}", type_map_filename); | ||
| let mut out_file = ::std::fs::File::create(&type_map_filename).unwrap(); | ||
| write!(out_file, "{}", result.type_map.to_json().pretty().to_string()).unwrap(); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| [package] | ||
| name = "rmc" | ||
| version = "0.1.0" | ||
| edition = "2018" | ||
| license = "MIT OR Apache-2.0" | ||
|
|
||
| [dependencies] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| #![feature(rustc_attrs)] // Used for rustc_diagnostic_item. | ||
|
|
||
| /// Creates an assumption that will be valid after this statement run. Note that the assumption | ||
| /// will only be applied for paths that follow the assumption. If the assumption doesn't hold, the | ||
| /// program will exit successfully. | ||
| /// | ||
| /// # Example: | ||
| /// | ||
| /// The code snippet below should never panic. | ||
| /// | ||
| /// ```rust | ||
| /// let i : i32 = rmc::nondet(); | ||
| /// rmc::assume(i > 10); | ||
| /// if i < 0 { | ||
| /// panic!("This will never panic"); | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// The following code may panic though: | ||
| /// | ||
| /// ```rust | ||
| /// let i : i32 = rmc::nondet(); | ||
| /// assert!(i < 0, "This may panic and verification should fail."); | ||
| /// rmc::assume(i > 10); | ||
| /// ``` | ||
| #[inline(never)] | ||
| #[rustc_diagnostic_item = "RmcAssume"] | ||
| pub fn assume(_cond: bool) {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a better docs and IDE experience, it would be preferable to do something like: pub fn assume(cond: bool) {
let _ = cond;
}Same goes for the other arguments.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I'll fix this next time I push some updates to this crate. Thanks for the suggestion. |
||
|
|
||
| /// This creates an unconstrained value of type `T`. You can assign the return value of this | ||
| /// function to a variable that you want to make symbolic. | ||
| /// | ||
| /// # Example: | ||
| /// | ||
| /// In the snippet below, we are verifying the behavior of the function `fn_under_verification` | ||
| /// under all possible i32 input values. | ||
| /// | ||
| /// ```rust | ||
| /// let inputA = rmc::nondet::<i32>(); | ||
| /// fn_under_verification(inputA); | ||
| /// ``` | ||
| #[inline(never)] | ||
| #[rustc_diagnostic_item = "RmcNonDet"] | ||
| pub fn nondet<T>() -> T { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This really needs to be marked as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have pushed this code already, but I created #607 to capture the work to fix this. Thanks
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| unimplemented!("RMC nondet") | ||
| } | ||
|
|
||
| /// Function used in tests for cases where the condition is not always true. | ||
| #[inline(never)] | ||
| #[rustc_diagnostic_item = "RmcExpectFail"] | ||
| pub fn expect_fail(_cond: bool, _message: &str) {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/bash | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
| SCRIPTS_DIR="$(dirname $SCRIPT_DIR)" | ||
| REPO_DIR="$(dirname $SCRIPTS_DIR)" | ||
|
|
||
| export RUSTC=$(${SCRIPTS_DIR}/rmc-rustc --rmc-path) | ||
| cargo build --manifest-path "${REPO_DIR}/library/rmc/Cargo.toml" $@ | ||
|
|
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.
Is there any advantage to having
-xwritten here and not in the script itself?Uh oh!
There was an error while loading. Please reload this page.
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.
I was wondering if this script will be helpful for users to build RMC library. In this case, we can keep the trace turned off by default, but still turn them on in the CI. What do you think?
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.
Makes sense.