-
Couldn't load subscription status.
- Fork 129
Autoharness: enable function-contracts and loop-contracts features by default #4016
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
Autoharness: enable function-contracts and loop-contracts features by default #4016
Conversation
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 this documented in all the necessary places?
- I don't really know of a reason why someone would not want to enable these features, but if such a use case ever comes along: how would we do it?
I forgot to update the book. That's now done. I also removed the limitation about loop contracts, which I fixed in a previous PR.
Assuming that we ever wanted to support the "Alternative" behavior from the PR description, we would:
// `fns_to_verify` contains all the functions eligible for automatic harnesses
for fn_to_verify in fns_to_verify {
if has_function_contract(fn_to_verify) {
if is_enabled(UnstableFeature::FunctionContracts) {
generate_automatic_contract_harness(fn_to_verify);
continue;
} else {
tcx.dcx.warn(format!("
Found {fn_to_verify} which has a function contract, but -Z function-contracts wasn't supplied;
generating a standard harness instead.
"));
}
generate_standard_harness(fn_to_verify);
}i.e., generate a contract harness iff the user opted into the feature, otherwise, generate a standard harness. You could also change this pseudocode to skip over functions with contracts entirely if that was the desired alternate behavior. |
|
More specifically, the constructor of kani/kani-compiler/src/kani_middle/transform/contracts.rs Lines 345 to 360 in 946263e
instantiates the pass for a given harness so that Then, we call kani/kani-compiler/src/kani_middle/transform/contracts.rs Lines 473 to 480 in 946263e
meaning that if a given function
we'll replace its body with the "check" closure to check the contract. To implement the alternative behavior, we'd have to change this logic to only use the "check" closure if it meets the above criteria and the user actually wants automatic harnesses to target contracts. I imagine I'd do this by changing the |
Pull Request is not mergeable
Problem
Right now,
-Z autoharnessimplies-Z function-contracts, since it will generate contract harnesses for contracts it finds without you explicitly opting in. It does not, however, imply-Z loop-contracts, so if you don't provide that flag you can unwind until you hit the default loop bound, and you don't prove the contract. This behavior is inconsistent and confusing.Solution
Autoharness is already unstable, so it feels redundant to make people opt in to instability on top of instability. Instead, just make
-Z autoharnessimply-Z function-contractsand-Z loop-contracts.Alternative
Alternatively, we could make
-Z autoharnessimply neither of these options, and skip functions with contracts altogether / generate standard harnesses for them. But I fear even with warnings, users wouldn't notice we did this, and erroneously conclude that we've proven their contracts. If they're already opting into the unstable autoharness feature, I think we can safely assume they are okay with instability and turn-Z function-contractsand-Z loop-contractson by default.Towards #3832
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.