Repository navigation
Introduce project and stop merging all files generated by the compiler - #1956
Conversation
- Harnesses with the same name in different crates can interfere with each other.
tedinski
left a comment
There was a problem hiding this comment.
There is a lot going on here and I'm not sure how to review it. There seems to be lots of behavior changes, some potentially unintended? (e.g. --function?, are the files generated changed? I can't tell. Wait, they must be, that one test changed. Do restrictions still work? There's changes there too and I can't figure out if they're significant. Does this change the behavior of the legacy linker in subtle ways?)
This seems to try to factor out common code from the various entry points, which sure, but the result is just big and complicated and I can't figure it out. I can't tell if that's just a bad abstraction (there's a REASON I went with a small amount of copy/paste code between the entry points) or if that's part of the changes needed to make the multiple artifacts work, or both.
As for path forward, I guess I'd at least like to see:
- Some thinking through of the behavior changes. This is I/O heavy code, so isn't (shouldn't won't) be something we can be confident in just by running the regression suite. I'm particularly curious about the deliberate deletion of code saying "hey we have to handle
--functionwhen it's not a harness" seemingly without concern? - I think at a minimum if
Projectis going to be a useful abstraction is needs to be cleaner than it is right now. I don't know how right now. This PR overflowed my ability to understand what was changing
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| # Test that Kani can handle harnesses in different crates with the same name | ||
|
|
||
| [workspace] |
There was a problem hiding this comment.
Did this fail before? I thought you'd want to do this with multiple same names under tests/ not multiple crates in a workspace
There was a problem hiding this comment.
Yes, this failed before in an unsound way. When we merge all the goto into one, Kani still know it has two harnesses, but their body become the same.
| )] | ||
| pub concrete_playback: Option<ConcretePlaybackMode>, | ||
| /// Keep temporary files generated throughout Kani process | ||
| /// Keep temporary files generated throughout Kani process. This is a no-op for `cargo-kani`. |
There was a problem hiding this comment.
Yes, isn't it? Cargo kani never deletes their temporary files.
There was a problem hiding this comment.
I updated the comment. Let me know if that makes sense.
| /// If the harness has information about the goto_file we can use that to find the exact file. | ||
| /// For cases where there is no goto_file, we just assume that everything has been linked | ||
| /// together. I.e.: There should only be one artifact of the given type. | ||
| pub fn get_harness_artifact( |
There was a problem hiding this comment.
why does this exist at all? Shouldn't we record this stuff in HarnessMetadata?
There was a problem hiding this comment.
No, I don't think so. The HarnessMetadata should really just have properties of the harness. The fact that the harness metadata has information about the goto_file is also not great and it was a shortcut to get some of this work done.
I also don't think kani-driver should really be modifying that object. The metadata is a communication mechanism that is meant to go one way, the compiler writes them and the driver reads them. I believe #1758 kind of touches that point.
I really dislike that we create mock harnesses metadata, but this is a problem for later.
The one thing I don't like about this new code is that we are passing HarnessMetadata everywhere. I would like to eventually think about a better mechanism to index a harness or a better structure to pass around.
| serde_json::to_writer_pretty(writer, &metadata).unwrap(); | ||
| } | ||
|
|
||
| pub fn cargo_project(session: &KaniSession) -> Result<Project> { |
There was a problem hiding this comment.
why would this not be part of call_cargo.rs?
There was a problem hiding this comment.
My main reason was simplicity and trying really hard to scope down this PR. I wanted to try to avoid changing call_cargo.rs because that code itself needs some refactoring (and this PR was already getting too big). So this code does a simple mapping between what call_cargo.rs generate.
FYI, the refactoring I'm talking about is to be able to get rid of cleaning the build artifacts.
| } | ||
| } | ||
|
|
||
| pub struct StandaloneProjectBuilder<'a> { |
There was a problem hiding this comment.
What is this for? Why is there a builder? And why isn't it part of call_single_file.rs?
There was a problem hiding this comment.
I can flatten it if you want into one function that calls two other functions. We can add the builder if the process becomes more configurable.
There was a problem hiding this comment.
I wrapped the builder into a standalone_project() function so the API is symmetric for cargo kani and kani.
zhassan-aws
left a comment
There was a problem hiding this comment.
A few comments from a cursory look. Will take a more thorough look today.
| impl StandaloneArgs { | ||
| pub fn validate(&self) { | ||
| self.common_opts.validate::<Self>(); | ||
| self.valid_input().unwrap(); |
There was a problem hiding this comment.
Wouldn't this cause a crash if the input is invalid?
There was a problem hiding this comment.
That's a good point. Let me double check and also add a test case.
There was a problem hiding this comment.
Yes, you were correct. This was crashing. I fixed it. unfortunately I cannot easily add a e2e test because compiletest already provides a valid input. I added a unit test for the valid_input() function.
| serde_json::to_writer_pretty(writer, &metadata).unwrap(); | ||
| } | ||
|
|
||
| pub fn cargo_project(session: &KaniSession) -> Result<Project> { |
There was a problem hiding this comment.
Please add documentation.
There was a problem hiding this comment.
Also, should we call this build_project or compile_project?
There was a problem hiding this comment.
Unfortunately, we still have a branch at the beginning of main to see if something is cargo kani or kani, so I kept their names separate. I will try to add symmetry by adding a standalone_project that will replace the builder.
| return Ok(vec![harness.clone()]); | ||
| } | ||
| Ok(metadata.proof_harnesses.clone()) | ||
| Ok(all_harnesses.iter().cloned().cloned().collect()) |
There was a problem hiding this comment.
I changed this to be a map to get rid of the double ref.
| let results = runner.check_all_harnesses(&harnesses)?; | ||
|
|
||
| ctx.print_final_summary(&results) | ||
| let project = project::cargo_project(&session)?; |
I'm sorry this PR is bigger than I would like it to be too. I tried really hard to scope it down, but in some cases just didn't make sense to replicate a hack or purposely inject them in the new code to keep the behavior exactly as it was. It also didn't make sense to create an intermediate fix as a separate PR since the new code was going to fix them by design. I believe the only behavioral change in this PR is that I disabled All the other behavioral changes, they are actually fixes to inconsistent / incorrect behaviors. They are the following:
Regarding the deliberate deletion of "hey we have to handle I'm happy to talk offline about a better abstraction for Project. I also agree that it could be better, but anything more sophisticated would require even more refactoring. I tried to keep it minimal, today it has 2 public members and 2 public functions. |
Co-authored-by: Zyad Hassan <[email protected]>
| if out_dir.exists() && !out_dir.is_dir() { | ||
| return Err(Error::raw( | ||
| ErrorKind::InvalidValue, | ||
| "Invalid argument: `--target-dir` argument `{}` is not a directory", |
There was a problem hiding this comment.
The argument (out_dir) is missing from the error message.
There was a problem hiding this comment.
And I'm missing the format call. That's why I need to add tests here.
There was a problem hiding this comment.
Are you still planning on adding a format call?
There was a problem hiding this comment.
I can't believe I forgot the format. I must be going crazy. Sorry about that. Let me fix this
There was a problem hiding this comment.
Ah, I did add format somewhere else. I guess I just missed this one. Thanks for catching this.
- Fixed comments - Improved documentation - Fix argument validation + add unit test - Add `standalone_project()`
| if out_dir.exists() && !out_dir.is_dir() { | ||
| return Err(Error::raw( | ||
| ErrorKind::InvalidValue, | ||
| "Invalid argument: `--target-dir` argument `{}` is not a directory", |
There was a problem hiding this comment.
Are you still planning on adding a format call?
|
|
||
| let c_demangled = alter_extension(output, "demangled.c"); | ||
| self.demangle_c(symtabs, &c_outfile, &c_demangled)?; | ||
| let symtabs = project.get_harness_artifact(&harness, ArtifactType::SymTab).unwrap(); |
There was a problem hiding this comment.
Should this be a singular symtab?
| /// | ||
| /// For one specific harness, there should be up to one artifact of each type. I.e., artifacts of | ||
| /// the same type are linked as part of creating the project. Except for `symtab` files used for | ||
| /// demangling `C` when on legacy linker mode. |
There was a problem hiding this comment.
Does this comment still apply given that this PR makes --legacy-linker conflict with --gen-c?
Hopefully I got the `format!()` right this time. LOL
Description of changes:
This PR is a pre-req for getting a per-harness reachability algorithm. First we need to stop treating all
gotogenerated by the compiler as the same model which is what this PR does.For that, I introduce the concept of a project, which is basically a container of artifacts produced by the build system. The goal is to abstracts the verification code from the build system we pick. It also provide methods to get artifacts relevant to a harness. Today this method will return the artifact related to the crate where it is contained, but in the future it can be easily modified to be the harness specific goto model.
As part of this refactoring, this fixes the issue with conflicting harnesses name. I also believe this fixes #1448 and it fixes #1910.
Resolved issues:
Fixes #1974
Fixes #1910
Related RFC:
Call-outs:
--legacy-linkerand--function. Fixing these two cases will take more effort, and I'm not sure it's worth it at this point. If people feel strong about them, I think they should be fixed in a separate PR since it will require more changes.assessfor standalone Kani. But it is also out of scope right now.Testing:
How is this change tested? New test + old test
Is this a refactor change?
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
edit: Add #1974 as part of the fixes and remove #1448 since it was fixed by the MIR Linker.