1
1
// Copyright Kani Contributors
2
2
// SPDX-License-Identifier: Apache-2.0 OR MIT
3
3
4
- use anyhow:: Result ;
4
+ use anyhow:: { bail , Result } ;
5
5
use kani_metadata:: { ArtifactType , HarnessMetadata } ;
6
6
use rayon:: prelude:: * ;
7
7
use std:: path:: Path ;
@@ -10,33 +10,33 @@ use crate::args::OutputFormat;
10
10
use crate :: call_cbmc:: { VerificationResult , VerificationStatus } ;
11
11
use crate :: project:: Project ;
12
12
use crate :: session:: KaniSession ;
13
- use crate :: util:: specialized_harness_name;
13
+ use crate :: util:: { error , specialized_harness_name} ;
14
14
15
15
/// A HarnessRunner is responsible for checking all proof harnesses. The data in this structure represents
16
16
/// "background information" that the controlling driver (e.g. cargo-kani or kani) computed.
17
17
///
18
18
/// This struct is basically just a nicer way of passing many arguments to [`Self::check_all_harnesses`]
19
- pub ( crate ) struct HarnessRunner < ' sess > {
19
+ pub ( crate ) struct HarnessRunner < ' sess , ' pr > {
20
20
/// The underlying kani session
21
21
pub sess : & ' sess KaniSession ,
22
22
/// The project under verification.
23
- pub project : Project ,
23
+ pub project : & ' pr Project ,
24
24
}
25
25
26
26
/// The result of checking a single harness. This both hangs on to the harness metadata
27
27
/// (as a means to identify which harness), and provides that harness's verification result.
28
- pub ( crate ) struct HarnessResult < ' sess > {
29
- pub harness : & ' sess HarnessMetadata ,
28
+ pub ( crate ) struct HarnessResult < ' pr > {
29
+ pub harness : & ' pr HarnessMetadata ,
30
30
pub result : VerificationResult ,
31
31
}
32
32
33
- impl < ' sess > HarnessRunner < ' sess > {
33
+ impl < ' sess , ' pr > HarnessRunner < ' sess , ' pr > {
34
34
/// Given a [`HarnessRunner`] (to abstract over how these harnesses were generated), this runs
35
35
/// the proof-checking process for each harness in `harnesses`.
36
- pub ( crate ) fn check_all_harnesses < ' a > (
36
+ pub ( crate ) fn check_all_harnesses (
37
37
& self ,
38
- harnesses : & ' a [ HarnessMetadata ] ,
39
- ) -> Result < Vec < HarnessResult < ' a > > > {
38
+ harnesses : & ' pr [ & HarnessMetadata ] ,
39
+ ) -> Result < Vec < HarnessResult < ' pr > > > {
40
40
let sorted_harnesses = crate :: metadata:: sort_harnesses_by_loc ( harnesses) ;
41
41
42
42
let pool = {
@@ -47,10 +47,10 @@ impl<'sess> HarnessRunner<'sess> {
47
47
builder. build ( ) ?
48
48
} ;
49
49
50
- let results = pool. install ( || -> Result < Vec < HarnessResult < ' a > > > {
50
+ let results = pool. install ( || -> Result < Vec < HarnessResult < ' pr > > > {
51
51
sorted_harnesses
52
52
. par_iter ( )
53
- . map ( |harness| -> Result < HarnessResult < ' a > > {
53
+ . map ( |harness| -> Result < HarnessResult < ' pr > > {
54
54
let harness_filename = harness. pretty_name . replace ( "::" , "-" ) ;
55
55
let report_dir = self . project . outdir . join ( format ! ( "report-{harness_filename}" ) ) ;
56
56
let goto_file =
@@ -139,11 +139,27 @@ impl KaniSession {
139
139
"Complete - {succeeding} successfully verified harnesses, {failing} failures, {total} total."
140
140
) ;
141
141
} else {
142
- // TODO: This could use a better error message, possibly with links to Kani documentation.
143
- // New users may encounter this and could use a pointer to how to write proof harnesses.
144
- println ! (
145
- "No proof harnesses (functions with #[kani::proof]) were found to verify."
146
- ) ;
142
+ match ( self . args . harnesses . as_slice ( ) , & self . args . function ) {
143
+ ( [ ] , None ) =>
144
+ // TODO: This could use a better message, possibly with links to Kani documentation.
145
+ // New users may encounter this and could use a pointer to how to write proof harnesses.
146
+ {
147
+ println ! (
148
+ "No proof harnesses (functions with #[kani::proof]) were found to verify."
149
+ )
150
+ }
151
+ ( [ harness] , None ) => {
152
+ bail ! ( "no harnesses matched the harness filter: `{harness}`" )
153
+ }
154
+ ( harnesses, None ) => bail ! (
155
+ "no harnesses matched the harness filters: `{}`" ,
156
+ harnesses. join( "`, `" )
157
+ ) ,
158
+ ( [ ] , Some ( func) ) => error ( & format ! ( "No function named {func} was found" ) ) ,
159
+ _ => unreachable ! (
160
+ "invalid configuration. Cannot specify harness and function at the same time"
161
+ ) ,
162
+ } ;
147
163
}
148
164
}
149
165
0 commit comments