rapx/verify/config.rs
1//! Verification command options.
2
3use clap::Args;
4pub use crate::vm::constructor_policy::ConstructorMirMode;
5
6
7
8#[derive(Debug, Clone, Copy, clap::ValueEnum)]
9pub enum VerifyMode {
10 #[value(help = "Auto-detect: verify all functions with unsafe callees or struct invariants")]
11 Scan,
12 #[value(help = "Only verify functions annotated with #[rapx::verify]")]
13 Targeted,
14}
15
16/// Postfix repeat count: `auto` (default) enables automatic loop-depth
17/// detection; a number N ≥ 0 sets a fixed repeat count.
18#[derive(Debug, Clone)]
19pub enum PostfixRepeat {
20 Auto,
21 Fixed(usize),
22}
23
24impl std::fmt::Display for PostfixRepeat {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 match self {
27 PostfixRepeat::Auto => write!(f, "auto"),
28 PostfixRepeat::Fixed(n) => write!(f, "{n}"),
29 }
30 }
31}
32
33impl std::str::FromStr for PostfixRepeat {
34 type Err = String;
35 fn from_str(s: &str) -> Result<Self, Self::Err> {
36 if s.eq_ignore_ascii_case("auto") {
37 Ok(PostfixRepeat::Auto)
38 } else {
39 s.parse::<usize>().map(PostfixRepeat::Fixed)
40 .map_err(|_| format!("expected 'auto' or a non-negative integer, got '{s}'"))
41 }
42 }
43}
44
45/// Configuration parsed by the `verify` command and shared throughout verification.
46#[derive(Debug, Clone, Args)]
47pub struct VerifyConfig {
48 /// List collected verification targets and their resolved contracts without running verification.
49 #[arg(long)]
50 pub prepare_targets: bool,
51 /// Number of extra SCC postfix repetitions allowed during path enumeration.
52 /// `auto` (default) estimates the needed repetitions for each target.
53 /// A number N checks repeat counts from 0 through N.
54 #[arg(long, default_value = "auto", value_parser = clap::value_parser!(PostfixRepeat))]
55 pub postfix_repeat: PostfixRepeat,
56 /// Verification mode: `scan` auto-detects unannotated unsafe targets (default), `targeted` verifies `#[rapx::verify]` functions.
57 #[arg(long, default_value = "scan")]
58 pub mode: VerifyMode,
59 /// Skip standalone struct and type invariant checks and verify
60 /// constructor-mutator-method sequences instead.
61 #[arg(long = "no-invariant-target")]
62 pub skip_invariant: bool,
63 /// Constructor MIR: true prioritizes available MIR over call models;
64 /// false skips MIR; default skips MIR if the direct result has an invariant,
65 /// otherwise tries call models before MIR. With `--no-invariant-target`,
66 /// default behaves as true.
67 #[arg(long = "expand-ctor", value_name = "MODE", default_value = "default")]
68 pub constructor_mir: ConstructorMirMode,
69 /// Filter verification targets to only those within the specified crate
70 /// (Rust crate name or Cargo package name, e.g. `std`, `core`, `my-crate`).
71 /// Useful for standard-library workspaces and sub-workspaces.
72 #[arg(long = "crate")]
73 pub crate_filter: Option<String>,
74 /// Filter verification targets to only those within the specified module path
75 /// (e.g. `my_module::inner`). When combined with `--crate`, the path is
76 /// interpreted relative to that crate. Applies to all verification modes.
77 #[arg(long = "module")]
78 pub module_filter: Option<String>,
79 /// Cap on the number of paths collected per checkpoint (defaults to the
80 /// built-in `PATH_LIMIT`; 0 also selects that default). Lower it to speed
81 /// up verification; paths omitted by the cap are treated as proved.
82 #[arg(long)]
83 pub path_limit: Option<usize>,
84 /// Cap on trait impls inlined for a virtual call and generic type combinations
85 /// checked during monomorphization. Defaults to 1; 0 also selects that default.
86 #[arg(long)]
87 pub trait_impl_limit: Option<usize>,
88 /// Print all contract resolutions for every verification target: each
89 /// unsafe callee with its resolved contracts, and the caller's own
90 /// contracts (expanded form), without running verification.
91 #[arg(long)]
92 pub debug_contracts: bool,
93}
94
95impl VerifyConfig {
96 /// Effective verification path cap, including the default for zero or omission.
97 pub(crate) fn path_limit(&self) -> usize {
98 self.path_limit.filter(|n| *n != 0).unwrap_or(crate::limit::PATH_LIMIT)
99 }
100
101 /// Effective trait implementation cap, including the default for zero or omission.
102 pub(crate) fn trait_impl_limit(&self) -> usize {
103 self.trait_impl_limit.filter(|n| *n != 0).unwrap_or(crate::limit::TRAIT_IMPL_LIMIT)
104 }
105
106 /// Invariant-less runs expand constructor MIR under the default mode.
107 pub(crate) fn constructor_mir_mode(&self) -> ConstructorMirMode {
108 if self.skip_invariant && matches!(self.constructor_mir, ConstructorMirMode::Default) {
109 ConstructorMirMode::True
110 } else {
111 self.constructor_mir
112 }
113 }
114}