-
Notifications
You must be signed in to change notification settings - Fork 112
Kani module stubs for development #3778
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
Comments
Yes, this is definitely something that's been in our radar. I think this would also play nicely with things like #2035. I think the main question is how to ensure compatibility between the crate version a user is importing and the one Kani is using. Especially if dependencies start exporting things like |
I'm using cargo cfg dependencies to do this right now, and after a bit of trial and error it seems to be working. Kani helpfully has rather extensive documentation, which I can now see on hover and get autocomplete for. The final working solution for code completion, documentation, error reporting, and highlighting under It requires that rust-analyzer use nightly, because the kani crate uses nightly features, but I think thats fine, and it does not requiring using the same (pinned) nightly as kani does. (For example, I am currently on This solution also allows the crate to continue compiling on stable, if it otherwise does so. No nightly-only changes are required to The purpose of the Cargo.toml "dependency" is purely for IDE use, and the reason it uses a custom The specific name for this is unimportant and can be changed at any time, and it may be advisable to pick a unique cfg name for this case, something that dependencies are not likely to have used, to prevent spurious problems. Cargo.toml is configured with a cfg / "platform specific" dependency. [target.'cfg(rust_analyzer)'.dependencies.kani]
git = "https://github.com/model-checking/kani"
tag = "kani-0.62.0" Rust-analyzer configured as follows, so that its analysis sees the kani dependency. This also ignores the "rust-analyzer.cargo.extraEnv": {
"RUSTFLAGS": "--cfg=rust_analyzer",
},
"rust-analyzer.procMacro.ignored": {
"kani_macros": [
"proof"
],
}, build.rs as follows, so that code is actually checked with the Without this step you will get highlighting, completion, and hover documentation, but not error reporting / red squiggles for
The reason why is that it will apply to all your dependencies, and if any of them happen to use kani themselves, their Setting it in This will have the side effect that you cant use Arbitrary implementations from dependencies if you wanted to without getting IDE errors. I don't believe there is any way around that while retaining error reporting for your own code, and I dont make use of this myself as of yet. fn main() {
println!("cargo::rerun-if-changed=build.rs");
#[cfg(rust_analyzer)]
println!("cargo::rustc-cfg=kani");
} Note that the use of build.rs introduces a potential problem: There is a workaround, which also requires nightly: the cargo The custom "rust-analyzer.cargo.extraEnv": {
"RUSTFLAGS": "--cfg=rust_analyzer",
"CARGO_HOST_RUSTFLAGS": "--cfg=rust_analyzer",
"CARGO_UNSTABLE_HOST_CONFIG": "true",
"CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST": "true",
"CARGO_TARGET_APPLIES_TO_HOST": "false",
}, |
Requested feature: Kani module stubs for development
Use case:
Kani is currently difficult to use in an IDE because the kani module is only injected when running
cargo kani
. This means that while writing harnesses in the IDE along with my code, the IDE does not recognize any statements likekani::any()
. This adds friction to writing new test harnesses and I cannot use facilities in the IDE to identify issues before I run my harness.If there could a module published that provided stubs for the Kani API, it would be useful for allowing the IDE to do basic type checks, etc.
The text was updated successfully, but these errors were encountered: