You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rfc/src/rfcs/0014-harness-partition.md
+18-9Lines changed: 18 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@
10
10
## Summary
11
11
12
12
It can often be useful to subdivide an expensive proof harness so that different parts of the input space are verified separately.
13
+
This is also known as *proof by cases* or a *case split*.
13
14
Adding the built-in ability to partition a proof harness into different pieces (that each make differing assumptions about their inputs) could reduce the cost of expensive proofs, while allowing Kani to automatically check that the partitions cover the entire input space and, thus, will be equivalent to a single-harness proof.
14
15
15
16
## User Impact
@@ -34,7 +35,7 @@ pub fn proof_harness() {
34
35
```
35
36
36
37
Since there are two tricky to analyze function calls, but only one will ever be called on a given input, you might want to verify all values of `input` where `input > 0` that will take the first branch separately from those that will take the second.
37
-
This way, each solve will only have to reason about two of the three complex function calls, and you could use Kani's parallel proof runner to run both proofs at once.
38
+
This way, each verification run will only have to reason about two of the three complex function calls, and you could use Kani's parallel proof runner to run both proofs at once.
38
39
39
40
The best way to currently do this is by manually partitioning out these paths into two proof harnesses.
40
41
@@ -56,7 +57,7 @@ One could also write preconditions for `very_complex_fn_{1_2}` that restrict `in
56
57
57
58
However, either of these strategies:
58
59
-**can affect soundness**--there's no guarantee that your partitions will fully span the space of possible inputs.
59
-
The only way to determine that a set of proofs like the one above are incorrect (as it forgets to verify the value of 0 for `input`) is by manual inspection.
60
+
The only way to determine that a set of proofs like the one above are incomplete (as it forgets to verify the value of 0 for `input`) is by manual inspection.
60
61
This gets infeasible for proofs with complex partition rules like those found in the [proofs for the standard library's unchecked multiplication](https://github.com/model-checking/verify-rust-std/blob/1c4ea17a99b9202f96608473083998b116bb6508/library/core/src/num/mod.rs#L1818-L1836).
61
62
-**increases user burden**--instead of having to write and maintain a single proof, the user now has to handle a proof for each partition.
62
63
@@ -72,7 +73,7 @@ For example, the above would become
-*It takes in an array of `conditions` with the specific length `const N`*, ensuring the number of harnesses we have to generate is knowable at compile time when we're doing partition generation.
128
+
-*It takes in an array of `conditions` with the specific length `const N`*, ensuring the number of harnesses we have to generate is known at compile time when we're doing partition generation.
128
129
-*Partition conditions & the partition closure are represented by function pointers*.
129
130
This allows the user to provide closures of the same signature, but only if those closures do not capture any state.
130
131
Allowing conditions closures to capture runtime state like local variables would be unwise as partitions are conceptually static divisions of a proof which should not depend on runtime values.
131
132
-*The function returns the same type `R` as the underlying partition closure*, with the thought being that value could then be used in later computation without affecting the mechanics of a partition.
132
133
-*The partition variable is bound by `T: Arbitrary`*.
133
134
This would allow us to construct a new non-deterministic value with `kani::any()` that can then be passed to the partition closure.
134
135
135
-
When the `kani-compiler` encounters a call to this function, it will transparently replace the entire `#[kani::proof()]` that called it with a set of new generated functions that, as a whole, will represent the partitioned proof. This new partitioned proof would contain:
136
+
When the `kani-compiler` encounters a call to this function, it will transparently replace the entire `#[kani::proof]` that called it with a set of new generated functions that, as a whole, will represent the partitioned proof. This new partitioned proof would contain:
The behavior of a partition in this case seems ill-defined, so Kani will detect cases where the partition conditions are not constant closures or function items and emit a compile error.
184
+
This would likely require new analysis from Kani to properly detect these cases.
183
185
184
186
## Rationale and alternatives
185
187
186
-
### 1. Allowing overlapping partition conditions
188
+
### 1. `kani::partition` as an attribute
189
+
We had initially considered implementing the partition as an attribute placed on a proof harness, similar to `kani::proof`.
190
+
However, we decided it would be best implemented as a function because a partition conceptually represents a split on variables in the proof, rather than something inherent to the proof itself.
191
+
Similarly, we wanted to maintain the convention that proof harnesses do not take in any inputs, and all attribute solutions would have to break that.
192
+
193
+
### 2. Allowing overlapping partition conditions
187
194
As a corollary to checking that partitions span the space of all possible inputs, I had initially considered giving a warning if partitions are overlapping as this could indicate ill-defined bounds.
188
195
189
-
However, this kind of overlap would not affect the correctness of the partition, as every possible value of the partition variable would still be checked, just potentially more than once. Admittedly, it's fairly difficult to come up with a realistic use case in which an overlap is helpful for users, so whether this should be allowed is up for debate.
196
+
However, this kind of overlap would not affect the correctness of the partition, as every possible value of the partition variable would still be checked, just potentially more than once.
197
+
Admittedly, it's fairly difficult to come up with a realistic use case in which an overlap is helpful for users, so whether this should be allowed is up for debate.
190
198
191
199
## Open questions
192
200
@@ -199,6 +207,7 @@ Potentially through a separate function `partition_bounded` which would be gener
199
207
Users may only want to test a subset of the input space (e.g., only testing multiplication for certain integer ranges), but the current design mandates that they cover the whole input space.
200
208
We could potentially introduce a separate API, e.g. `unsafe_partition`, that allows this, or some other mechanism to skip the coverage check.
201
209
6. Should overlapping partition conditions be allowed?
202
-
7. Can we tell the user which section(s) of the input space they're missing?
210
+
7. (Similar to #3) How can a coverage check failure be best presented to users?
211
+
Perhaps by running the coverage harness with concrete playback to generate a test case that doesn't fall into the partitions?
203
212
204
213
[^unstable_feature]: This unique ident should be used to enable features proposed in the RFC using `-Z <ident>` until the feature has been stabilized.
0 commit comments